Changes

Jump to navigation Jump to search
95 bytes added ,  14:24, 27 February 2020
no edit summary
==xquery:eval==
 
{{Mark|Updated with 9.2}}: First argument can be a URI (xquery:invoke was removed).
{| width='100%'
|
* {{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)
</pre>* If a URI is supplied, the query in the specified file will be evaluated:<pre class='brush:xquery'>xquery:eval(xs:anyURI('cleanup.xq'))</presyntaxhighlight>
|}
==xquery:eval-update==
 
{{Mark|Updated with 9.2}}: First argument may be a URI (xquery:invoke-update was removed).
{| width='100%'
|
* Removes entries from a temporary databases and returns an info string:
<pre classsyntaxhighlight lang="brush:xquery">
xquery:eval-update("
delete node db:open('tmp')/*,
update:output('TEMPORARY DATABASE WAS CLEANED UP')
")
</presyntaxhighlight>
|}
* {{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'''
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu