|
[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message] Error in unexecuted(?) codeRonald Bourret rpbourret at rpbourret.comSun 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
|
Purchase Stylus Studio Online Today!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|






