Difference between revisions of "Database Module"

From BaseX Documentation
Jump to navigation Jump to search
m (Reverted edits by AW (talk) to last revision by Michael)
Line 1: Line 1:
<p>This module offers utility methods, which can be used for testing and profiling the code. All functions are preceded by the <code>util:</code> prefix. </p>
+
<p>This module contains methods to list and open databases, explicitly apply available index structures, or get information on the database structure. All functions are introduced with the <code>db:</code> prefix.</p>  
 +
==db:system==
  
==util:eval==
+
{|
 +
|-
 +
| width="90" | <b>Signatures</b>
 +
|<code><b>db:system</b>() as xs:string*</code>
 +
 
 +
|-
 +
| <b>Summary</b>
 +
| Lists information on the database system.
 +
|-
 +
| <b>Rules</b>
 +
| This function returns general information on the database system, such as the database path and current database settings.<br />
 +
|}
  
 +
==db:list==
 
{|
 
{|
 
|-
 
|-
 
| width="90" | <b>Signatures</b>
 
| width="90" | <b>Signatures</b>
|<code><b>util:eval</b>($expr as xs:string) as item()*</code>
+
|<code><b>db:list</b>() as xs:string*</code>  
 
|-
 
|-
 
| <b>Summary</b>
 
| <b>Summary</b>
| Evaluates the argument at runtime.
+
| Lists all databases.
 
|-
 
|-
 
| <b>Rules</b>
 
| <b>Rules</b>
| This function dynamically evaluates <code>$expr</code> as XQuery expression and returns the resulting items.<br />
+
| This function returns a <code>xs:string</code> sequence with the names of all databases.<br />
 +
|}
 +
 
 +
==db:open==
 +
{|
 +
|-
 +
| width="90" | <b>Signatures</b>
 +
|<code><b>db:open</b>($name as xs:string) as document-node()</code>
 +
|-
 +
| <b>Summary</b>
 +
| Returns documents from a database.
 +
|-
 +
| <b>Rules</b>
 +
| This function opens the documents of the database specified by <code>$name</code>. The name of the database may be extended by a collection path.<br />
 
|-
 
|-
 
| <b>Examples</b>
 
| <b>Examples</b>
| The expression <code>util:eval("1+3")</code> returns <code>4</code>.<br />
+
| The expression <code>db:open("docs")</code> returns all documents from the database named <code>docs</code>.<br />The expression <code>db:open("docs/one")</code> returns all documents from the database named <code>docs</code> in the subpath <code>one</code>.<br />
 +
|-
 +
| <b>Errors</b>
 +
| <b>[BASX0003]</b> is raised if the database is not found.<br />
 
|}
 
|}
  
==util:run==  
+
==db:open-pre==  
 +
{|
 +
|-
 +
| width="90" | <b>Signatures</b>
 +
|<code> <b>db:open-pre</b>($name as xs:string, $pre as xs:integer) as node()</code>
 +
|-
 +
| <b>Summary</b>
 +
| Returns a specific database node.
 +
|-
 +
| <b>Rules</b>
 +
| This function opens the database specified by <code>$name</code> and returns the node with the <i>pre</i> value specified by <code>$pre</code>.<br />
 +
|-
 +
| <b>Examples</b>
 +
| The expression <code>db:open-pre("docs", 0)</code> returns the first database node from the database named <code>docs</code>.<br />
 +
|-
 +
| <b>Errors</b>
 +
| <b>[BASX0004]</b> is raised if the specified <code>$pre</code> value does not exist in the database.<br />
 +
|}
  
 +
==db:open-id==
 
{|
 
{|
 
|-
 
|-
 
| width="90" | <b>Signatures</b>
 
| width="90" | <b>Signatures</b>
|<code><b>util:run</b>($input as xs:string) as item()*</code>
+
|<code><b>db:open-id</b>($name as xs:string, $id as xs:integer) as node()</code>  
 
|-
 
|-
 
| <b>Summary</b>
 
| <b>Summary</b>
| Opens the argument as file and evaluates it as at runtime.
+
| Returns a specific database node.
 
|-
 
|-
 
| <b>Rules</b>
 
| <b>Rules</b>
| This function opens <code>$input</code> as file, evaluates it as XQuery expression, and returns the resulting items.<br />
+
| This function opens the database specified by <code>$name</code> and returns the node with the <i>id</i> value specified by <code>$id</code>.<br />In contrast to the <i>pre</i> value, the <i>id</i> will remain valid after update operations.<br />
 +
|-
 +
| <b>Errors</b>
 +
| <b>[BASX0004]</b> is raised if the specified <code>$id</code> does not exist in the database.<br />
 
|}
 
|}
  
==util:mb==  
+
==db:text-index==  
 +
{|
 +
|-
 +
| width="90" | <b>Signatures</b>
 +
|<code><b>db:text-index</b>($string as item()) as text()*</code>
 +
|-
 +
| <b>Summary</b>
 +
| Returns results from a text index request.
 +
|-
 +
| <b>Rules</b>
 +
| This function accesses the text index and returns all text nodes that have <code>$string</code> as string value.<br />
 +
|-
 +
| <b>Errors</b>
 +
|<b>[BASX0001]</b> is raised if the index is not available.<br /> <b>[BASX0002]</b> is raised if the context item does not represent a database node.<br />
 +
|}
 +
 
 +
==db:attribute-index==
 +
{|
 +
|-
 +
| width="90" | <b>Signatures</b>
 +
|<code><b>db:attribute-index</b>($string as item()) as attribute()*</code> <br /> <code> <b>db:attribute-index</b>($string as item(), $name as xs:string) as attribute()*</code>
 +
|-
 +
| <b>Summary</b>
 +
| Returns results from a attribute index request.
 +
|-
 +
| <b>Rules</b>
 +
| This function accesses the attribute index and returns all attribute nodes that have <code>$string</code> as string value.<br />If <code>$name</code> is specified, the resulting attribute nodes are filtered by their attribute name.<br />
 +
|-
 +
| <b>Errors</b>
 +
|<b>[BASX0001]</b> is raised if the index is not available.<br /><b>[BASX0002]</b> is raised if the context item does not represent a database node.
 +
|}
  
 +
==db:fulltext-index==
 
{|
 
{|
 
|-
 
|-
 
| width="90" | <b>Signatures</b>
 
| width="90" | <b>Signatures</b>
|<code><b>util:mb</b>($expr as item()) as xs:double</code>
+
|<code><b>db:fulltext-index</b>($text as xs:string) as text()</code>  
|<code><b>util:mb</b>($expr as item(), $cache as xs:boolean) as xs:double</code>
 
 
|-
 
|-
 
| <b>Summary</b>
 
| <b>Summary</b>
| Measures the memory consumption for evaluating the argument.
+
| Returns results from a full-text index request.
 
|-
 
|-
 
| <b>Rules</b>
 
| <b>Rules</b>
| This function measures the amount of memory that is needed to evaluate <code>$expr</code>. If the value of <code>$cache</code> is <code>true()</code>, the result will be cached. The returned <code>xs:double</code> value represents the amount of memory in megabytes.<br />
+
| This function accesses the full-text index and returns all text nodes that contain <code>$text</code>.<br />
 
|-
 
|-
| <b>Examples</b>
+
| <b>Errors</b>
| The expression <code>util:mb("1 to 100000")</code> might return <code>0</code>.<br />The expression <code>util:mb("1 to 100000", true())</code> might return <code>26.678</code>.<br />
+
|<b>[BASX0001]</b> is raised if the index is not available.<br /> <b>[BASX0002]</b> is raised if the context item does not represent a database node.<br />
 
|}
 
|}
 
==util:ms==
 
  
 +
==db:info==
 
{|
 
{|
 
|-
 
|-
 
| width="90" | <b>Signatures</b>
 
| width="90" | <b>Signatures</b>
|<code><b>util:ms</b>($expr as item()) as xs:double</code>
+
|<code> <b>db:info</b>() as xs:string</code>  
|<code><b>util:ms</b>($expr as item(), $cache as xs:boolean) as xs:double</code>
 
 
|-
 
|-
 
| <b>Summary</b>
 
| <b>Summary</b>
| Measures the time needed for evaluating the argument.
+
| Returns database information.
 
|-
 
|-
 
| <b>Rules</b>
 
| <b>Rules</b>
| This function measures the time needed to evaluate <code>$expr</code>. If the value of <code>$cache</code> is <code>true()</code>, the result will be cached. The returned <code>xs:double</code> value represents the needed time in milliseconds.<br />
+
| This function returns information on the database that is referenced by the current context item.<br />
 
|-
 
|-
| <b>Examples</b>
+
| <b>Errors</b>
| The expression <code>util:ms("1 to 100000")</code> might return <code>25.69</code>.<br />The expression <code>util:ms("1 to 100000", true())</code> might return <code>208.12</code>.<br />  
+
|<b>[[BASX0002]]</b> is raised if the context item does not represent a database node.<br />
 
|}
 
|}
  
