Changes

Jump to navigation Jump to search
2,277 bytes added ,  11:24, 20 March 2017
==Database Nodes==
Database nodes are XML nodes which are either stored in a persistent database , or part of which contained in 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">
| '''Errors'''
|{{Error|BXDB0002|XQuery Errors#BaseX Errors}} the addressed database does not exist or could not be opened.
|}
 
==db:property==
 
{{Mark|Introduced with Version 8.6}}:
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|db:property|$db as xs:string, $property as xs:string|xs:anyAtomicType}}
|-
| '''Summary'''
|Returns the specified {{Code|$property}} of the database {{Code|$db}}. The available properties are the ones returned by [[#db:info|db:info]].
|-
| '''Errors'''
|{{Error|BXDB0017|XQuery Errors#BaseX Errors}} the specified property is unknown.
|-
| '''Examples'''
|
* <code>db:property('db', 'size')</code> returns the number of bytes occupied by the database <code>db</code>.
* <code>db:property('xmark', 'textindex')</code> indicates if the <code>xmark</code> database has a text index.
* <code>db:property('discogs', 'uptodate')</code> indicates if the database statistics and index structures of the <code>discogs</code> database are up-to-date.
|}
| '''Summary'''
|The result of this function is dependent on the number of arguments:
* Without arguments, the names of all databases are returnedthat are accessible to the current user.
* If a database {{Code|$db}} is specified, all documents and raw files of the specified database are returned.
* The list of returned resources can be restricted by the {{Code|$path}} argument.
|-
| '''Summary'''
|Without arguments, an element is returned for each databasethat is accessible to the current user:
* An element has a value, which is the name of the database, and several attributes, which contain the number of stored resources, the modification date, the database size on disk (measured in bytes), and a path to the original database input.
If a database {{Code|$db}} is specified, an element for each documents and raw file of the specified database is returned:
* {{Code|db:retrieve("DB", "music/01.mp3")}} returns the specified audio file as raw data.
* <code><nowiki>stream:materialize(db:retrieve("DB", "music/01.mp3"))</nowiki></code> materializes the streamable result in main-memory before returning it.
* <code><nowiki>convert:binary-to-string(db:retrieve("DB", "info.txt"), 'UTF-8')</nowiki></code> converts a binary database resource as UTF-8 text and returns a string.
|}
** strings can be a URI pointing to a file/directory or an XML string (which is detected by the leading <code>&lt;</code> character)
** a path must be specified if the input is not a file or directory reference
* The parsing and indexing behavior can be controlled via {{Code|$options}} argument can be used to change the indexing behavior:** the allowed options are {{Option|ADDCACHE}} and the [[Options#Indexing|indexing]], [[Options#Full-TextIndexing|full-textindexing]], [[Options#Parsing|parsing]] and [[Options#XML Parsing|XML parsing]] options, all in lower case.** parsing options are will only applied to impact string input (URIs, XML strings or file/directory references) specified via this command. If you plan to add data in a subsequent step, you should specify your options along with these commandsbecause nodes have already been parsed.
* An existing database will be overwritten.
* Database creation takes place after most other update operations (see [[XQuery Update#Pending Update List|Pending Update List]]). As a consequence, a newly created database cannot be addressed in the same query.
|Adds documents specified by {{Code|$input}} to the database {{Code|$db}} with the specified {{Code|$path}}:
* A document with the same path may occur more than once in a database. If you want to enforce single instances, use [[#db:replace|db:replace]] instead.
* For more information on the arguments, see See [[#db:create|db:create]] (note that for more details on the specified input argument.* The parsing behavior can be controlled via {{Code|$options}}:** allowed options cannot be are {{Option|ADDCACHE}} and the [[Options#IndexingParsing|indexingparsing]] and [[Options#Full-TextXML Parsing|full-textXML parsing]] options, all in lower case** parsing options will only impact string input (URIs, XML strings)., because nodes have already been parsed
|-
| '''Errors'''
| '''Examples'''
|
* {{Code|<code>db:add("DB", "/home/dir/doc.xml")}} </code> adds the file {{Code|/home/dir/doc.xml}} to the database {{Code|DB}}.* {{Code|<code>db:add("DB", <a/>, "doc.xml")}} </code> adds a document node to the database {{Code|DB}} under the name {{Code|doc.xml}}.* {{Code|<code>db:add("DB", "/home/dir", "docs/dir", map { 'addcache': true()}} )</code> adds all documents in {{Code|/home/dir}} to the database {{Code|DB}} under the path {{Code|docs/dir}}. In order to reduce memory consumption, the files will be cached before being added to the database.
|}
|-
| width='120' | '''Signatures'''
|{{Func|db:copy|$db as xs:string, $newname name as xs:string|empty-sequence()}}
|-
| '''Summary'''
|Creates a copy of the database specified by {{Code|$db}} to , which will be called {{Code|$newnamename}}.
|-
| '''Errors'''
|-
| width='120' | '''Signatures'''
|{{Func|db:alter|$db as xs:string, $newname name as xs:string|empty-sequence()}}
|-
| '''Summary'''
|Renames the database specified by {{Code|$db}} to {{Code|$newnamename}}.
|-
| '''Errors'''
| '''Summary'''
|Replaces a resource, specified by {{Code|$path}}, in the database {{Code|$db}} with the contents of {{Code|$input}}, or adds it as a new resource:
* See [[#db:addcreate|db:addcreate]] for more details on the arguments input argument.* The parsing behavior can be controlled via {{Code|$options}}:** allowed options are {{Option|ADDCACHE}} and the [[Options#Parsing|parsing]] and [[Options#XML Parsing|XML parsing]] options, all in lower case** parsing options will only impact string input (for URIs, XML strings), because nodes have already been parsed* For historical reasons, the order of the 2nd and 3rd argument differs!).is different to [[#db:add|db:add]] and [[#db:create|db:create]]
|-
| '''Errors'''
|
* {{Code|db:store("DB", "video/sample.mov", file:read-binary('video.mov'))}} stores the addressed video file at the specified location.
* With the following query, you can copy full directories:
<pre class="brush:xquery">
let $db := 'db'
let $src-path := 'src/'
let $trg-path := 'trg/'
for $src in db:list($db, $src-path)
where db:is-raw($db, $src)
let $trg := $trg-path || substring-after($src, $src-path)
return db:store($db, $trg, db:retrieve($db, $src))
</pre>
|}
|{{Code|BXDB0014}}
|Path points to a directory.
|-
|{{Code|BXDB0015}}
|No backup is found.
|-
|{{Code|BXDB0016}}
|Name of the source and target database is equal.
|-
|{{Code|BXDB0017}}
|The specified property is unknown..
|}
=Changelog=
 
;Version 8.6
* Added: [[#db:property|db:property]]
;Version 8.4
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu