Changes

Jump to navigation Jump to search
5,266 bytes added ,  17:21, 18 October 2011
no edit summary
A [[Database Functions (Snapshot)|preview page]] contains all functions offered by the [http://files.basex.org/releases/latest/ latest stable snapshot].
=General Functions= ==db:systeminfo==
{|
|-
| valign='top' width='90' | '''Signatures'''
|<code><b>db:systeminfo</b>($db as item()) as xs:string</code><br/><code><b>db:info</b>($db as item(), $type as xs:string) as xs:string</code>
|-
| valign='top' | '''Summary'''
|Prints Returns information about for a database.<br />If <code>$type</code> is specified, the function returns information on a database systemindex. It must be one of the values <code>TEXT</code>, <code>ATTRIBUTE</code>, <code>FULLTEXT</code>, including <code>PATH</code>, <code>TAG</code>, or <code>ATTNAME</code>.|-| valign='top' | '''Errors'''|<b>[[XQuery Errors#BaseX Errors|BASX0001]]</b> is raised if the specified index is not available.|-| valign='top' | '''Examples'''|* <code>db:info("DB", "FULLTEXT")</code> returns information about the full-text index in the database path and current database settings<code>DB</code>.
|}
|-
| valign='top' width='90' | '''Signatures'''
|<code><b>db:list</b>() as xs:string*</code><br/><code><b>db:list</b>($db as xs:string) as xs:string*</code><br/><code><b>db:list</b>($db as xs:string, $path as xs:string) as xs:string*</code>
|-
| valign='top' | '''Summary'''
|Returns an <code>xs:string</code> sequence with the names of all databases. If an argument <code>$db</code> is specified, all documents and raw files of the specified database or are returned. The list of resources can be further restricted by the <code>$path</code> argument.<br/><font color='orangered'>Modified in Version 7.0</font>: database and resource path are returnednow specified as two separate arguments.
|}
|-
| valign='top' width='90' | '''Signatures'''
|<code><b>db:open</b>($name db as xs:string) as document-node()*</code><br /><code><b>db:open</b>($db as xs:string, $path as xs:string) as document-node()*</code>
|-
| valign='top' | '''Summary'''
|Returns a sequence with all document nodes contained in the database specified by <code>$namedb</code>. The name of the database returned documents may be extended filtered by a collection the <code>$path</code> argument.<br/><font color='orangered'>Modified in Version 7.0</font>: database and resource pathare now specified as two separate arguments.
|-
| valign='top' | '''Errors'''
|
* <code>db:open("docs")</code> returns all documents from the database named <code>docs</code>.
* <code>db:open("docs/", "one")</code> returns all documents from the database named <code>docs</code> in the subpath <code>one</code>.|} ==db:open-id=={||-| valign='top' width='90' | '''Signatures'''|<code><b>db:open-id</b>($db as item(), $id as xs:integer) as node()</code>|-| valign='top' | '''Summary'''|Opens the database specified by <code>$db</code> and returns the node with the specified <code>$id</code> value.<br />In contrast to the <i>pre</i> value, the <i>id</i> will remain valid after update operations.|-| valign='top' | '''Errors'''|<b>[[XQuery Errors#BaseX Errors|BASX0004]]</b> is raised if the specified <code>$id</code> does not exist in the database.
|}
|-
| valign='top' | '''Summary'''
|Opens the database specified by <code>$namedb</code> and returns the node with the specified <code>$pre</code> value.
|-
| valign='top' | '''Errors'''
|}
==db:opensystem=={||-| valign='top' width='90' | '''Signatures'''|<code><b>db:system</b>() as xs:string</code>|-| valign='top' | '''Summary'''|Prints information about the database system, including the database path and current database settings.|} =Read Operations= ==db:attribute=={||-| valign='top' width='90' | '''Signatures'''|<code><b>db:attribute</b>($db as item(), $string as item()) as attribute()*</code><br/><code><b>db:attribute</b>($db as item(), $string as item(), $attname as xs:string) as attribute()*</code>|-| valign='top' | '''Summary'''|Returns all attribute nodes that have <code>$string</code> as their string value.<br />If <code>$attname</code> is specified, the resulting attribute nodes are filtered by their attribute name.|-| valign='top' | '''Examples'''|* <code>db:attribute("DB", "QUERY", "id")/..</code> returns the parents of all <code>id</code> attribute nodes of the database <code>DB</code> that have <code>QUERY</code> as string value.|} ==db:fulltext==
{|
|-
| valign='top' width='90' | '''Signatures'''
|<code><b>db:open-idfulltext</b>($db as item(), $id text as xs:integeritem()) as nodetext()*</code>
|-
| valign='top' | '''Summary'''
|Opens Returns all text nodes from the database specified by <code>$name</code> and returns the node with full-text index that contain the specified string <code>$idtext</code> value.<br />In contrast to The index full-text options are used for searching, i.e., if the <i>pre</i> valueindex terms have been stemmed, the <i>id</i> search string will remain valid after update operationsbe stemmed as well.
|-
| valign='top' | '''Errors'''
|<b>[[XQuery Errors#BaseX Errors|BASX0004BASX0001]]</b> is raised if the index is not available.|-| valign='top' | '''Examples'''|* <code>db:fulltext("DB", "QUERY")</code> returns all text nodes of the database <code>DB</code> that contain the string <code>QUERY</code>.|} ==db:node-id=={||-| valign='top' width='90' | '''Signatures'''|<code><b>db:node-id</b>($nodes as node()*) as xs:integer*</code>|-| valign='top' | '''Summary'''|Returns the <i>id</i> values of all database nodes specified by <code>$nodes</code>. <i>id</codei> does values are pointers to database nodes, which are not exist in the databasechanged by updates.
|}
|}
==db:node-idretrieve== <font color='orangered'>Introduced with Version 7.0:</font>
{|
|-
| valign='top' width='90' | '''Signatures'''
|<code><b>db:node-idretrieve</b>($nodes db as node()*xs:string, $path as xs:string) as xs:integer*raw</code>
|-
| valign='top' | '''Summary'''
|Returns Retrieves the binary resource specified by <icode>id$path</icode> values of all database nodes specified by in the (implementation specific) <code>$nodesxs:raw</code>format.|-| valign='top' | '''Errors'''|<b>[[XQuery Errors#Functions Errors|FODC0002]]</b> is raised if the addressed resource is not found or cannot be retrieved. |-| valign='top' | '''Examples'''|* <icode>iddeclare option output:method 'raw';<br/i> values are pointers to database nodesdb:retrieve("DB", which are not changed by updates"music/01.mp3")</code> returns the specified audio file as raw data.
|}
|}
=Updates= ==db:attributeadd=<font color='orangered'>Modified in Version 7.0:</font> 
{|
|-
| valign='top' width='90' | '''Signatures'''
|<code><b>db:attributeadd</b>($db as item(), $string input as item()) as attributeempty-sequence()*</code><br/><code><b>db:attributeadd</b>($db as item(), $string input as item(), $attname path as xs:string) as attributeempty-sequence()*</code>
|-
| valign='top' | '''Summary'''
|Returns all attribute nodes Add documents specified by <code>$input</code> to the database <code>$db</code> and the specified <code>$path</code>.|-| valign='top' | '''Errors'''|<b>[[XQuery Errors#BaseX Errors|BASX0002]]</b> is raised if <code>$db</code> is not a database node.<br/><b>[[XQuery Errors#BaseX Errors|BASX0003]]</b> is raised if <code>$db</code> is a string and a database with that have name cannot be opened.<br/><b>[[XQuery Errors#Functions Errors|FODC0002]]</b> is raised if <code>$stringinput</code> as their is a string valuerepresenting a path, which cannot be read.<br />If <b>[[XQuery Errors#Update Errors|FOUP0001]]</b> is raised if <code>$attnameinput</code> is specified, the resulting attribute nodes are filtered by their attribute namenot a string and not a document node.
|-
| valign='top' | '''Examples'''
|
* <code>db:attributeadd("DB", "QUERY/home/dir/doc.xml")</code> adds the file <code>/home/dir/doc.xml</code> to the database <code>DB</code>.* <code>db:add("DB", "id<a/>", "doc.xml")</code> adds a document with content <code>&lt;a/&gt;</code> to the database <code>DB</code> under the name <code>doc.xml</code>.* <code>db:add("DB", document { <a/> }, "doc.xml")</code> adds the document node to the database <code>DB</code> returns under the parents of name <code>doc.xml</code>.* <code>db:add("DB", "/home/dir", "docs/dir")</code> adds all documents in <code>id/home/dir</code> attribute nodes of to the database <code>DB</code> that have under the path <code>QUERYdocs/dir</code> as string value.
|}
==db:fulltextdelete==
{|
|-
| valign='top' width='90' | '''Signatures'''
|<code><b>db:fulltextdelete</b>($db as item(), $text path as item()xs:string) as textempty-sequence()*</code>
|-
| valign='top' | '''Summary'''
|Returns all text nodes from the full-text index that contain Delete document(s), specified by <code>$path</code> in the string database <code>$textdb</code>. The index full-text options are used for searching, i.e., if the index terms have been stemmed, the search string will be stemmed as well.
|-
| valign='top' | '''Errors'''
|<b>[[XQuery Errors#BaseX Errors|BASX0001BASX0002]]</b> is raised if the index <code>$db</code> is not availablea database node.<br/><b>[[XQuery Errors#BaseX Errors|BASX0003]]</b> is raised if <code>$db</code> is a string and a database with that name cannot be opened.
|-
| valign='top' | '''Examples'''
|
* <code>db:fulltextdelete("DB", "QUERYdocs/dir/doc.xml")</code> returns all text nodes of deletes the document <code>docs/dir/doc.xml</code> in the database <code>DB</code> that contain .* <code>db:delete("DB", "docs/dir", "<a/>")</code> deletes all documents with paths beginning with <code>docs/dir</code> in the string database <code>QUERYDB</code>.
|}
==db:infooptimize==
{|
|-
| valign='top' width='90' | '''Signatures'''
|<code><b>db:infooptimize</b>($db as item()) as xs:string) as empty-sequence()</code><br/><code><b>db:infooptimize</b>($db as item()xs:string, $type all as xs:stringboolean) as xs:stringempty-sequence()</code>
|-
| valign='top' | '''Summary'''
|Returns information for a Optimize the data structures of the database.<br />If <code>$typedb</code> is specified, the function returns information on a database index. It must be one of the values If <code>TEXT$all</code>, is set to <code>ATTRIBUTEtrue()</code>, <code>FULLTEXT</code>, <code>PATH</code>, <code>TAG</code>, or <code>ATTNAME</code>then the whole database will be rebuilt.
|-
| valign='top' | '''Errors'''
|<b>[[XQuery Errors#BaseX Errors|BASX0001BASX0002]]</b> is raised if <code>$db</code> is not a database node.<br/><b>[[XQuery Errors#BaseX Errors|BASX0003]]</b> is raised if <code>$db</code> is a string and a database with that name cannot be opened.<br/><b>[[XQuery Errors#BaseX Errors|BASX0014]]</b> is raised if an error occurs during optimizing the data structures.<br/><b>[[XQuery Errors#BaseX Errors|BASX0015]]</b> is raised if the <code>$all</code> flag is set to <code>true()</code>, but the specified index database is not availablean in-memory database.<br/><b>[[XQuery Errors#BaseX Errors|BASX0016]]</b> is raised if the database <code>$db</code> is in use by other user(s).
|-
| valign='top' | '''Examples'''
|
* <code>db:infooptimize("DB", )</code> optimizes the database structures of the database <code>DB</code>.* <code>db:optimize("FULLTEXTDB", true())</code> returns information about the full-text index in optimizes all database structures of the database <code>DB</code>.
|}
==db:addrename==
{|
|-
| valign='top' width='90' | '''Signatures'''
|<code><b>db:addrename</b>($db as item(), $input as item()*) as empty-sequence()</code><br/><code><b>db:add</b>($db as item(), $input as item()*, $name as xs:string) as empty-sequence()</code><br/><code><b>db:add</b>($db as item(), $input as item()*, $name path as xs:string, $path newpath as xs:string) as empty-sequence()</code>
|-
| valign='top' | '''Summary'''
|Add documents Rename document(s), specified by <code>$inputpath</code> to the database <code>$dbnewpath</code>, using an optional document name in the database <code>$name</code> and an optional path <code>$pathdb</code>.
|-
| valign='top' | '''Errors'''
|<b>[[XQuery Errors#BaseX Errors|BASX0002]]</b> is raised if <code>$db</code> is not a database node.<br/><b>[[XQuery Errors#BaseX Errors|BASX0003]]</b> is raised if <code>$db</code> is a string and a database with that name cannot be openopened.<br/><b>[[XQuery Errors#Functions BaseX Errors|FODC0002BASX0013]]</b> is raised if <code>$input</code> is a string representing a path, which cannot new document name(s) will be read.<br/><b>[[XQuery Errors#Update Errors|FOUP0001]]</b> is raised if <code>$input</code> is not a string and not a document nodeempty.
|-
| valign='top' | '''Examples'''
|
* <code>db:addrename("DB", "/homedocs/dir/doc.xml")</code> adds the file <code>/home, "docs/dir/docnewdoc.xml")</code> to renames the database document <code>DB<docs/code>.* <code>db:add("DB", "<adir/>", "doc.xml")</code> adds a document with content <code>&lt;a/&gt;</code> to the database <code>DB<docs/code> under the name <code>doc.xml</code>.* <code>db:add("DB", document { <adir/> }, "docnewdoc.xml")</code> adds the document node to in the database <code>DB</code> under the name <code>doc.xml</code>.* <code>db:addrename("DB", "/homedocs/dir", "", "docs/dirnewdir")</code> adds renames all documents in with paths beginning with <code>/homedocs/dir</code> to the database paths beginning with <code>DBdocs/newdir</code> under in the path database <code>docs/dirDB</code>.
|}
|-
| valign='top' | '''Errors'''
|<b>[[XQuery Errors#BaseX Errors|BASX0002]]</b> is raised if <code>$db</code> is not a database node.<br/><b>[[XQuery Errors#BaseX Errors|BASX0003]]</b> is raised if <code>$db</code> is a string and a database with that name cannot be openopened.<br/><b>[[XQuery Errors#BaseX Errors|BASX0012]]</b> is raised if <code>$path</code> is not a single document path.<br/><b>[[XQuery Errors#Functions Errors|FODC0002]]</b> is raised if <code>$input</code> is a string representing a path, which cannot be read.<br/><b>[[XQuery Errors#Update Errors|FOUP0001]]</b> is raised if <code>$input</code> is not a string and not a document node.
|-
| valign='top' | '''Examples'''
|}
==db:deletestore== <font color='orangered'>Introduced with Version 7.0:</font>
{|
|-
| valign='top' width='90' | '''Signatures'''
|<code><b>db:deletestore</b>($db as item()xs:string, $path as xs:string, $data as item()) as empty-sequence()</code>
|-
| valign='top' | '''Summary'''
|Delete document(s), Stores a binary resource specified by <code>$pathdata</code> in at the database location specified by <code>$dbpath</code>.
|-
| valign='top' | '''Errors'''
|<b>[[XQuery Errors#BaseX Update Errors|BASX0002FOUP0002]]</b> is raised if <code>$db</code> is not a database node.<br/><b>[[XQuery Errors#BaseX Errors|BASX0003]]</b> is raised if <code>$db</code> is a string and a database with that name the resource cannot be openstored at the specified location.
|-
| valign='top' | '''Examples'''
|
* <code>db:deletestore("DB", "docsvideo/dir/docsample.xmlmov")</code> deletes the document <code>docs/dir/doc.xml</code> in the database <code>DB</code>.* <code>db, file:deleteread-binary("DB", "docs/dir", "<a/>"'video.mov'))</code> deletes all documents with paths beginning with <code>docs/dir</code> in stores the addressed video file at the database <code>DB</code>specified location.
|}
=Helper Functions= ==db:renamecontent-type=<font color='orangered'>Introduced with Version 7.0:</font>
{|
|-
| valign='top' width='90' | '''Signatures'''
|<code><b>db:renamecontent-type</b>($db as item()xs:string, $path as xs:string, $newpath ) as xs:string) as empty-sequence()</code>
|-
| valign='top' | '''Summary'''
|Rename document(s), Retrieves the content type of the resource specified by <code>$path</code> . Currently, the implementation uses the file extension to recognize the content-type of a resource stored in the database (this mechanism is provided by Java). Content-type <code>$newpathapplication/xml</code> will be returned for any XML document stored in the database <code>$db</code>, regardless of its file name extension.
|-
| valign='top' | '''Errors'''
|<b>[[XQuery Errors#BaseX Functions Errors|BASX0002FODC0002]]</b> is raised if <code>$db</code> the addressed resource is not a database node.<br/><b>[[XQuery Errors#BaseX Errors|BASX0003]]</b> is raised if <code>$db</code> is a string and a database with that name found or cannot be open.<br/><b>[[XQuery Errors#BaseX Errors|BASX0013]]</b> is raised if new document name(s) will be emptyretrieved.
|-
| valign='top' | '''Examples'''
|
* <code>db:renamecontent-type("DB", "docs/dir/docdoc01.xml", "docs/dir/newdoc.xmlpdf")</code> renames the document returns <code>docsapplication/dir/doc.xmlpdf</code> to .* <code>db:content-type("DB", "docs/dir/newdocdoc01.xml")</code> in the database returns <code>DBapplication/xml</code>.* <code>db:renamecontent-type("DB", "docs/dir", "docs/newdirdoc01")</code> renames all documents with paths beginning with returns <code>docsapplication/dirxml</code> to paths beginning with , if <code>db:is-xml("DB", "docs/newdirdoc01")</code> in the database returns <code>DBtrue</code>.
|}
==db:optimizeevent==
{|
|-
| valign='top' width='90' | '''Signatures'''
|<code><b>db:optimizeevent</b>($db name as xs:string) , $query as empty-sequenceitem()</code><br/><code><b>db:optimize</b>($db as xs:string, $all as xs:boolean) as empty-sequence()</code>
|-
| valign='top' | '''Summary'''
|Optimize the data structures of the database Executes a <code>$dbquery</code>. If and sends the resulting value to all clients watching the [[Events|Event]] with the specified <code>$allname</code> is set . No event will be sent to <code>true()</code>, then the whole database will be rebuiltclient that fired the event.
|-
| valign='top' | '''Errors'''
|<b>[[XQuery Errors#BaseX Errors|BASX0002BASX0009]]</b> is raised if <code>$db</code> the specified event is not a database nodeunknown.<br/><b>[[XQuery ErrorsXQuery_Errors#BaseX ErrorsSerialization_Errors|BASX0003SEPM0016]]</b> is raised if serialization errors occurred while sending the value.<br/>|} ==db:exists== <font color='orangered'>Introduced with Version 7.0:</font>{||-| valign='top' width='90' | '''Signatures'''|<code><b>db:exists</b>($dbas xs:string) as xs:boolean</code> is a string and a database with that name cannot be open.<br/><code><b>[[XQuery Errors#BaseX Errors|BASX0014]]db:exists</b> is raised ($db as xs:string, $path as xs:string) as xs:boolean</code>|-| valign='top' | '''Summary'''|Checks if an error occurs during optimizing the data structuresspecified database or resource exists.Returns <code>false</code> if a database directory is specified.|-| valign='top' | '''Examples'''|* <code>db:exists("DB")<br/code>returns <bcode>[[XQuery Errors#BaseX Errors|BASX0015]]true</bcode> is raised if the database <code>$allDB</code> flag is set to exists.* <code>truedb:exists("DB", "resource")</code>, but the database returns <code>true</code> if <code>resource</code> is an inXML document or a raw file.|} ==db:is-memory databaseraw== <font color='orangered'>Introduced with Version 7.0:<br/font>{||-| valign='top' width='90' | '''Signatures'''|<bcode>[[XQuery Errors#BaseX Errors|BASX0016]]</b> db:is raised if the database -raw<code/b>($dbas xs:string, $path as xs:string) as xs:boolean</code> |-| valign='top' | '''Summary'''|Checks if the specified resource exists and if it is in use by other user(s)a raw file.
|-
| valign='top' | '''Examples'''
|
* <code>db:optimizeis-raw("DB", "music/01.mp3")</code> optimizes the database structures of the database returns <code>true</code>.|} ==db:is-xml== <font color='orangered'>Introduced with Version 7.0:</font>{||-| valign='top' width='90' | '''Signatures'''|<code>DB<b>db:is-xml</b>($db as xs:string, $path as xs:string) as xs:boolean</code>|-| valign='top' | '''Summary'''|Checks if the specified resource exists and if it is an XML document.|-| valign='top' | '''Examples'''|* <code>db:optimizeis-xml("DB", true()"dir/doc.xml")</code> optimizes all database structures of the database returns <code>DBtrue</code>.
|}
[[Category:XQuery]]
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu