Changes

Jump to navigation Jump to search
571 bytes added ,  18:39, 1 December 2023
m
Text replacement - "syntaxhighlight" to "pre"
==xquery:eval==
 
{{Announce|Updated with Version 11}}: The Clark notation was replaced with the [[XQuery 3.0#Expanded QNames|Expanded QNames]] notation.
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|xquery:eval|$query as xs:anyAtomicType|item()*}}<br /pre>{{Func|xquery:eval|( $query as xs:anyAtomicType, $bindings as map(*)?|item()* := map { }}<br />{{Func|xquery:eval|$query as xs:anyAtomicType, $bindings options as map(*)?, $options as := map(*{ })?|as item()*}}<br /pre>|-valign="top"
| '''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 is expected to be 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.
* It a key is a string, it may be prefixed with a dollar sign. 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.
The {{Code|$options}} parameter contains evaluation options:
* {{Code|base-uri}}: set [https://www.w3.org/TR/xquery-31/#dt-static-base-uri base-uri property] for the query. Overwrites the base URI of the query; will be used when resolving relative URIs by functions such as {{Code|fn:doc}}.
* {{Code|pass}}: passes on the original error info (line and column number, optional file uri). By default, this option is {{Code|false}}.
|-valign="top"
| '''Errors'''
|{{Error|update|#Errors}} the query contains [[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.
|-valign="top"
| '''Examples'''
|
* {{Code|xquery:eval("1+3")}} returns {{Code|4}}.<br />
* If a URI is supplied, the query in the specified file will be evaluated:
<syntaxhighlight pre lang="'xquery"'>
xquery:eval(xs:anyURI('cleanup.xq'))
</syntaxhighlightpre>* You can bind the context and e.g. operate on a certain database only:<br /><syntaxhighlight pre lang="'xquery"'>xquery:eval("//country", map { '': db:openget('factbook') })</syntaxhighlightpre>
* The following expressions use strings as keys. All of them return 'XML':<br/>
<syntaxhighlight pre lang="'xquery"'>
xquery:eval(".", map { '': 'XML' }),
map { '{URI}xml': 'XML' }
)
</syntaxhighlightpre>
* The following expressions use QNames as keys. All of them return 'XML':<br/>
<syntaxhighlight pre lang="'xquery"'>
declare namespace pref = 'URI';
let $vars := map { xs:QName('pref:xml'): 'XML' }
return xquery:eval($query, $vars)
</syntaxhighlightpre>
|}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|xquery:eval-update|$query as xs:anyAtomicType|item()*}}<br /pre>{{Func|xquery:eval-update|( $query as xs:anyAtomicType, $bindings as map(*)?|item := ()*}}<br />{{Func|xquery:eval-update|$query as xs:anyAtomicType, $bindings options as map(*)?, $options as map := (*)?|) as item()*}}<br /pre>|-valign="top"
| '''Summary'''
|Evaluates a query as updating expression. All updates will be added to the [[XQuery Update#Pending Update List|Pending Update List]] of the main query and performed after the evaluation of the main query.<br />The rules for all arguments are the same as for {{Function||xquery:eval}}.|-valign="top"
| '''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.
|-valign="top"
| '''Examples'''
|
* Removes entries from a temporary databases and returns an info string:
<syntaxhighlight pre lang="'xquery"'>
xquery:eval-update("
delete node db:openget('tmp')/*,
update:output('TEMPORARY DATABASE WAS CLEANED UP')
")
</syntaxhighlightpre>
|}
==xquery:parse==
 
{{Announce|Updated with Version 10:}} {{Code|$query}} can additionally be of type {{Code|xs:anyURI}}.
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|xquery:parse|$query as xs:anyAtomicType|item()?}}<br /pre>{{Func|xquery:parse|( $query as xs:anyAtomicType, $options as map(*)?| := map { }) as item()?}}<br /pre>|-valign="top"
| '''Summary'''
|Parses the specified {{Code|$query}} as XQuery module and returns the resulting query plan. 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 is expected to be of type {{Code|xs:string}}. The {{Code|$options}} parameter influences the output:
* {{Code|pass}}: by default, the option is {{Code|false}}. If an error is raised, the line/column number and the optional file uri will refer to the location of the function call. If the option is 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}}.
|-valign="top"
| '''Errors'''
|Any error that may occur while parsing the query.
|-valign="top"
| '''Examples'''
|
* {{Code|xquery:parse("1 + 3")}} returns:
<syntaxhighlight pre lang="xml">
<MainModule updating="false">
<QueryPlan compiled="false">
</QueryPlan>
</MainModule>
</syntaxhighlightpre>
|}
==xquery:fork-join==
 
{{Announce|Updated with Version 11:}} Options added.
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>xquery:fork-join|( $functions as function(*)*|, $options as map(*)? := map { }) as item()*}}</pre>|-valign="top"
|'''Summary'''
|This function executes the supplied (non-updating) {{Code|$functions }} in parallel. The following {{Code|$options}} are available:* {{Code|parallel}}: Maximum number of parallel threads. If the value is smaller than {{Code|1}}, or if the option is omitted, the number of available processors is used.* {{Code|result}}: Suppress or return the function results (default: {{Code|true}}).* {{Code|errors}}: Ignore or raise errors (default: {{Code|true}}).|-valign="top"
| '''Examples'''
|
* The following function sleeps in parallel; it will be finished in 1 second if your system has Request 100 URLs, use at least 2 cores:<syntaxhighlight lang="xquery">let $f := function() { prof:sleep(1000) }return xquery:fork-join(($f, $f))</syntaxhighlight>* In the following query, up to four URLs will be requested in most 8 parallelthreads:<syntaxhighlight pre lang="'xquery"'>
xquery:fork-join(
for $segment in 1 to 4100
let $url := 'http://url.com/path/' || $segment
return function() { http:send-request((), $url) }, map { 'parallel': 8 }
)
</syntaxhighlightpre>* Parallel sleep function calls. The function is expected to finish in 1 second if the system has at least 2 cores:<pre lang='xquery'>let $f := function() { prof:sleep(1000) }return xquery:fork-join(($f, $f))</pre>|-valign="top"
|'''Errors'''
|{{Error|error|#Errors}} an unexpected error occurred.
! width="110"|Code
|Description
|-valign="top"
|{{Code|permission}}
|Insufficient permissions for evaluating the query.
|-valign="top"
|{{Code|update}}
|[[XQuery Update#Updating Expressions|updating expression]] found or expected.
|-valign="top"
|{{Code|timeout}}
|Query execution exceeded timeout.
|-valign="top"
|{{Code|memory}}
|Query execution exceeded memory limit.
|-valign="top"
|{{Code|nested}}
|Nested query evaluation is not allowed.
|-valign="top"
|{{Code|error}}
|An unexpected error occurred.
=Changelog=
 
;Version 11
 
* Updated: {{Function||xquery:fork-join}}: Options added.
* Updated: The Clark notation was replaced with the [[XQuery 3.0#Expanded QNames|Expanded QNames]] notation.
;Version 10
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu