Changes

Jump to navigation Jump to search
133 bytes added ,  17:36, 1 December 2023
m
Text replacement - "</syntaxhighlight>" to "</pre>"
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:
<syntaxhighlight pre lang="'xquery"'>
(: Retrieve documents from database :)
let $client-id := client:connect('localhost', 1984, 'admin', '...')
(: Create database with same name :)
return db:create('conflict', $docs, $docs ! db:path(.))
</syntaxhighlightpre>
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.
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''|{{Func|<pre>client:connect|( $host as xs:string, $port as xs:integer, $username as xs:string, $password as xs:string|) as xs:anyURI}}<br/ pre>
|- valign="top"
|'''Summary'''
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''|{{Func|<pre>client:execute|( $id as xs:anyURI, $command as xs:string|) as xs:string}}</pre>
|- valign="top"
| '''Summary'''
| '''Examples'''
|The following query creates a new database {{Code|TEST}} on a remote BaseX server:
<syntaxhighlight pre lang="'xquery"'>
client:connect('basex.server.org', 8080, 'admin', '...') !
client:execute(., 'create database TEST')
</syntaxhighlightpre>
|}
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''|{{Func|<pre>client:info|( $id as xs:anyURI|) as xs:string}}</pre>
|- valign="top"
| '''Summary'''
==client:query==
 
{{Announce|Updated with Version 11}}: Clark notation replaced with Expanded QNames notation.
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''|{{Func|client:query|$id as xs:anyURI, $query as xs:string|item()*}}<br/pre>{{Func|client:query|( $id as xs:anyURI, $query as xs:string, $bindings as map(*)?| := ()) as item()*}}</pre>
|- valign="top"
| '''Summary'''
|Evaluates a query and returns the result as sequence. The parameter {{Code|$id}} contains the session id returned by {{Function||client:connect}}, and {{Code|$query}} represents the query string, which will be evaluated by the server.<br />Variables and the context item can be declared via {{Code|$bindings}}. The specified keys must be QNames or strings:
* If a key is a QName, it will be directly adopted as variable name.
* If a key is a string, it may be prefixed with a dollar sign. A namespace can be specified using the [http://www[XQuery 3.jclark.com/xml/xmlns.htm Clark Notation0#Expanded QNames|Expanded QNames]]notation. If the specified string is empty, the value will be bound to the context item.
|- valign="top"
|'''Errors'''
| '''Examples'''
|The following query sends a query on a local server instance, binds the integer {{Code|123}} to the variable {{Code|$n}} and returns {{Code|246}}:
<syntaxhighlight pre lang="'xquery"'>
let $c := client:connect('localhost', 1984, 'admin', '...')
return client:query($c, "declare variable $n external; $n * 2", map { 'n': 123 })
</syntaxhighlightpre>
The following query performs a query on a first server, the results of which are passed on to a second server:
<syntaxhighlight pre lang="'xquery"'>
let $c1 := client:connect('basex1.server.org', 8080, 'jack', 'C0S19tt2X')
let $c2 := client:connect('basex2.server.org', 8080, 'john', '465wFHe26')
for $it in client:query($c1, '1 to 10')
return client:query($c2, $it || '* 2')
</syntaxhighlightpre>
|}
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''|{{Func|<pre>client:close|( $id as xs:anyURI|) as empty-sequence()}}</pre>
|- valign="top"
| '''Summary'''
=Changelog=
 
;Version 11.0
* Updated: Clark notation replaced with [[XQuery 3.0#Expanded QNames|Expanded QNames]] notation.
;Version 9.0
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu