Changes

Jump to navigation Jump to search
307 bytes added ,  13:33, 20 July 2022
m
Text replacement - "db:pre(" to "db:get("
<syntaxhighlight lang="xquery">
copy $c := (db:openget('example')//entry)[1]
...
</syntaxhighlight>
===update===
 
{{Announce|Updated with Version 10:}} Curly braces are now mandatory.
The {{Code|update}} expression is a BaseX-specific convenience operator for the {{Code|copy/modify/return}}
<syntaxhighlight lang="xquery">
for $item in db:openget('data')//itemreturn $item update { delete node text()}
</syntaxhighlight>
<syntaxhighlight lang="xquery">
db:openget('data')//item update { delete node text()}
</syntaxhighlight>
==Pending Update List==
{{Announce|Updated with Version 10}}: {{CodeFunction|Database|db:storeput-binary}} is executed before all standard XQuery Update expressions.
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. After the evaluation of the query, and after some consistency checks and optimizations, the update primitives will be applied in the following order:
* '''Backups, Binary resources''': {{CodeFunction|Database|db:alter-backup()}}, {{CodeFunction|Database|db:create-backup()}}, {{CodeFunction|Database|db:put}}, {{Function|Database|db:store()put-binary}}* '''XQuery Update''': {{Code|insert before}}, {{Code|delete}}, {{Code|replace}}, {{Code|rename}}, {{Code|replace value}}, {{Code|insert attribute}}, {{Code|insert into first}}, {{Code|insert into}}, {{Code|insert into last}}, {{Code|insert}}, {{Code|insert after}}, {{Code|fn:put}}* '''Documents''': {{CodeFunction|Database|db:add()}}, {{CodeFunction|Database|db:replace()put}}, {{CodeFunction|Database|db:rename()}}, {{CodeFunction|Database|db:delete()}}, {{CodeFunction|Database|db:optimize()}}, {{CodeFunction|Database|db:flush()}},* '''Users''': {{CodeFunction|User|user:grant()}}, {{CodeFunction|User|user:password()}}, {{CodeFunction|User|user:drop()}}, {{CodeFunction|User|user:alter()}}, {{CodeFunction|User|user:create()}}* '''Databases''': {{CodeFunction|Database|db:copy()}}, {{CodeFunction|Database|db:drop()}}, {{CodeFunction|Database|db:alter()}}, {{CodeFunction|Database|db:create()}}* '''Backups ''': {{CodeFunction|Database|db:restore()}}, {{CodeFunction|Database|db:drop-backup()}}
If an inconsistency is found, an error message is returned and all accessed databases remain untouched (atomicity). For the user, this means that updates are only visible '''after''' the end of a snapshot.
By default, it is not possible to mix different types of expressions in a query result. The root expression of a query must be a sequence of updating expressions. But there are two ways out:
* The BaseX-specific <code>[[{{Function|Update Module#update:output|update:output()]]</code> }} function bridges this gap: it caches the results of its arguments at runtime and returns them after all updates have been processed. The following example performs an update and returns a success message:
<syntaxhighlight lang="xquery">
* Updates on main-memory instances of files that have been retrieved via {{Code|fn:doc}} or {{Code|fn:collection}} will be propagated back to disk if {{Option|WRITEBACK}} is turned on. This option can also be activated on [[Command-Line Options#BaseX Standalone|command line]] via <code>-u</code>. Make sure you back up the original documents before running your queries.
* Functions like <code>[[#fn:put{{Code|fn:put]]</code> }} or <code>[[{{Function|File Module#file:write|file:write]]</code> }} can be used to write single XML documents to disk. With <code>[[{{Function|File Module#file:write-binary|file:write-binary]]</code>}}, you can write binary resources.* The [[Commands#EXPORT{{Command|EXPORT]] }} command can be used write all resources of a databases to disk.
==Indexes==
;Version 10.0
* Updated: {{CodeFunction|Database|db:storeput-binary}} is executed before XQuery Update expressions.* Updated: [[#update|update]]: Curly braces are now mandatory.
;Version 9.0
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu