Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.2.2dev1

Bug #10778 Wrong number of results when paging
Submitted: 2007-04-19 08:17 UTC Modified: 2007-05-07 14:21 UTC
From: banquette Assigned: olivierg
Status: Closed Package: Structures_DataGrid_DataSource_DataObject
PHP Version: 4.4.4 OS: windows/linux
Roadmaps: (Not assigned)    
Subscription  


 [2007-04-19 08:17 UTC] banquette (Alex Desktop)
Description: ------------ //PEAR require_once "PEAR.php"; define("DB_DATAOBJECT_NO_OVERLOAD",true); /* This is needed for some buggy versions of PHP4 */ require_once "DB/DataObject.php"; require_once 'HTML/Table.php'; require_once 'Structures/DataGrid.php'; require_once 'HTML/QuickForm.php'; /* Database and DataObject setup */ $dataobjectOptions = &PEAR::getStaticProperty("DB_DataObject","options"); $dataobjectOptions["database"] = "mysql://root:@localhost/db"; $dataobjectOptions["proxy"] = "full"; //one person = multi cars/toys. One toy/car = only one person $person = new person; $person->selectAdd("count(DISTINCT cars.person_id) AS n_cars"); $person->selectAdd("count(DISTINCT toys.person_id) AS n_toys"); $person->joinAdd(array('id_person','cars'.':'.'person_id'),'left'); $person->joinAdd(array('id_person','toys'.':'.'person_id'),'left'); $adh->groupBy("person.name"); $datagrid =& new Structures_DataGrid(20); $datagrid->bind($person); print_r($datagrid); //Everything is correct except the paging : for example there are 3 rows for the result and datagrid show [_rowNum] => 51 //This leads to an abnormal number of pages (empty) and links (1 2 3 etc ...) // There is no problem when binding with a "hard" query : "SELECT * FROM etc ..."

Comments

 [2007-04-19 19:16 UTC] alan_k (Alan Knowles)
This is a Structures_DataGrid issue - moving to there.
 [2007-04-20 00:49 UTC] wiesemann (Mark Wiesemann)
This is actually an issue with the DB_DataObject DataSource driver of Structures_DataGrid. I guess we need something similar to the 'count_query' bind() option as in the MDB2 DataSource for such cases because queries with DISTINCT can't automatically be counted right (c.p. the documentation page for the MDB2 driver for more details).
 [2007-05-07 14:21 UTC] olivierg (Olivier Guilyardi)
The MDB2 driver actually detects when records are grouped. But I can't do that with DB_DataObject without playing with its private variables in a hackish way. So, I just added the "raw_count" option that tells the driver to fetch all records in order to count them. This is exactly like the MDB2 driver except for the automatic detection. Fixing this bug doesn't require a such thing as the "count_query" option of the MDB2 driver. The new "raw_count" option seems fairly sufficient to me. Alex, just set the "raw_count" option to true when bind()'ing your dataobject. This bug is fixed in CVS. Thanks for your report.