|
[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message] Error in unexecuted(?) codeMichael Kay mike at saxonica.comMon Mar 12 09:45:30 PST 2007
XQuery processors are in fact given a surprising amount of latitude to rewrite expressions in ways that can cause errors to be reported that would not be reported if they were evaluated as written. However, there's an explicit guarantee for "if" and "typeswitch": "Conditional and typeswitch expressions raise only dynamic errors that occur in the branch that is actually selected." (Section 2.3.4). So I think DB2 is wrong here. Michael Kay http://www.saxonica.com/ > -----Original Message----- > From: http://x-query.com/mailman/listinfo/talk > [mailto:http://x-query.com/mailman/listinfo/talk] On Behalf Of Ronald Bourret > Sent: 12 March 2007 05:22 > To: xquery-talk > Subject: 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>195501 > 01</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>195501 > 01</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 > > _______________________________________________ > http://x-query.com/mailman/listinfo/talk > http://x-query.com/mailman/listinfo/talk
|
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
|






