Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    DSResponse.getTotalRows() to yield total rows without limit (mysql). How?

    Hello,

    Using: (v8.3p_2013-01-09/PowerEdition Deployment 2013-01-09)

    The following code is all server-side (I am building a webservice).

    I have a customSQL (mysql) query, like so:
    Code:
     <customSQL> <![CDATA[
    SELECT SQL_CALC_FOUND_ROWS p.Product_id, ...
      FROM Product p
      WHERE  
      # ... some complex where clause
      LIMIT $dsRequest.getStartRow(), $dsRequest.getEndRow()
     </customSQL>
    (Note the use of SQL_CALC_FOUND_ROWS.)

    However, if I do a call like:
    Code:
    DSResponse resp = req.execute();
    Long total = resp.getTotalRows(); //yields the total of rows as per the limit set.
    This yields the number specified in limit. However, I would like it to yield the total amount as if there was no limit.
    How can I achieve this?

    I tried using creating another DSRequest with customSQL that did something along the lines of SELECT ROWS_FOUND(), but this always yielded 1, instead of the real number.

    Could you give some advice as in how to achieve the thing I want?

    #2
    If you look at the SQL that SQLDataSource generates in the server log, you can see that we do a separate query in order to determine the row count.

    Comment


      #3
      Okay thanks. But does it also do this for customSQL queries?

      Or is it then required to use $defaultSelectClause in order to replace that with count(*) or something?

      Because that could be something i'm missing right now.

      Comment


        #4
        You can use the DataSource/operationBinding.sqlPaging setting to control whether we attempt paging and/or a row count for a custom SQL query.

        Note that of course if you configure the framework not to attempt a row count, you can do your own row count as just another DSRequest targeting an operationBinding with <customSQL> that contains just a row count query.

        Comment


          #5
          I fixed it, by switching from customSQL to a normal <selectClause> et al. approach, which was better anyways.

          Then, using just a normal $defaultSelectClause, with outputs="..." limiting the number of fields selected, I could just use DSResponse.getTotalRows() method.

          Comment

          Working...
          X