Database Reference
In-Depth Information
XQuery Execution
There are some details you should be aware of regarding XQuery execution in eXist.
These include:
Transaction boundaries
eXist is transactional only during updates to the database; that is, a single update
either succeeds or fails atomically, not something in between, even if a crash
occurs in the middle of the operation.
eXist is not transactional during the execution of a full XQuery script (like some
other XQuery engines are). An XQuery script does not run in isolation, and
updates made by it or by concurrently running neighbor scripts will immediately
be visible. However, you can group updates into a single transaction; see the
exist:batch-transaction pragma in “eXist XQuery Pragmas” on page 123 .
Evaluation of expressions
eXist does not lazily evaluate expressions. For instance, a series of let expres‐
sions will all be evaluated, from top to bottom, even if some of the variables are
never used again.
The reasoning behind this has to do with side effects, which XQuery officially
doesn't have, but which (as we all know) in a real-world program are a necessity.
For instance, when you have a function that adds to a logfile, you want it exe‐
cuted even if you don't do anything with its return value.
As a consequence, be careful computing expensive values that might never be
used. It's better to either defer this until you really need them (e.g., nesting them
inside an if - then - else structure) or do something along the lines of:
let $expensive-value :=
if (...decide-whether-value-is-really-needed...)
then compute-value...
else ()
Serialization
Although it may seem as though eXist works directly with XML, as in “text with a lot
of angle brackets,” it does not. Internally, XML is represented as an efficient tree-
structured data type. Only on the way out, in the final step, are the angle brackets
added and the XML displayed once again as we know it. This process of changing the
internal representation into something suitable for the outside world is known as
serialization .
Controlling serialization is important: sometimes you may want XML, while at other
times you want HTML and/or JSON. You may perhaps also want to set the Internet
media type explicitly, or control indentation.
Search WWH ::




Custom Search