Changes

Jump to navigation Jump to search
1,046 bytes removed ,  04:06, 25 September 2018
m
drop extra 'as' in db:attribute#1
=Conventions=
 
{{Mark|Updated with Version 9.0}}:
All functions and errors in this module are assigned to the <code><nowiki>http://basex.org/modules/db</nowiki></code> namespace, which is statically bound to the {{Code|db}} prefix.<br/>
==Database Nodes==
Database nodes are XML nodes which are either stored in a persistent database, or which contained in are a sonode of a main-called ''memory database fragment''representation. All XML fragments can be converted to a main-memory database fragments by e. g. applying the [[XQuery_Update#update|update]] or [[XQuery_Update#transform|transform]] expression on an XML fragmenta node:
<pre class="brush:xquery">
copy $c db:= node-id(element hello { 'world' } modify (update {}) return $c
</pre>
|-
| '''Summary'''
|Returns general information on the database system, such as the database path current values of all global and current database settingslocal [[Options]]. The {{Command|INFO}} command returns similar output is similar to .|} ==db:option== {| width='100%'|-| width='120' | '''Signatures'''|{{Func|db:option|$name as xs:string|xs:string}}|-| '''Summary'''|Returns the current value (string, integer, boolean, map) of a global or local [[Commands#INFOOptions|INFOOption]] with the specified {{Code|$name}}. The {{Command|GET}} commandworks similar.|-| '''Examples'''|* <code>db:option('dbpath')</code> returns the database path string.* <code>db:option('serializer')</code> returns a map with the current serialization parameters.* <code>declare option db:chop 'true'; db:option('chop')</code> returns {{Code|true}} (irrespective of the global value).
|}
|-
| '''Summary'''
|Returns meta information on the database {{Code|$db}}. The output is similar to the [[Commands#INFO DB{{Command|INFO DB]] }} command.
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.
|}
|-
| width='120' | '''Signatures'''
|{{Func|db:property|$db as xs:string, $property name as xs:string|xs:anyAtomicType}}
|-
| '''Summary'''
|Returns the value (string, boolean, integer) of a property with the specified {{Code|$propertyname}} of in the database {{Code|$db}}. The available properties are the ones returned by [[#db:info|db:info]].
|-
| '''Errors'''
|{{Error|property|XQuery Errors#BaseX Errors}} the specified property is unknown.
|-
| '''Examples'''
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.
|-
| '''Examples'''
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.
|-
| '''Examples'''
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.
|-
| '''Examples'''
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.<br/>{{Error|range|XQuery Errors#BaseX Errors}} the specified pre value does not exist in the database.
|-
| '''Examples'''
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.<br/>{{Error|range|XQuery Errors#BaseX Errors}} the specified id value does not exist in the database.
|}
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.<br/>{{Error|mainmem|#Errors}} the database is not ''persistent'' (stored on disk).
|-
| '''Examples'''
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.
|-
| '''Examples'''
==db:text==
 
{{Mark|Updated with Version 9.1}}: Support for multiple string values.
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|db:text|$db as xs:string, $strings as xs:string as item()*|text()*}}
|-
| '''Summary'''
|Returns all text nodes of the database {{Code|$db}} that have one of the specified {{Code|$stringstrings}} as their string value values and that are stored in the text index.
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.<br/>{{Error|no-index|Database Module#Errors}} the index is not available.<br/>
|-
| '''Examples'''
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.<br/>{{Error|no-index|Database Module#Errors}} the index is not available.<br/>
|-
| '''Examples'''
==db:attribute==
 
{{Mark|Updated with Version 9.1}}: Support for multiple string values.
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|db:attribute|$db as xs:string, $strings as xs:string as item()*|attribute()*}}<br/>{{Func|db:attribute|$db as xs:string, $string strings as item()xs:strings*, $name as xs:string|attribute()*}}
|-
| '''Summary'''
|Returns all attribute nodes of the database {{Code|$db}} that have one of the specified {{Code|$stringstrings}} as string value values and that are stored in the attribute index.<br />If {{Code|$name}} is specified, the resulting attribute nodes are filtered by their attribute name.
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.<br/>{{Error|no-index|Database Module#Errors}} the index is not available.<br/>
|-
| '''Examples'''
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.<br/>{{Error|no-index|Database Module#Errors}} the index is not available.<br/>
|-
| '''Examples'''
==db:token==
 
{{Mark|Updated with Version 9.1}}: Support for multiple string values.
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|db:token|$db as xs:string, $token tokens as item()xs:string*|attribute()*}}<br/>{{Func|db:token|$db as xs:string, $token tokens as item()xs:string*, $name as xs:string|attribute()*}}
|-
| '''Summary'''
|Returns all attribute nodes of the database {{Code|$db}}, the value values of which contains contain one of the specified {{Code|$tokentokens}}.<br />If {{Code|$name}} is specified, the resulting attribute nodes are filtered by their attribute name.
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.<br/>{{Error|no-index|Database Module#Errors}} the index is not available.<br/>
|-
| '''Examples'''
|-
| width='120' | '''Signatures'''
|{{Func|db:create|$db as xs:string|empty-sequence()}}<br/>{{Func|db:create|$db as xs:string, $inputs as item()*|empty-sequence()}}<br/>{{Func|db:create|$db as xs:string, $inputs as item()*, $paths as xs:string*|empty-sequence()}}<br/>{{Func|db:create|$db as xs:string, $inputs as item()*, $paths as xs:string*, $options as map(*)?|empty-sequence()}}
|-
| '''Summary'''
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.<br/>{{Error|lock|#Errors}} a database is opened by another process.<br/>{{Error|conflict|#Errors}} the same database was addressed more than once.
|-
| '''Examples'''
|-
| width='120' | '''Signatures'''
|{{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()}}<br/>{{Func|db:add|$db as xs:string, $input as item(), $path as xs:string, $options as map(*)?|empty-sequence()|empty-sequence()}}
|-
| '''Summary'''
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.
|-
| '''Examples'''
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.<br/>{{Error|path|#Errors}} the specified path is invalid.
|-
| '''Examples'''
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.<br/>{{Error|lock|#Errors}} a database is opened by another process.<br/>{{Error|name|XQuery Errors#BaseX Errors}} invalid database name.<br/>{{Error|conflict|#Errors}} the same database was addressed more than once.
|}
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.<br/>{{Error|lock|#Errors}} a database is opened by another process.<br/>{{Error|name|XQuery Errors#BaseX Errors}} invalid database name.<br/>{{Error|conflict|#Errors}} the same database was addressed more than once.
|}
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.<br/>{{Error|name|XQuery Errors#BaseX Errors}} invalid database name.<br/>{{Error|conflict|#Errors}} the same database was addressed more than once.
|-
| '''Examples'''
|-
| '''Errors'''
|{{Error|backup|XQuery Errors#BaseX Errors}} No backup file found.<br/>{{Error|name|XQuery Errors#BaseX Errors}} invalid database name.<br/>{{Error|conflict|#Errors}} the same database was addressed more than once.
|-
| '''Examples'''
|-
| '''Errors'''
|{{Error|lock|#Errors}} a database is opened by another process.<br/>{{Error|name|XQuery Errors#BaseX Errors}} invalid database name.<br/>{{Error|no-backup|XQuery Errors#BaseX Errors}} No backup found.<br/>{{Error|conflict|#Errors}} the same database was addressed more than once.
|-
| '''Examples'''
|-
| width='120' | '''Signatures'''
|{{Func|db:optimize|$db as xs:string|empty-sequence()}}<br/>{{Func|db:optimize|$db as xs:string, $all as xs:boolean|empty-sequence()}}<br/>{{Func|db:optimize|$db as xs:string, $all as xs:boolean, $options as map(*)?|empty-sequence()}}
|-
| '''Summary'''
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.
|-
| '''Examples'''
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.<br/>{{Error|path|#Errors}} the specified source or target path, or one of its descendants, is invalid.
|-
| '''Examples'''
|-
| width='120' | '''Signatures'''
|{{Func|db:replace|$db as xs:string, $path as xs:string, $input as item()|empty-sequence()}}<br/>{{Func|db:replace|$db as xs:string, $path as xs:string, $input as item(), $options as map(*)?|empty-sequence()|empty-sequence()}}
|-
| '''Summary'''
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.<br/>{{Error|target|#Errors}} the path points to a directory.
|-
| '''Examples'''
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.<br/>{{Error|mainmem|#Errors}} the database is not ''persistent'' (stored on disk).
|-
| '''Examples'''
return db:store($db, $trg, db:retrieve($db, $src))
</pre>
|}
 
==db:output==
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|db:output|$result as item()*|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.<br/>The function can only be used together with [[XQuery Update#Updating Expressions|updating expressions]]; if the function is called within a transform expression, its results will be discarded.
|-
| '''Examples'''
|
* {{Code|db:output("Prices have been deleted."), delete node //price}} deletes all {{Code|price}} elements in a database and returns an info message.
|}
 
==db:output-cache==
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|db:output-cache||item()*}}
|-
| '''Summary'''
|Returns the items that have been cached by [[#db:output|db:output]]. It can be used to check which items will eventually be returned as result of an updating function.<br/>This function is ''non-deterministic'': It will return different results before and after items have been cached. It is e. g. useful when writing [[Unit Module|unit tests]].
|}
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.
|}
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.
|-
| '''Examples'''
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.
|-
| '''Summary'''
|-
| '''Errors'''
|{{Error|open|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.
|-
| '''Examples'''
=Errors=
 
{{Mark|Updated with Version 9.0}}:
{| class="wikitable" width="100%"
;Version 9.0
* Added: [[#db:option|db:option]]
* Updated: db:output renamed to {{Function|Update|update:output}}, db:output-cache renamed to {{Function|Update|update:cache}}
* Updated: error codes updated; errors now use the module namespace
administrator, editor
12

edits

Navigation menu