Changes

Jump to navigation Jump to search
1,306 bytes added ,  11:43, 6 October 2017
no edit summary
==Updating Expressions==
 
There are five new expressions to modify data. While {{Code|insert}}, {{Code|delete}}, {{Code|rename}} and {{Code|replace}} are basically self-explanatory, the {{Code|transform}} expression is different, as modified nodes are copied in advance and the original databases remain untouched.
==Non-Updating Expressions==
===transformcopy/modify/return===
<pre class="brush:xquery">
===update===
 
The {{Code|update}} expression is a BaseX-specific convenience operator for the {{Code|copy/modify/return}}
construct:
 
* Similar to the [[XQuery 3.0#Simple Map Operator|XQuery 3.0 map operator]], the value of the first
expression is bound as context item, and the second expression performs updates on this item.
The updated item is returned as result:
<pre class="brush:xquery">
</pre>
* More than one node can be specified as source: <pre class="brush:xquery">db:open('data')//item update delete node text()</pre> * If wrapped with curly braces, update expressions can be chained: <pre class="brush:xquery"><root/> update { insert node <child/> into .} update { insert node "text" into child}</pre> ===transform with=== The {{Code|updatetransform with}} expression is a convenience operator for writing simple transform expressions.Similar was added to the current [[XQuery 3https://www.w3.0org/TR/xquery-update-30/#Simple Map Operator|id-transform-with XQuery Update 3.0 map operator]], the value working draft. It is a simple version of the first[[#update|update]] expression is bound as context item, and the second expression performs updates on this item.The updated item is returned as result.also availablein BaseX:
Please note that <pre class="brush:xquery"><xml>text</xml> transform with {{Code|update}} is not part replace value of the official XQuery Update Facility yetnode .with 'new-text'It is currently being discussed in the [https:}<//www.w3.org/Bugs/Public/show_bug.cgi?id=23643 W3 Bug Tracker];your feedback is welcome.pre>
==Functions==
===Built-in Functions=== {{Code|fn:put()}} is can be used to serialize XDM instances to secondary storage. It is executed at the end of a snapshot. Serialized documents therefore reflect all changes made effective during a query. No files will be created if the addressed nodes have been deleted. With {{Version|9.0}}, serialization parameters can be specified as third argument (more details are found in the [https://www.w3.org/TR/xquery-update-30/#id-func-put XQUF 3.0 Specification]). Numerous additional [[Database Module#Updates|database functions]] exist for performing updates on document and database level. ===User-Defined Functions===
If an updating function item is called, the function call must be prefixed with the keyword {{Code|fn:put()updating}} is also part of the XQUF and enables the user to serialize XDM instances to secondary storage. It is executed at This ensures that the end of a snapshot. Serialized documents therefore reflect all changes made effective during a query.compiler can statically detect if an invoked function item will perform updates or not:
<pre class="brush:xquery">let $node :=<node>TO-BE-DELETED</node>let $delete-text :=Database Functions===%updating function($node) { delete node $node//text()}return $node update ( updating $delete-text(.))</pre>
Some additionalAs shown in the example, user-defined and anonymous functions can additionally be annotated as {{Code|%updating [[Database Module#Updates|database functions]] exist in order to perform updates on document and database level}}.
=Concepts=
 
There are a few specialties around XQuery Update that you should know about. In addition to the '''simple expression''', the XQUF adds the '''updating expression''' as a new type of expression. An updating expression returns only a Pending Update List (PUL) as a result which is subsequently applied to addressed databases and DOM nodes. A simple expression cannot perform any permanent changes and returns an empty or non-empty sequence.
If you want to modify nodes in main memory, you can use the [[Update#transform|transform expression]].
 
==Function Declaration==
 
To use updating expressions within a function, the {{Code|%updating}} annotation has to be added to the function declaration. A correct declaration of a function that contains updating expressions (or one that calls updating functions) looks like this:
 
<pre class="brush:xquery">
declare %updating function { ... }
</pre>
==Effects==
to the specification and BaseX. All errors are listed in the
[[XQuery Errors#Update Errors|XQuery Errors]] overview.
 
Please remember that the collected updates will be executed after the query evaluation.
If errors occur at this final stage, they cannot be caught via try/catch.
=Changelog=
 
;Version 9.0
* Updated: [[#Built-in Functions|Built-in Functions]]: serialization parameters
 
;Version 8.5
* Added: [[#transform with|transform with]]
* Updated: [[#update|update]] was extended.
;Version 8.0
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu