Changes

Jump to navigation Jump to search
1,710 bytes added ,  19:20, 20 August 2018
This article is part of the [[XQuery|XQuery Portal]]. It lists extensions and optimizations that are specific to the BaseX XQuery processor.
=SuffixesOption Declarations=
In BaseX, files with the suffixes {{Code|.xq}}, {{Code|.xqm}}, {{Code|.xqy}}, {{Code|.xql}}, {{Code|.xqu}} and {{Code|.xquery}} are treated as XQuery files. In XQuery, there are main and library modules:==Database Options==
* Main modules have [[Options|Local database options]] can be set in the prolog of an expression as query bodyXQuery main module. In the option declaration, options need to be bound to the [[Database Module]] namespace. Here is All values will be reset after the evaluation of a minimum examplequery:
<pre class="brush:xquery">
declare option db:chop 'Hello World!false';doc('doc.xml')
</pre>
* Library modules start with a module namespace declaration and have no query body: <pre class="brush:xquery">module namespace hello = 'http://basex.org/examples/hello';XQuery Locks==
declare function hello:world() { 'Hello World!'};</pre>If [[Transactions#XQuery_Locks|XQuery Locks]] are defined in the query prolog of a module, access to functions of this module locks will be controlled by the central transaction management.
We recommend {{Code|.xq}} as suffix for for main modules, and {{Code|.xqm}} for library modules. However, If the actual module type will dynamically be detected when a file following XQuery code is opened and parsed. =Option Declarations= [[Options|Local database options]] can be set called by two clients in the prolog of an XQuery main module. In the option declarationparallel, options need to be bound to the [[Database Module]] namespace. All values queries will be reset evaluated one after the evaluation of a queryanother:
<pre class="brush:xquery">
declare option dbbasex:chop write-lock 'falseCONFIGLOCK';docfile:write('docconfig.xml', <config/>)
</pre>
This pragma can be helpful when debugging your code.
 
{{Mark|Introduced with Version 9.1:}}
 
In analogy with option declarations and function annotations, [[Transactions#XQuery_Locks|XQuery Locks]] can also set via pragmas:
 
<pre class="brush:xquery">
(# basex:write-lock CONFIGLOCK #) {
file:write('config.xml', <config/>)
}
</pre>
==Database Pragmas==
All [[Options|local database options]] can be assigned via pragmas. Some examples:
* Enforce query to be rewritten for index access. This can e. g. be helpful if the name of a database is not static (see [[Indexes#Enforce Rewritings|Enforce Rewritings]] for more examples):
=Annotations=
==basex:inlineFunction Inlining==
{{Code|%basex:inline([limit])}} controls if functions will be inlined.
</pre>
==basex:lazyLazy Evaluation==
{{Code|%basex:lazy}} enforces the lazy evaluation of a global variable. An example:
'''Example:'''
<pre class="brush:xquery">
declare %basex:lazy variable $january := doc('does-not-exist');
if(month-from-date(current-date()) == 1) then $january else ()
</pre>
The annotation ensures that an error will only be thrown raised if the condition yields true. Without the annotation, the error will always be raised, because the referenced document is not found. ==XQuery Locks== {{Mark|Introduced with Version 9.1:}} In analogy with option declarations and pragmas, [[Transactions#XQuery_Locks|XQuery Locks]] can also set via annotations: <pre class="brush:xquery">declare %basex:write-lock('CONFIGLOCK') function local:write() { file:write('config.xml', <config/>)};</pre> =Functions= ==Regular Expressions== {{Mark|Introduced with Version 9.1:}} In analogy with Saxon, you can specify the flag {{Code|j}} to revert to Java’s default regex parser. For example, this allows you to use the word boundary option {{Code|\b}}, which has not been included in the XQuery grammar for regular expressions: '''Example:''' <pre class="brush:xquery">(: yields "!Hi! !there!" :)replace('Hi there', '\b', '!', 'j')</pre>
=Serialization=
For more information and some additional BaseX-specific parameters, see the article on [[Serialization]].
=Non-determinismDeterminism=
In [http://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.
Two non-deterministic functions will be bound to <code>$read</code>, and the result of the function call will be bound to <code>$ignored</code>. As the variable is not referenced in the subsequent code, the let clause would usually be discarded by the compiler. In the given query, however, execution will be enforced because of the BaseX-specific {{Code|non-deterministic}} keyword.
 
=Suffixes=
 
In BaseX, files with the suffixes {{Code|.xq}}, {{Code|.xqm}}, {{Code|.xqy}}, {{Code|.xql}}, {{Code|.xqu}} and {{Code|.xquery}} are treated as XQuery files. In XQuery, there are main and library modules:
 
* Main modules have an expression as query body. Here is a minimum example:
 
<pre class="brush:xquery">
'Hello World!'
</pre>
 
* Library modules start with a module namespace declaration and have no query body:
 
<pre class="brush:xquery">
module namespace hello = 'http://basex.org/examples/hello';
 
declare function hello:world() {
'Hello World!'
};
</pre>
 
We recommend {{Code|.xq}} as suffix for for main modules, and {{Code|.xqm}} for library modules. However, the actual module type will dynamically be detected when a file is opened and parsed.
=Miscellaneous=
Various other extensions are described in the articles on [[Full-Text#BaseX Features|XQuery Full Text]] and [[Updates|XQuery Update]].
 
=Changelog=
 
;Version 9.1:
 
* Added: XQuery Locks via pragmas and function annotations.
* Added: [[#Regular expressions|Regular Expressions]], {{Code|j}} flag for using Java’s default regex parser.
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu