[xquery-talk] Error in unexecuted(?) code
Ronald Bourret
rpbourret at rpbourret.com
Sun Mar 11 21:21:57 PST 2007
Hello,
I have a data structure where a <timeinfo> element can have either a
<sngdate> (single date) child or a <rngdate> (range of dates) child. The
following query tests for which child is present and constructs an
xs:date appropriately.
for $timeinfo in
<timeinfo><rngdates><begdate>19550101</begdate><enddate>19550101</enddate></rngdates></timeinfo>
return
<date>
{
fn:min(if ($timeinfo/sngdate)
then let $fgdcDate:=$timeinfo/sngdate/caldate
return xs:date(
fn:concat(
fn:substring($fgdcDate, 1, 4),
"-",
fn:substring($fgdcDate, 5, 2),
"-",
fn:substring($fgdcDate, 7, 2)))
else let $fgdcDate:=$timeinfo/rngdates/begdate
return xs:date(
fn:concat(
fn:substring($fgdcDate, 1, 4),
"-",
fn:substring($fgdcDate, 5, 2),
"-",
fn:substring($fgdcDate, 7, 2)))
)
}
</date>
This executes correctly in Saxon 8, but fails in DB2 v9 with the
following error:
The value "--" cannot be constructed as, or cast (using
an implicit or explicit cast) to the data type "xs:date"
The error goes away if I remove the xs:date constructor from the "then"
clause. For example:
for $timeinfo in
<timeinfo><rngdates><begdate>19550101</begdate><enddate>19550101</enddate></rngdates></timeinfo>
return
<date>
{
fn:min(if ($timeinfo/sngdate)
then $timeinfo/sngdate/caldate
else let $fgdcDate:=$timeinfo/rngdates/begdate
return xs:date(
fn:concat(
fn:substring($fgdcDate, 1, 4),
"-",
fn:substring($fgdcDate, 5, 2),
"-",
fn:substring($fgdcDate, 7, 2)))
)
}
</date>
This makes me believe that the then clause is being executed (even
though sngdate is not present) with an empty sequence. An empty sequence
would cause concat to return "--" and xs:date() to return the
aforementioned error.
Is a DB2 bug (my guess) or am I missing something subtle? For example,
perhaps XQuery processors can execute any code they like and only take
the results that apply? This would contradict the statement in 3.10 of
the XQuery spec that:
"Similarly, if the effective value of the test expression is false, the
conditional expression ignores any dynamic errors encountered in the
then-expression, and the then-expression need not be evaluated."
-- Ron
More information about the talk
mailing list