Changes

Jump to navigation Jump to search
1,797 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.
|}
| '''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'''
|
* {{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