Changes

Jump to navigation Jump to search
32 bytes added ,  16:22, 7 August 2022
<syntaxhighlight lang="xquery">
(: if/then/else :)if ($test ok) then 1 else 0,(: ternary if :)$ok ?? 'ok' 1 !! 'fails'0
</syntaxhighlight>
<syntaxhighlight lang="xquery">
let $number := 123return ( (: if/then/else :) if (exists($numberargument)) then $number argument else 0, (: elvis operator :) $number argument ?: 0)-1
</syntaxhighlight>
<syntaxhighlight lang="xquery">
if ($a) then if($b) then '$a and $b is true' else 'only $b a is true'
</syntaxhighlight>
<syntaxhighlight lang="xquery">
if ($a) then (
if($b) then '$a and $b is true' else 'only $b a is true'
)
</syntaxhighlight>
<syntaxhighlight lang="xquery">
declare option db:chop catalog 'falseetc/w3-catalog.xml';
doc('doc.xml')
</syntaxhighlight>
[[Options|Local database options]] can also be assigned via pragmas:
* [[Indexes|Index access rewritings ]] can be enforced. This is helpful if the name of a database is not static (see [[Indexes#Enforce Rewritings|Enforce Rewritings]] for more details):
<syntaxhighlight lang="xquery">
(# db:enforceindex #) {
for $db in ('persons1', 'persons2', 'persons3')
return db:openget($db)//name[text() = 'John']
}
</syntaxhighlight>
'wrapped-db-nodes.xml',
(# db:copynode false #) {
<xml>{ db:openget('huge') }</xml>
}
)
'''Example:'''
<syntaxhighlight lang="xquery">
declare %basex:lazy variable $january := doc('does-not-exist.xml');
if(month-from-date(current-date()) = 1) then $january else ()
</syntaxhighlight>
The annotation ensures that an error will is only be raised if the condition yields true. Without the annotation, the error will is always be raised, because if the referenced document is not found.
==XQuery Locks==
=Non-Determinism=
In [httphttps://www.w3.org/TR/xpath-functions-31/#dt-deterministic XQuery], ''deterministic'' functions are “guaranteed to produce ·identical· results from repeated calls within a single ·execution scope· if the explicit and implicit arguments are identical”. In BaseX, many extension functions are non-deterministic or side-effecting. If an expression is internally flagged as non-deterministic, various optimizations that might change their execution order will not be applied.
<syntaxhighlight lang="xquery">
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu