Difference between revisions of "XQuery Update"

From BaseX Documentation
Jump to navigation Jump to search
Line 12: Line 12:
 
==Indexes==
 
==Indexes==
 
<p>As BaseX aims mainly for efficiency, the maintenance of indexes is left to the user.
 
<p>As BaseX aims mainly for efficiency, the maintenance of indexes is left to the user.
This requires the user to call the <a href='commands#optimize'><code>[[OPTIMIZE]]</code></a>
+
This requires the user to call the [[Commands|OPTIMIZE]]  
 
command if up-to-date index structures are
 
command if up-to-date index structures are
necessary. Using this approach guarantees fast updates and fast access at the same time.</p>  
+
necessary. Using this approach guarantees fast updates and fast access at the same time.</p>
+
 
 
==Fragments==  
 
==Fragments==  
 
<p>So far BaseX differentiates between fragments and database nodes. Updates on fragments
 
<p>So far BaseX differentiates between fragments and database nodes. Updates on fragments

Revision as of 14:10, 6 December 2010

With the release of version 6.0, BaseX offers a complete implementation of the XQuery Update Facility (XQUF).

New Expressions

The XQUF offers five new expressions to modify data. While insert, delete, rename and replace basically explain themselves, the transform expression is different. Modified nodes are copied in advance and the original databases remain untouched.

fn:put() Function

Effects on Your Documents

In BaseX, all updates are performed on database nodes. This is why update operations never affect the original input file. You can, however, use the EXPORT command or the fn:put() function to create an updated XML file.

Indexes

As BaseX aims mainly for efficiency, the maintenance of indexes is left to the user. This requires the user to call the OPTIMIZE command if up-to-date index structures are necessary. Using this approach guarantees fast updates and fast access at the same time.

Fragments

So far BaseX differentiates between fragments and database nodes. Updates on fragments have no effect on any existing databases and are therefore not applied at all. This includes the test for violation of any constraints. Thus it is possible to execute an update on a fragment, which would raise an error if applied on a database node.

Query: insert node attribute id{'1'} into <a id='0'/>

Result:

File 'doc.xml': <n id='1'/>

Query: insert node attribute id{'0'} into doc('doc.xml')//n

Result: [XUDY0021]Duplicate attribute "id".

fn:put() and Fragments

As a consequence, updates on a fragment are not visible in an XML file created with fn:put(). If this functionality is required, the transform expression can be applied. The copied nodes in a transform expression are internally treated like database nodes and are updatable as a result.

Example:

Query:

let $n := <n/> return (insert node <x/> into $n, put($n,'doc.xml'))

File 'doc.xml': <n/>

Query:

 
  put(
    copy $nn := <n/>
    modify insert node <x/> into $nn
    return $nn,
    'doc.xml')

File 'doc.xml': <n> <x/> </n>