[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

Error in unexecuted(?) code

Ronald Bourret rpbourret at rpbourret.com
Sun Mar 11 21:21:57 PST 2007


  Error in unexecuted(?) code
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!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.