Difference between revisions of "XQuery 3.0"
Jump to navigation
Jump to search
Line 10: | Line 10: | ||
The [http://www.w3.org/TR/xquery-30/#id-try-catch try/catch] construct can be used to handle errors at runtime: | The [http://www.w3.org/TR/xquery-30/#id-try-catch try/catch] construct can be used to handle errors at runtime: | ||
− | + | ||
'''Example:''' | '''Example:''' | ||
<pre class="brush:xquery"> try { | <pre class="brush:xquery"> try { | ||
Line 17: | Line 17: | ||
concat('Error [', $code, ']: ', $desc) | concat('Error [', $code, ']: ', $desc) | ||
}</pre> | }</pre> | ||
+ | '''Result:''' <code>Error [XPTY0004]: '+' operator: number expected, string found.</code> | ||
+ | |||
+ | ==Switch== | ||
+ | |||
+ | The [http://www.w3.org/TR/xquery-30/#id-switch switch] statement is available in many other programming languages. It chooses one of several expressions to evaluate based on its input value. | ||
+ | |||
+ | '''Example:''' | ||
+ | <pre class="brush:xquery"> | ||
+ | for $fruit in ("Apple", "Pear", "Peach") | ||
+ | return switch ($fruit) | ||
+ | case "Apple" return "Red" | ||
+ | case "Pear" return "Green" | ||
+ | case "Peach" return "Pink" | ||
+ | default return "Unknown" | ||
+ | </pre> | ||
'''Result:''' <code>Error [XPTY0004]: '+' operator: number expected, string found.</code> | '''Result:''' <code>Error [XPTY0004]: '+' operator: number expected, string found.</code> | ||
[[Category:XQuery]] | [[Category:XQuery]] | ||
[[Category:Finish]] | [[Category:Finish]] |
Revision as of 15:01, 12 January 2011
This article summarizes the most important features of the upcoming Version 3.0 of the XQuery language that have already been implemented in BaseX.
Group By
FLWOR expressions have been extended by the group by clause, which is well-established among relational database systems. Group by clauses can be used to group query results based on its values.
Michi? (Example, Details)...
Try/Catch
The try/catch construct can be used to handle errors at runtime:
Example:
try { 1 + '2' } catch *($code, $desc) { concat('Error [', $code, ']: ', $desc) }
Result: Error [XPTY0004]: '+' operator: number expected, string found.
Switch
The switch statement is available in many other programming languages. It chooses one of several expressions to evaluate based on its input value.
Example:
for $fruit in ("Apple", "Pear", "Peach") return switch ($fruit) case "Apple" return "Red" case "Pear" return "Green" case "Peach" return "Pink" default return "Unknown"
Result: Error [XPTY0004]: '+' operator: number expected, string found.