Changes

Jump to navigation Jump to search
619 bytes added ,  11:23, 1 March 2017
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 always have an expression as query body. Here is a body expressionminimum example:
<pre class="brush:xquery">
</pre>
* Library modules start with a module namespace declaration and have no query body expression:
<pre class="brush:xquery">
=Annotations=
The following implementation-defined annotations are available==basex:inline==
* {{Code|%basex:inline([limit])}} enforces controls if functions will be inlined. If XQuery functions are ''inlined'', the function call will be replaced by a FLWOR expression, in which the function variables are bound to let clauses, and in which the function body is returned. This optimization triggers further query rewritings that will speed up your query. An example: '''Query:''' <pre class="brush:xquery">declare function local:square($a) { $a * $a };for $i in 1 to 3return local:square($i)</pre> '''Query after function inlining :''' <pre class="brush:xquery">for $i in 1 to 3return let $a := $i return $a * $a</pre> '''Query after further optimizations:''' <pre class="brush:xquery">for $i in 1 to 3return $i * $i</pre> By default, XQuery functions will be ''inlined'' if the query body is not too large and does not exceed a fixed number of a functionexpressions, which can be adjusted via the {{Option|INLINELIMIT}} option.  The annotation can be used to overwrite this global limit: Function inlining limit can be enforced if no argument is specified as argument. Inlining can will be disabled by specifying if {{Code|0}}is specified.
'''Example:'''
<pre class="brush:xquery">
(: disable function inlining; the full stack trace will be shown... :)
declare %basex:inline(0) function local:e() { error() };
local:e()
</pre>
In the next example, function inlining was disabled globally by assigning {{Code|0}} to the [[Options#INLINELIMIT|INLINELIMIT]] option. However, annotation is enforced to a single function: '''Example:'''<pre class="brush:xquery">declare option db:inlinelimit '0';declare %=basex:inline function local:id($x) { $x };local:id(123)</pre> The query will be optimized to {{Code|123}}. lazy==
* {{Code|%basex:lazy}} enforces the lazy evaluation of a global variable. ExampleAn example:
'''Example:'''
</pre>
The annotation ensures that an error will only be thrown if the condition yields true. Without the annotation, the error will always be thrownraised, because the referenced document is not found.
=Serialization=
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu