Changes

Jump to navigation Jump to search
569 bytes added ,  13:22, 24 May 2018
no edit summary
This [[Module Library|XQuery Module]] contains functions to access BaseX server instances from XQuery. With this module, you can execute database commands and evaluate XQuery expressions.
Please note that the client module should always be used to address independent BaseX server instances. You can create deadlocks if you evaluate a query with a server instance, and if you are addressing the same server instance in your query. See the following example: <pre class="brush:xquery">(: Retrieve documents from database :)let $client-id := client:connect('localhost', 1984, 'admin', 'admin')let $docs := client:query($client-id, 'db:open("conflict")')(: Create database with same name :)return db:create('conflict', $docs, $docs ! db:path(.)) </pre> The read-only query cannot be processed, because the <code>conflict</code> database is currently write-locked by the main query. See [[Transaction Management]] for more background information.
=Conventions=
All functions and errors in this module are assigned to the <code><nowiki>http://basex.org/modules/client</nowiki></code> namespace, which is statically bound to the {{Code|client}} prefix.<br/>All errors are assigned to the <code><nowiki>http://basex.org/errors</nowiki></code> namespace, which is statically bound to the {{Code|bxerr}} prefix.
=Functions=
==client:connect==
 
{| width='100%'
|-
|-
|'''Errors'''
|{{Error|BXCL0001connect|#Errors}} an error occurs while creating the session (possible reasons: server not available, access denied).<br/>
|}
==client:execute==
 
{| width='100%'
|-
|-
|'''Errors'''
|{{Error|BXCL0003error|#Errors}} an I/O error occurs while transferring data from or to the server.<br/>{{Error|BXCL0004command|#Errors}} an error occurs while executing a command.
|-
| '''Examples'''
|-
| width='120' | '''Signatures'''
|{{Func|client:query|$id as xs:anyURI, $query as xs:string|item()*}}<br/>{{Func|client:query|$id as xs:anyURI, $query as xs:string, $bindings as map(*)?|item()*}}
|-
| '''Summary'''
|-
|'''Errors'''
|{{Error|BXCL0003error|#Errors}} an I/O error occurs while transferring data from or to the server.<br/>{{Error|BXCL0005query|#Errors}} an error occurs while evaluating a query, and if the original error cannot be extracted from the returned error string.<br/>{{Error|BXCL0006function|#Errors}} function items (including maps and arrays) cannot be returned.
|-
| '''Examples'''
==client:close==
 
{| width='100%'
|-
|-
| '''Summary'''
| This function closes a client session. {{Code|$id}} specifies the session id.<br/>At Opened connections will automatically be closed after the end of query executionXQuery expression has been evaluated, but it is recommendable to explicitly close them with this function if you open sessions will be automatically closedmany connections.
|-
|'''Errors'''
|{{Error|BXCL0003error|#Errors}} an I/O error occurs while transferring data from or to the server.
|}
|Description
|-
|{{Code|BXCL0001command}}| An error occurred while executing a command.|-|{{Code|connect}}
| An error occurred while creating a new session (possible reasons: server not available, access denied).
|-
|{{Code|BXCL0002error}}| The specified session is unknown, An I/O error occurred while transferring data from or has already been closedto the server.
|-
|{{Code|BXCL0003function}}| An I/O error occurred while transferring data from or to the serverFunction items (including maps and arrays) cannot be returned.
|-
|{{Code|BXCL0004id}}| An error occurred while executing a commandThe id with the specified session is unknown, or has already been closed.
|-
|{{Code|BXCL0005query}}
| An error occurred while evaluating a query. Will only be raised if the XQuery error cannot be extracted from the returned error string.
|-
|{{Code|BXCL0006}}
| Function items (including maps and arrays) cannot be returned.
|}
=Changelog=
 
;Version 9.0
 
* Updated: error codes updated; errors now use the module namespace
;Version 8.0
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu