3 Replies Latest reply on Mar 1, 2012 5:02 PM by pfung-Oracle

    fn:ceiling() on xquery

      Hi All,

      on xquery,
      It seems i am getting wrong output from fn:ceiling() on my custom xquery

      Here is code what I am using to find out how many page exists

      let $recordCount := xs:decimal(string(zero-or-one($OutputXML/mdata:RecordsResult/@TotalRecordCount)))
      let $recordperpage := xs:decimal(string(zero-or-one($OutputXML/mdata:RecordsResult/@RecordsPerPage)))
      return fn:ceiling(xs:decimal($recordCount div $recordperpage))

      it seems it works when recordcount = 3,4,20,23,46,50...... and recordperpage = 30

      but when recordcount = 1 or 2 and recordperpage = 30,
      it returns -0.8446744073709551616
      it should be 1.

      just wondering if it's kind of bug and so i need to do it on different way, or there is any better way to do it, or if RecordsResult contains TotalPageCount(?).

        • 1. Re: fn:ceiling() on xquery
          I can reproduce this issue and have filed this against the Xquery 1.0 implementation in MDEX6 (Bug ref# IFCORE-1581). Given that you are really interested in the # of pages (which will not be a number < 1), you could potentially code around this like the following given that the ceiling function works fine for cases where the argument is > 1:

          let $ceilingValue :=
          if($recordCount <= $recordperpage) then 1
          else fn:ceiling(xs:decimal($recordCount div $recordperpage))

          You probably also want to add another condition to handle the case where $recordCount = 0 if you are routing them to a different page from your standard record list page, etc..
          • 2. Re: fn:ceiling() on xquery
            Hi Pi,

            Thanks for the quick reply and filing the bug.

            so, it seems there is no TotalPageCount(?).

            What i concern is also if it's only happened when recordCount < recordPerPage.
            I don't have any thing yet but still not feel free from worry.

            before you replied, i was thinking to use if(fn:ceiling(xs:decimal($recordCount div $recordperpage))<0) then 1
            somehow I feel there might be some values causing same issue when even recordCount > recordPerPage

            for now, I implement what you suggested.

            if ($recordCount<$recordperpage) then 1
            else fn:ceiling(xs:decimal($recordCount div $recordperpage))
            • 3. Re: fn:ceiling() on xquery
              Hi Julia

              The mdex6 service currently does not provide a total page count attribute: Web Services and XQuery Developer's Guide > About the MDEX API through XQuery > MDEX API through XQuery data types > RecordsResult data type. I do see this as a fairly common use case, so I have filed a feature request (Reference #IFCORE-1582) for you. Thanks.