[[Category:XQuery]]
+
==db:index-info==
 +
{|
 +
|-
 +
| width="90" | <b>Signatures</b>
 +
| <code> <b>db:index-info</b>($type as xs:string) as xs:string</code>
 +
|-
 +
| <b>Summary</b>
 +
| Returns database index information.
 +
|-
 +
| <b>Rules</b>
 +
| This function returns information on an index of the database that is referenced by the current context item.<br /> <code>$type</code> must be one of the values <code>TEXT</code>, <code>ATTRIBUTE</code>, <code>FULLTEXT</code>, <code>PATH</code>, <code>TAG</code>, or <code>ATTNAME</code>.<br />
 +
|-
 +
| <b>Errors</b>
 +
| <b>[BASX0001]</b> is raised if the specified index is not available.<br /> <b>[BASX0002]</b> is raised if the context item does not represent a database node.<br />
 +
|}
 +
[[Category:Commands]]
 +
[[Category:Wikify]]

Revision as of 16:35, 12 December 2010

This module contains methods to list and open databases, explicitly apply available index structures, or get information on the database structure. All functions are introduced with the db: prefix.

db:system

Signatures db:system() as xs:string*
Summary Lists information on the database system.
Rules This function returns general information on the database system, such as the database path and current database settings.

db:list

Signatures db:list() as xs:string*
Summary Lists all databases.
Rules This function returns a xs:string sequence with the names of all databases.

db:open

Signatures db:open($name as xs:string) as document-node()
Summary Returns documents from a database.
Rules This function opens the documents of the database specified by $name. The name of the database may be extended by a collection path.
Examples The expression db:open("docs") returns all documents from the database named docs.
The expression db:open("docs/one") returns all documents from the database named docs in the subpath one.
Errors [BASX0003] is raised if the database is not found.

db:open-pre

Signatures db:open-pre($name as xs:string, $pre as xs:integer) as node()
Summary Returns a specific database node.
Rules This function opens the database specified by $name and returns the node with the pre value specified by $pre.
Examples The expression db:open-pre("docs", 0) returns the first database node from the database named docs.
Errors [BASX0004] is raised if the specified $pre value does not exist in the database.

db:open-id

Signatures db:open-id($name as xs:string, $id as xs:integer) as node()
Summary Returns a specific database node.
Rules This function opens the database specified by $name and returns the node with the id value specified by $id.
In contrast to the pre value, the id will remain valid after update operations.
Errors [BASX0004] is raised if the specified $id does not exist in the database.

db:text-index

Signatures db:text-index($string as item()) as text()*
Summary Returns results from a text index request.
Rules This function accesses the text index and returns all text nodes that have $string as string value.
Errors [BASX0001] is raised if the index is not available.
[BASX0002] is raised if the context item does not represent a database node.

db:attribute-index

Signatures db:attribute-index($string as item()) as attribute()*
db:attribute-index($string as item(), $name as xs:string) as attribute()*
Summary Returns results from a attribute index request.
Rules This function accesses the attribute index and returns all attribute nodes that have $string as string value.
If $name is specified, the resulting attribute nodes are filtered by their attribute name.
Errors [BASX0001] is raised if the index is not available.
[BASX0002] is raised if the context item does not represent a database node.

db:fulltext-index

Signatures db:fulltext-index($text as xs:string) as text()
Summary Returns results from a full-text index request.
Rules This function accesses the full-text index and returns all text nodes that contain $text.
Errors [BASX0001] is raised if the index is not available.
[BASX0002] is raised if the context item does not represent a database node.

db:info

Signatures db:info() as xs:string
Summary Returns database information.
Rules This function returns information on the database that is referenced by the current context item.
Errors BASX0002 is raised if the context item does not represent a database node.

db:index-info

Signatures db:index-info($type as xs:string) as xs:string
Summary Returns database index information.
Rules This function returns information on an index of the database that is referenced by the current context item.
$type must be one of the values TEXT, ATTRIBUTE, FULLTEXT, PATH, TAG, or ATTNAME.
Errors [BASX0001] is raised if the specified index is not available.
[BASX0002] is raised if the context item does not represent a database node.