Changes

Jump to navigation Jump to search
40 bytes removed ,  19:27, 27 March 2015
no edit summary
language. These are stated in the [[Update#Concepts|Concepts]] paragraph.
==Features==
===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.
An expression consists of a target node (the node we want to alter) and additional information like insertion nodes, a QName, etc. which depends on the type of expression. Optional modifiers are available for some of them. You can find a few examples and additional information below.
====insert====
<pre class="brush:xquery">
''Note'': in most cases, '''as last''' and '''after''' will be evaluated faster than '''as first''' and '''before'''!
====delete====
<pre class="brush:xquery">
The example query deletes all <code><node></code> elements in your database. Note that, in contrast to other updating expressions, the delete expression allows multiple nodes as a target.
====replace====
<pre class="brush:xquery">
All descendants of /n are deleted and the given text is inserted as the only child. Note that the result of the insert sequence is either a single text node or an empty sequence. If the insert sequence is empty, all descendants of the target are deleted. Consequently, replacing the value of a node leaves the target with either a single text node or no descendants at all.
====rename====
<pre class="brush:xquery">
All node elements are renamed. An iterative approach helps to modify multiple nodes within a single statement. Nodes on the descendant- or attribute-axis of the target are not affected. This has to be done explicitly as well.
===Non-Updating Expressions===
====transform====
<pre class="brush:xquery">
</pre>
====update====
<pre class="brush:xquery">
your feedback is welcome.
===Functions===
====fn:put====
{{Code|fn:put()}} is also part of the XQUF and enables the user 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.
====Database Functions====
Some additional, 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.
===Pending Update List===
The most important thing to keep in mind when using XQuery Update is the Pending Update List (PUL). Updating statements are not executed immediately, but are first collected as update primitives within a set-like structure. At the end of a query, after some consistency checks and optimizations, the update primitives will be applied in the following order:
It may be surprising to see <code>[[Database Module|db:create]]</code> in the lower part of this list. This means that newly created database cannot be accessed by the same query, which can be explained by the semantics of updating queries: all expressions can only be evaluated on databases that already exist while the query is evaluated. As a consequence, {{Code|db:create}} is mainly useful in the context of [[Commands#Basics|Command Scripts]], or [[Web Application]]s, in which a redirect to another page can be triggered after having created a database.
====Example====
The query…
Despite explicitly renaming all child nodes of {{Code|<doc/>}}, the former {{Code|<a/>}} element is the only one to be renamed. The {{Code|<b/>}} element is inserted within the same snapshot and is therefore not yet visible to the user.
===Returning Results===
By default, it is not possible to mix different types of expressions in a query result. The outermost expression of a query must either be a collection of updating or non-updating expressions. But there are two ways out:
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:
==Effects==
===Original Files===
In BaseX, all updates are performed on database nodes or in main memory. By default, update operations do not affect the original input file (the info string "Updates are not written back" appears in the query info to indicate this). The following solutions exist to write XML documents and binary resources to disk:
* The [[Commands#EXPORT|EXPORT]] command can be used write all resources of a databases to disk.
===Indexes===
Index structures are discarded after update operations when [[Options#UPDINDEX|UPDINDEX]] is turned off (which is the default).
More details are found in the article on [[Index#Updates|Indexing]].
==Error Messages==
Along with the Update Facility, a number of new error codes and messages have been added
Bureaucrats, editor, reviewer, Administrators
12,946

edits

Navigation menu