Changes

Jump to navigation Jump to search
522 bytes added ,  14:24, 27 February 2020
no edit summary
==xquery:eval==
 
{{Mark|Updated with 9.2}}: First argument may be a URI (xquery:invoke was removed).
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|xquery:eval|$query as xs:anyAtomicType|item()*}}<br />{{Func|xquery:eval|$query as xs:stringanyAtomicType, $bindings as map(*)?|item()*}}<br />{{Func|xquery:eval|$query as xs:stringanyAtomicType, $bindings as map(*)?, $options as map(*)?|item()*}}<br />
|-
| '''Summary'''
|Evaluates the supplied {{Code|$query}} and returns the resulting items. If the query is of type {{Code|xs:anyURI}}, the module located at this URI will be retrieved (a relative URI will be resolved against the static base URI). Otherwise, the input will is expected to be evaluated as query of type {{Code|xs:string}}.
Variables and context items 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.
|
* {{Code|xquery:eval("1+3")}} returns {{Code|4}}.<br />
* If a URI is supplied, the query in the specified file will be evaluated:
<syntaxhighlight lang="xquery">
xquery:eval(xs:anyURI('cleanup.xq'))
</syntaxhighlight>
* You can bind the context and e.g. operate on a certain database only:<br />
<pre classsyntaxhighlight lang='brush:"xquery'">
xquery:eval("//country", map { '': db:open('factbook') })
</presyntaxhighlight>
* The following expressions use strings as keys. All of them return 'XML':<br/>
<pre classsyntaxhighlight lang='brush:"xquery'">
xquery:eval(".", map { '': 'XML' }),
map { '{URI}xml': 'XML' }
)
</presyntaxhighlight>
* The following expressions use QNames as keys. All of them return 'XML':<br/>
<pre classsyntaxhighlight lang='brush:"xquery'">
declare namespace pref = 'URI';
let $vars := map { xs:QName('pref:xml'): 'XML' }
return xquery:eval($query, $vars)
</presyntaxhighlight>
|}
==xquery:eval-update==
 
{{Mark|Updated with 9.2}}: First argument may be a URI (xquery:invoke-update was removed).
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|xquery:eval-update|$query as xs:stringanyAtomicType|item()*}}<br />{{Func|xquery:eval-update|$query as xs:stringanyAtomicType, $bindings as map(*)?|item()*}}<br />{{Func|xquery:eval-update|$query as xs:stringanyAtomicType, $bindings as map(*)?, $options as map(*)?|item()*}}<br />
|-
| '''Summary'''
| '''Errors'''
|{{Error|update|#Errors}} the query contains no [[XQuery Update#Updating Expressions|updating expressions]].<br/>{{Error|permission|#Errors}} insufficient permissions for evaluating the query.<br/>{{Error|timeout|#Errors}} query execution exceeded timeout.<br/>{{Error|limit|#Errors}} query execution exceeded memory limit.<br/>{{Error|nested|#Errors}} nested query evaluation is not allowed.<br/>Any other error that may occur while evaluating the query.
|-
| '''Examples'''
|
* Removes entries from a temporary databases and returns an info string:
<syntaxhighlight lang="xquery">
xquery:eval-update("
delete node db:open('tmp')/*,
update:output('TEMPORARY DATABASE WAS CLEANED UP')
")
</syntaxhighlight>
|}
* {{Code|compile}}: additionally compiles the query after parsing it. By default, this option is {{Code|false}}.
* {{Code|plan}}: returns an XML representation of the internal query plan. By default, this option is {{Code|true}}. The naming of the expressions in the query plan may change over time
* {{Code|pass}}: passes on by default, the original option is {{Code|false}}. If an error info (is raised, the line and /column number, and the optional file uri)will refer to the location of the function call. By default, this  If the option is {{Code|false}}enabled, the line/column and file uri will be adopted from the raised error.
* {{Code|base-uri}}: set [https://www.w3.org/TR/xquery-31/#dt-static-base-uri base-uri property] for the query. This URI will be used when resolving relative URIs by functions such as {{Code|fn:doc}}.
|-
|
* {{Code|xquery:parse("1 + 3")}} returns:
<pre classsyntaxhighlight lang='brush:"xml'">
<MainModule updating="false">
<QueryPlan compiled="false">
</QueryPlan>
</MainModule>
</presyntaxhighlight>
|}
|
* The following function sleeps in parallel; it will be finished in 1 second if your system has at least 2 cores:
<pre classsyntaxhighlight lang='brush:"xquery'">
let $f := function() { prof:sleep(1000) }
return xquery:fork-join(($f, $f))
</presyntaxhighlight>
* In the following query, up to four URLs will be requested in parallel:
<pre classsyntaxhighlight lang='brush:"xquery'">
xquery:fork-join(
for $segment in 1 to 4
return function() { http:send-request((), $url) }
)
</presyntaxhighlight>
|-
|'''Errors'''
;Version 9.2
* Deleted: xquery:invoke, xquery:invoke-update (merged with [[#xquery:invokeeval|xquery:invokeeval]], and [[#xquery:invokeeval-update|xquery:invokeeval-update]] (merged with xquery:eval and xquery:eval-update)
;Version 9.0
Bureaucrats, editor, reviewer, Administrators
13,551

edits

Navigation menu