Changes

Jump to navigation Jump to search
230 bytes removed ,  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>
==XQuery Locks==
If [[Transactions#XQuery_Locks|XQuery Locks]] locks are defined declared in the query prolog of a modulevia the {{Code|basex:lock}} option, access to functions of this module locks will be controlled by the central transaction management. If the following XQuery code is called by two clients in parallel, the queries will be evaluated one after another: <syntaxhighlight lang="xquery">declare option basex:write-lock 'CONFIGLOCK';file:write('configSee [[Transaction Management#Options|Transaction Management]] for further details.xml', <config/>)</syntaxhighlight>
=Pragmas=
This pragma can be helpful when debugging your code.
In analogy with option declarations and function annotations, XQuery locks can also set via pragmas. See [[TransactionsTransaction Management#XQuery_LocksOptions|XQuery LocksTransaction Management]] can also set via pragmas:for details and examples.
<syntaxhighlight lang="xquery">
==Database Pragmas==
All [[Options|local Local database options]] can also be assigned via pragmas. Some examples:
* Enforce query to [[Indexes|Index access rewritings]] can be rewritten for index accessenforced. This can e. g. be is helpful if the name of a database is not static (see [[Indexes#Enforce Rewritings|Enforce Rewritings]] for more examplesdetails):
<syntaxhighlight lang="xquery">
(# db:enforceindex #) {
for $db in ('persons1', 'persons2', 'persons3')
return db:openget($db)//name[text() = 'John']
}
</syntaxhighlight>
* Temporarily disable node Node copying in node constructors can be disabled (see {{Option|COPYNODE}} for more details). The following query will be evaluated faster, and take consume much less memory, than without pragma, because as the database nodes will not be fully copiedduplicated, but only attached to the new {{Code|xml}} parent element:
<syntaxhighlight lang="xquery">
'wrapped-db-nodes.xml',
(# db:copynode false #) {
<xml>{ db:openget('huge') }</xml>
}
)
</syntaxhighlight>
* Specify an An XML catalog can be specified for URI rewritingrewritings. See the [[Catalog Resolver]] section for an example.
=Annotations=
'''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==
In analogy with option declarations and pragmas, locks can also set via annotations. See [[TransactionsTransaction Management#XQuery_LocksAnnotations|XQuery LocksTransaction Management]] can also set via annotations: <syntaxhighlight lang="xquery">declare %basex:write-lock('CONFIGLOCK') function local:write() { file:write('configfor details and examples.xml', <config/>)};</syntaxhighlight>
=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