I am trying to find a way to use MySQL's FOUND_ROWS() feature with Rose:

http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_found-rows

I am most interested in getting this to work with my Manager classes so 
that I do not have to do a second query to find the total count using 
the 'get_objects_count' method.

I could not find a way to do this through the docs. The 'select' 
argument in Rose::DB::Object::Manager's get_objects method looked 
promising, but the query breaks when more than one table is involved.

I got it to work using the get_objects_sql method and injecting 
SQL_CALC_FOUND_ROWS into the query, but that's far from ideal.

Is there a way to currently do this using the get_objects and 
get_objects_iterator methods?

If not, could an option be added to the QueryBuilder so that a string 
can be added immediately after the SELECT keyword? Maybe something like:

  my $iterator = $manager_class->$iterator_method
  (
    query => $query,
    select_suffix => 'SQL_CALC_FOUND_ROWS',
    db => $self->db,
  );

or even:

  my $iterator = $manager_class->$iterator_method
  (
    query => $query,
    sql_calc_found_rows => 1,
    db => $db,
   );

Although I believe the latter would be MySQL specific.

Even better would be to have a way to automatically add 
SQL_CALC_FOUND_ROWS to every query used by a Manager.

The count could then be retrieved using:

  my ($count) = $db->dbh->selectrow_array('SELECT FOUND_ROWS()');

Perhaps a method could be added to the iterator (or some other 
appropriate place) to retrieve this value.

Thanks,
Ken
 


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to