Changes

Jump to navigation Jump to search
2,547 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'''
|Returns a string sequence with The result of this function is dependent on the number of arguments:* Without arguments, the names of all databases:are returned that 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 further restricted by the {{Code|$path}} argument.
|-
| '''Errors'''
| '''Examples'''
|
* {{Code|db:list("docs")}} returns the names of all documents from the of a database named {{Code|docs}}.
|}
|-
| '''Summary'''
|Without arguments, an element is returned for each database that is accessible to the current user:* If no argument is specifiedAn element has a value, a sequence of elements which is returned. A single element contains the name of a the database, and several attributes, which contain the number of stored resources, the modification date of modification, the database size on disk (measured in bytes), and a path to the original database pathinput.* If a database {{Code|$db}} is specified, a sequence an element for each documents and raw file of elements the specified database is returned, comprising information on all resources of the addressed database. :* An element contains has a value, which is the name of the resource, and several attributes, which contain the content type, the modified modification date, the raw flag (which indicates if the resource is binary or XML), and the size of a resource.* For binary resources, The value of the size is attribute depends on the resource type: for documents, it represents the number of bytesnodes; for document resourcesbinary data, it represents the file size is the number of nodes(measured in bytes).
* Returned databases resources can be further restricted by the {{Code|$path}} argument.
|-
| '''Examples'''
|
* {{Code|db:list-details("docsshop")}} returns the names plus additional data info on all resources of all documents from the a database named {{Code|docsshop}}.
|}
* {{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.
|}
==db:token==
 
{{Mark|Introduced with Version 8.4:}}
{| width='100%'
==db:create==
 
{{Mark|Updated with Version 8.4}}: Support for {{Code|ADDCACHE}} option.
{| width='100%'
* {{Code|$inputs}} may be strings or nodes:
** nodes may be of any type except for attributes
** strings may can be a URI pointing to a file/directory references, or an XML strings string (which are 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.** the parsing options are will only applied to impact string input (URIs, XML strings or file/directory references), because nodes have already been parsed.* An existing database will be overwritten. Next, {{Code|db:create}} will be placed last on the * 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.
|-
| '''Errors'''
==db:add==
 
{{Mark|Updated with Version 8.4}}: Support for {{Code|ADDCACHE}} option.
{| width='100%'
|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'''
==db:replace==
 
{{Mark|Updated with Version 8.4}}: Support for {{Code|ADDCACHE}} option.
{| width='100%'
| '''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'''
|-
| '''Summary'''
|Stores Replaces a binary resource specified by {{Code|$input}} in the database {{Code|$db}} and the location specified by {{Code|$path}}, or adds it as new resource.
|-
| '''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