Difference between revisions of "Database Module"
(→Errors) |
|||
Line 8: | Line 8: | ||
==Database Nodes== | ==Database Nodes== | ||
− | + | {{Mark|With Version 7.7}}, the database functions no longer accept database nodes as reference. Instead, the name of a database must now be specified. This argument is consistently labeled as {{Code|$db}}. | |
+ | |||
+ | {{Error|BXDB0002|#Errors}} may be raised if the addressed database cannot be opened. | ||
− | + | Database nodes are XML nodes which are either stored in a persistent database or part of a so-called ''database fragment''. All XML fragments can be converted to database fragments by e. g. applying the [[XQuery_Update#transform|transform]] expression on an XML fragment: | |
− | |||
− | |||
− | |||
<pre class="brush:xquery"> | <pre class="brush:xquery"> | ||
copy $c := element hello { 'world' } | copy $c := element hello { 'world' } | ||
modify () | modify () | ||
− | return | + | return $c |
</pre> | </pre> | ||
Line 27: | Line 26: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:info|$db as | + | |{{Func|db:info|$db as xs:string|element(database)}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns meta information on the database specified by the | + | |Returns meta information on the database specified by the database {{Code|$db}}. |
|} | |} | ||
Line 37: | Line 36: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:list||xs:string*}}<br/>{{Func|db:list|$db as | + | |{{Func|db:list||xs:string*}}<br/>{{Func|db:list|$db as xs:string|xs:string*}}<br/>{{Func|db:list|$db as xs:string, $path as xs:string|xs:string*}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns a string sequence with the names of all databases.<br/>If a | + | |Returns a string sequence with the names of all databases.<br/>If a database {{Code|$db}} is specified, all documents and raw files of the specified database are returned.<br/>The list of resources can be further restricted by the {{Code|$path}} argument. |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
Line 51: | Line 50: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:list-details||element(database)*}}<br/>{{Func|db:list-details|$db as | + | |{{Func|db:list-details||element(database)*}}<br/>{{Func|db:list-details|$db as xs:string|element(resource)*}}<br/>{{Func|db:list-details|$db as xs:string, $path as xs:string|element(resource)*}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns an element sequence with the names of all databases together with their database path, the number of stored resources and the date of modification.<br/>If a | + | |Returns an element sequence with the names of all databases together with their database path, the number of stored resources and the date of modification.<br/>If a database {{Code|$db}} is specified, all documents and raw files of the specified database together with their content-type, the modification date and the resource type are returned.<br/>The list of resources can be further restricted by the {{Code|$path}} argument. |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
Line 65: | Line 64: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:open|$db as | + | |{{Func|db:open|$db as xs:string|document-node()*}}<br />{{Func|db:open|$db as xs:string, $path as xs:string|document-node()*}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns a sequence with all document nodes contained in the database specified by the | + | |Returns a sequence with all document nodes contained in the database specified by the database {{Code|$db}}.<br/>The document nodes to be returned can be restricted by the {{Code|$path}} argument. |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
Line 80: | Line 79: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:open-id|$db as | + | |{{Func|db:open-id|$db as xs:string, $id as xs:integer|node()}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Opens the database specified by the | + | |Opens the database specified by the database {{Code|$db}} and returns the node with the specified {{Code|$id}} value.<br />Each database node has a persistent ''id'', which remains valid after update operations. If no updates are performed, the ''pre'' value can be requested, which provides access to database nodes in constant time. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 93: | Line 92: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:open-pre|$db as | + | |{{Func|db:open-pre|$db as xs:string, $pre as xs:integer|node()}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Opens the database specified by the | + | |Opens the database specified by the database {{Code|$db}} and returns the node with the specified {{Code|$pre}} value.<br />The ''pre'' value provides access to a database node in constant time, but it is ''transient'', i.e., it may change when database updates are performed. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 120: | Line 119: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:backups||element(backup)*}}<br/>{{Func|db:backups|$db as | + | |{{Func|db:backups||element(backup)*}}<br/>{{Func|db:backups|$db as xs:string|element(backup)*}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns an element sequence containing all available database backups.<br/>If a | + | |Returns an element sequence containing all available database backups.<br/>If a database {{Code|$db}} is specified, the sequence will be restricted to the backups matching this database. |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
Line 136: | Line 135: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:attribute|$db as | + | |{{Func|db:attribute|$db as xs:string, $string as item()|attribute()*}}<br/>{{Func|db:attribute|$db as xs:string, $string as item(), $attname as xs:string|attribute()*}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns all attribute nodes of the database specified by the | + | |Returns all attribute nodes of the database specified by the database {{Code|$db}} that have {{Code|$string}} as string value. If available, the value index is used to speed up evaluation.<br />If {{Code|$attname}} is specified, the resulting attribute nodes are filtered by their attribute name. |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
Line 150: | Line 149: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:attribute-range|$db as | + | |{{Func|db:attribute-range|$db as xs:string, $min as xs:string, $max as xs:string|attribute()*}}<br/>{{Func|db:attribute-range|$db as xs:string, $min as xs:string, $max as xs:string, $attname as xs:string|attribute()*}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns all attributes of the database specified by the | + | |Returns all attributes of the database specified by the database {{Code|$db}}, the string values of which are larger than or equal to {{Code|$min}} and smaller than or equal to {{Code|$max}}. If available, the value index is used to speed up evaluation. |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
Line 164: | Line 163: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:fulltext|$db as | + | |{{Func|db:fulltext|$db as xs:string, $terms as xs:string|text()*}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns all text nodes from the full-text index of the database specified by the | + | |Returns all text nodes from the full-text index of the database specified by the database {{Code|$db}} that contain the text specified as {{Code|$terms}}.<br/>The options used for building the full-text will also be applied to the search terms. As an example, if the index terms have been stemmed, the search string will be stemmed as well. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 187: | Line 186: | ||
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
− | |{{Error|BXDB0001|#Errors}} {{Code|$nodes}} contains a node which is not a | + | |{{Error|BXDB0001|#Errors}} {{Code|$nodes}} contains a node which is not stored in a database. |
|} | |} | ||
Line 200: | Line 199: | ||
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
− | |{{Error|BXDB0001|#Errors}} {{Code|$nodes}} contains a node which is not a | + | |{{Error|BXDB0001|#Errors}} {{Code|$nodes}} contains a node which is not stored in a database. |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
Line 212: | Line 211: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:retrieve|$db as | + | |{{Func|db:retrieve|$db as xs:string, $path as xs:string|xs:base64Binary}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns a binary database resource addressed by the | + | |Returns a binary database resource addressed by the database {{Code|$db}} and {{Code|$path}} as [[Streaming Module|streamable]] {{Code|xs:base64Binary}}. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 230: | Line 229: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:text|$db as | + | |{{Func|db:text|$db as xs:string, $string as item()|text()*}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns all text nodes of the database specified by the | + | |Returns all text nodes of the database specified by the database {{Code|$db}} that have {{Code|$string}} as their string value. If available, the value index is used to speed up evaluation. |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
Line 244: | Line 243: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:text-range|$db as | + | |{{Func|db:text-range|$db as xs:string, $min as xs:string, $max as xs:string|text()*}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns all text nodes of the database specified by the | + | |Returns all text nodes of the database specified by the database {{Code|$db}} that are located in between the {{Code|$min}} and {{Code|$max}} strings. If available, the value index is used to speed up evaluation. |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
Line 285: | Line 284: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:drop|$db as | + | |{{Func|db:drop|$db as xs:string|empty-sequence()}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Drops the database specified by the | + | |Drops the database specified by the database {{Code|$db}} and all connected resources. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 302: | Line 301: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:add|$db as | + | |{{Func|db:add|$db as xs:string, $input as item()|empty-sequence()}}<br/>{{Func|db:add|$db as xs:string, $input as item(), $path as xs:string|empty-sequence()}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Adds documents specified by {{Code|$input}} to the database specified by the | + | |Adds documents specified by {{Code|$input}} to the database specified by the database {{Code|$db}} and the specified {{Code|$path}}.<br/>{{Code|$input}} may be a string or a node different than attribute. If the {{Code|$input}} source is not a file or a folder, {{Code|$path}} must be specified. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 321: | Line 320: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:delete|$db as | + | |{{Func|db:delete|$db as xs:string, $path as xs:string|empty-sequence()}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Deletes document(s), specified by {{Code|$path}}, from the database specified by the | + | |Deletes document(s), specified by {{Code|$path}}, from the database specified by the database {{Code|$db}}. |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
Line 336: | Line 335: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:optimize|$db as | + | |{{Func|db:optimize|$db as xs:string|empty-sequence()}}<br/>{{Func|db:optimize|$db as xs:string, $all as xs:boolean|empty-sequence()}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Optimizes the meta data and indexes of the database specified by the | + | |Optimizes the meta data and indexes of the database specified by the database {{Code|$db}}.<br/>If {{Code|$all}} is set to {{Code|true()}}, the complete database will be rebuilt. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 354: | Line 353: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:rename|$db as | + | |{{Func|db:rename|$db as xs:string, $path as xs:string, $newpath as xs:string|empty-sequence()}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Renames document(s), specified by {{Code|$path}} to {{Code|$newpath}} in the database specified by the | + | |Renames document(s), specified by {{Code|$path}} to {{Code|$newpath}} in the database specified by the database {{Code|$db}}. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 372: | Line 371: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:replace|$db as | + | |{{Func|db:replace|$db as xs:string, $path as xs:string, $input as item()|empty-sequence()}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Replaces a document, specified by {{Code|$path}}, in the database specified by the | + | |Replaces a document, specified by {{Code|$path}}, in the database specified by the database {{Code|$db}} with the content of {{Code|$input}}, or adds it as a new document. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 391: | Line 390: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:store|$db as | + | |{{Func|db:store|$db as xs:string, $path as xs:string, $input as item()|empty-sequence()}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Stores a binary resource specified by {{Code|$input}} in the database specified by the | + | |Stores a binary resource specified by {{Code|$input}} in the database specified by the database {{Code|$db}} and the location specified by {{Code|$path}}. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 423: | Line 422: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:flush|$db as | + | |{{Func|db:flush|$db as xs:string|empty-sequence()}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Explicitly flushes the buffers of the database specified by the | + | |Explicitly flushes the buffers of the database specified by the database {{Code|$db}}. This command is only useful if [[Options#AUTOFLUSH|AUTOFLUSH]] has been set to {{Code|false}}. |
|} | |} | ||
Line 435: | Line 434: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:exists|$db as | + | |{{Func|db:exists|$db as xs:string|xs:boolean}}<br/>{{Func|db:exists|$db as xs:string, $path as xs:string|xs:boolean}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Checks if the database specified by the | + | |Checks if the database specified by the database {{Code|$db}} or the resource specified by {{Code|$path}} exists. {{Code|false}} is returned if a database directory has been addressed. |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
Line 450: | Line 449: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:is-raw|$db as | + | |{{Func|db:is-raw|$db as xs:string, $path as xs:string|xs:boolean}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Checks if the specified resource in the database specified by the | + | |Checks if the specified resource in the database specified by the database {{Code|$db}} and the path {{Code|$path}} exists, and if it is a raw file. |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
Line 464: | Line 463: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:is-xml|$db as | + | |{{Func|db:is-xml|$db as xs:string, $path as xs:string|xs:boolean}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Checks if the specified resource in the database specified by the | + | |Checks if the specified resource in the database specified by the database {{Code|$db}} and the path {{Code|$path}} exists, and if it is an XML document. |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
Line 478: | Line 477: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|db:content-type|$db as | + | |{{Func|db:content-type|$db as xs:string, $path as xs:string|xs:string}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Retrieves the content type of a resource in the database specified by the | + | |Retrieves the content type of a resource in the database specified by the database {{Code|$db}} and the path {{Code|$path}}.<br/>The file extension is used to recognize the content-type of a resource stored in the database. Content-type {{Code|application/xml}} will be returned for any XML document stored in the database, regardless of its file name extension. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 513: | Line 512: | ||
|- | |- | ||
|{{Code|BXDB0001}} | |{{Code|BXDB0001}} | ||
− | |A referenced XML node is no | + | |A referenced XML node is no database, i.e. is neither stored in a database nor a database fragment. |
|- | |- | ||
|{{Code|BXDB0002}} | |{{Code|BXDB0002}} | ||
Line 556: | Line 555: | ||
=Changelog= | =Changelog= | ||
+ | |||
+ | ;Version 7.7 | ||
+ | |||
+ | * Updated: instead of [[#Database Nodes|Database Nodes]], the name of a database must now be specified. | ||
;Version 7.6 | ;Version 7.6 |
Revision as of 13:52, 20 May 2013
This XQuery Module contains functions for processing databases from within XQuery. Existing databases can be opened and listed, its contents can be directly accessed, documents can be added to and removed, etc.
Contents
Conventions
All functions in this module are assigned to the http://basex.org/modules/db
namespace, which is statically bound to the db
prefix.
All errors are assigned to the http://basex.org/errors
namespace, which is statically bound to the bxerr
prefix.
Database Nodes
Template:Mark, the database functions no longer accept database nodes as reference. Instead, the name of a database must now be specified. This argument is consistently labeled as $db
.
BXDB0002
: may be raised if the addressed database cannot be opened.
Database nodes are XML nodes which are either stored in a persistent database or part of a so-called database fragment. All XML fragments can be converted to database fragments by e. g. applying the transform expression on an XML fragment:
copy $c := element hello { 'world' } modify () return $c
General Functions
db:info
Signatures | db:info($db as xs:string) as element(database)
|
Summary | Returns meta information on the database specified by the database $db .
|
db:list
Signatures | db:list() as xs:string* db:list($db as xs:string) as xs:string* db:list($db as xs:string, $path as xs:string) as xs:string*
|
Summary | Returns a string sequence with the names of all databases. If a database $db is specified, all documents and raw files of the specified database are returned.The list of resources can be further restricted by the $path argument.
|
Examples |
|
db:list-details
Signatures | db:list-details() as element(database)* db:list-details($db as xs:string) as element(resource)* db:list-details($db as xs:string, $path as xs:string) as element(resource)*
|
Summary | Returns an element sequence with the names of all databases together with their database path, the number of stored resources and the date of modification. If a database $db is specified, all documents and raw files of the specified database together with their content-type, the modification date and the resource type are returned.The list of resources can be further restricted by the $path argument.
|
Examples |
|
db:open
Signatures | db:open($db as xs:string) as document-node()* db:open($db as xs:string, $path as xs:string) as document-node()*
|
Summary | Returns a sequence with all document nodes contained in the database specified by the database $db .The document nodes to be returned can be restricted by the $path argument.
|
Examples |
|
db:open-id
Signatures | db:open-id($db as xs:string, $id as xs:integer) as node()
|
Summary | Opens the database specified by the database $db and returns the node with the specified $id value.Each database node has a persistent id, which remains valid after update operations. If no updates are performed, the pre value can be requested, which provides access to database nodes in constant time. |
Errors | BXDB0009 : the specified id value does not exist in the database.
|
db:open-pre
Signatures | db:open-pre($db as xs:string, $pre as xs:integer) as node()
|
Summary | Opens the database specified by the database $db and returns the node with the specified $pre value.The pre value provides access to a database node in constant time, but it is transient, i.e., it may change when database updates are performed. |
Errors | BXDB0009 : the specified pre value does not exist in the database.
|
Examples |
|
db:system
Signatures | db:system() as element(system)
|
Summary | Returns information on the database system, such as the database path and current database settings. |
db:backups
Signatures | db:backups() as element(backup)* db:backups($db as xs:string) as element(backup)*
|
Summary | Returns an element sequence containing all available database backups. If a database $db is specified, the sequence will be restricted to the backups matching this database.
|
Examples |
|
Read Operations
db:attribute
Signatures | db:attribute($db as xs:string, $string as item()) as attribute()* db:attribute($db as xs:string, $string as item(), $attname as xs:string) as attribute()*
|
Summary | Returns all attribute nodes of the database specified by the database $db that have $string as string value. If available, the value index is used to speed up evaluation.If $attname is specified, the resulting attribute nodes are filtered by their attribute name.
|
Examples |
|
db:attribute-range
Signatures | db:attribute-range($db as xs:string, $min as xs:string, $max as xs:string) as attribute()* db:attribute-range($db as xs:string, $min as xs:string, $max as xs:string, $attname as xs:string) as attribute()*
|
Summary | Returns all attributes of the database specified by the database $db , the string values of which are larger than or equal to $min and smaller than or equal to $max . If available, the value index is used to speed up evaluation.
|
Examples |
|
db:fulltext
Signatures | db:fulltext($db as xs:string, $terms as xs:string) as text()*
|
Summary | Returns all text nodes from the full-text index of the database specified by the database $db that contain the text specified as $terms .The options used for building the full-text will also be applied to the search terms. As an example, if the index terms have been stemmed, the search string will be stemmed as well. |
Errors | BXDB0004 : the full-text index is not available.
|
Examples |
|
db:node-id
Signatures | db:node-id($nodes as node()*) as xs:integer*
|
Summary | Returns the id values of the nodes supplied by $nodes , which must all be database nodes.Each database node has a persistent id, which remains valid after update operations. If so far no updates have been performed, the pre value is equal to the id value and can be requested instead, which provides access to database nodes in constant time. |
Errors | BXDB0001 : $nodes contains a node which is not stored in a database.
|
db:node-pre
Signatures | db:node-pre($nodes as node()*) as xs:integer*
|
Summary | Returns the pre values of the nodes supplied by $nodes , which must all be database nodes. The pre value provides access to a database node in constant time, but it is transient, i.e., it may change when database updates are performed. |
Errors | BXDB0001 : $nodes contains a node which is not stored in a database.
|
Examples |
|
db:retrieve
Signatures | db:retrieve($db as xs:string, $path as xs:string) as xs:base64Binary
|
Summary | Returns a binary database resource addressed by the database $db and $path as streamable xs:base64Binary .
|
Errors | BXDB0003 : the database is not persistent (stored on disk).FODC0002 : the addressed resource cannot be retrieved.FODC0007 : the specified path is invalid.
|
Examples |
|
db:text
Signatures | db:text($db as xs:string, $string as item()) as text()*
|
Summary | Returns all text nodes of the database specified by the database $db that have $string as their string value. If available, the value index is used to speed up evaluation.
|
Examples |
|
db:text-range
Signatures | db:text-range($db as xs:string, $min as xs:string, $max as xs:string) as text()*
|
Summary | Returns all text nodes of the database specified by the database $db that are located in between the $min and $max strings. If available, the value index is used to speed up evaluation.
|
Examples |
|
Updates
Important note: All functions in this section are updating functions: they will not be immediately executed, but queued on the Pending Update List, which will be processed after the actual query has been evaluated. This means that the order in which the functions are specified in the query does usually not reflect the order in which the code will be evaluated.
db:create
Template:Mark allow more than one input and path.
Signatures | db:create($db as xs:string) as empty-sequence() db:create($db as xs:string, $inputs as item()*) as empty-sequence() db:create($db as xs:string, $inputs as item()*, $paths as xs:string*) as empty-sequence()
|
Summary | Creates a new database with name $db and adds initial documents specified via $inputs to the specified $paths .$inputs may be strings or nodes different than attributes. If the $input source is not a file or a folder, the $paths argument is mandatory.Please note that db:create will be placed last on the Pending Update List. As a consequence, a newly created database cannot be addressed in the same query.
|
Errors | FODC0002 : $inputs points to an unknown resource.FOUP0001 : $inputs is neither string nor a document node.BXDB0007 : $db is opened by another process.BXDB0011 : $db is not a valid database name.BXDB0012 : two db:create statements with the same database name were specified.BXDB0013 : the number of specified inputs and paths differs.
|
Examples |
|
db:drop
Signatures | db:drop($db as xs:string) as empty-sequence()
|
Summary | Drops the database specified by the database $db and all connected resources.
|
Errors | BXDB0007 : $db is opened by another process.
|
Examples |
|
db:add
Signatures | db:add($db as xs:string, $input as item()) as empty-sequence() db:add($db as xs:string, $input as item(), $path as xs:string) as empty-sequence()
|
Summary | Adds documents specified by $input to the database specified by the database $db and the specified $path .$input may be a string or a node different than attribute. If the $input source is not a file or a folder, $path must be specified.
|
Errors | FODC0002 : $input points to an unknown resource.FOUP0001 : $input is neither string nor a document node.
|
Examples |
|
db:delete
Signatures | db:delete($db as xs:string, $path as xs:string) as empty-sequence()
|
Summary | Deletes document(s), specified by $path , from the database specified by the database $db .
|
Examples |
|
db:optimize
Signatures | db:optimize($db as xs:string) as empty-sequence() db:optimize($db as xs:string, $all as xs:boolean) as empty-sequence()
|
Summary | Optimizes the meta data and indexes of the database specified by the database $db .If $all is set to true() , the complete database will be rebuilt.
|
Errors | FOUP0002 : an error occurred while optimizing the database.
|
Examples |
|
db:rename
Signatures | db:rename($db as xs:string, $path as xs:string, $newpath as xs:string) as empty-sequence()
|
Summary | Renames document(s), specified by $path to $newpath in the database specified by the database $db .
|
Errors | BXDB0008 : new document names would be empty.
|
Examples |
|
db:replace
Signatures | db:replace($db as xs:string, $path as xs:string, $input as item()) as empty-sequence()
|
Summary | Replaces a document, specified by $path , in the database specified by the database $db with the content of $input , or adds it as a new document.
|
Errors | BXDB0014 : $path points to a directory.FODC0002 : $input is a string representing a path, which cannot be read.FOUP0001 : $input is neither a string nor a document node.
|
Examples |
|
db:store
Signatures | db:store($db as xs:string, $path as xs:string, $input as item()) as empty-sequence()
|
Summary | Stores a binary resource specified by $input in the database specified by the database $db and the location specified by $path .
|
Errors | BXDB0003 : the database is not persistent (stored on disk).FODC0007 : the specified path is invalid.FOUP0002 : the resource cannot be stored at the specified location.
|
Examples |
|
db:output
Signatures | db:output($result as item()*) as empty-sequence()
|
Summary | This function can be used to both perform updates and return results in a single query. The argument of the function will be evaluated, and the resulting items will be cached and returned after the updates on the pending update list have been processed. As nodes may be updated, they will be copied before being cached. The function can only be used together with updating expressions; if the function is called within a transform expression, its results will be discarded. |
Examples |
|
db:flush
Signatures | db:flush($db as xs:string) as empty-sequence()
|
Summary | Explicitly flushes the buffers of the database specified by the database $db . This command is only useful if AUTOFLUSH has been set to false .
|
Helper Functions
db:exists
Signatures | db:exists($db as xs:string) as xs:boolean db:exists($db as xs:string, $path as xs:string) as xs:boolean
|
Summary | Checks if the database specified by the database $db or the resource specified by $path exists. false is returned if a database directory has been addressed.
|
Examples |
|
db:is-raw
Signatures | db:is-raw($db as xs:string, $path as xs:string) as xs:boolean
|
Summary | Checks if the specified resource in the database specified by the database $db and the path $path exists, and if it is a raw file.
|
Examples |
|
db:is-xml
Signatures | db:is-xml($db as xs:string, $path as xs:string) as xs:boolean
|
Summary | Checks if the specified resource in the database specified by the database $db and the path $path exists, and if it is an XML document.
|
Examples |
|
db:content-type
Signatures | db:content-type($db as xs:string, $path as xs:string) as xs:string
|
Summary | Retrieves the content type of a resource in the database specified by the database $db and the path $path .The file extension is used to recognize the content-type of a resource stored in the database. Content-type application/xml will be returned for any XML document stored in the database, regardless of its file name extension.
|
Errors | FODC0002 : the addressed resource is not found or cannot be retrieved.
|
Examples |
|
db:event
Signatures | db:event($name as xs:string, $query as item()) as empty-sequence()
|
Summary | Executes a $query and sends the resulting value to all clients watching the Event with the specified $name . The query may also perform updates; no event will be sent to the client that fired the event.
|
Errors | BXDB0010 : the specified event is unknown.SEPM0016 : serialization errors occurred while sending the value. |
Errors
Code | Description |
---|---|
BXDB0001
|
A referenced XML node is no database, i.e. is neither stored in a database nor a database fragment. |
BXDB0002
|
An I/O error occurred while opening a database. |
BXDB0003
|
The addressed database is not persistent (stored on disk). |
BXDB0004
|
The database lacks an index structure required by the called function. |
BXDB0005
|
A query is expected to exclusively return database nodes of a single database. |
BXDB0006
|
A database path addressed with doc() contains more than one document.
|
BXDB0007
|
A database cannot be updated because it is opened by another process. |
BXDB0008
|
Database paths cannot be renamed to empty strings. |
BXDB0009
|
The addressed database id or pre value is out of range. |
BXDB0010
|
The specified event is unknown. |
BXDB0011
|
The name of the specified database is invalid. |
BXDB0012
|
A database can only be created once. |
BXDB0013
|
The number of specified inputs and paths differs. |
BXDB0014
|
Path points to a directory. |
Changelog
- Version 7.7
- Updated: instead of Database Nodes, the name of a database must now be specified.
- Version 7.6
- Updated: db:create: allow more than one input and path.
- Version 7.5
- Updated: db:add: input nodes will be automatically converted to document nodes
- Added: db:backups
- Added: db:create
- Added: db:drop
- Version 7.3
- Added: db:flush
- Version 7.2.1
- Added: db:text-range, db:attribute-range, db:output
- Version 7.1
- Added: db:list-details, db:content-type
- Updated: db:info, db:system, db:retrieve
- Version 7.0