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

Bug #16002 ORDER clause not stripped in count()
Submitted: 2009-03-09 23:27 UTC
From: bbaumer Assigned: doconnor
Status: Closed Package: Structures_DataGrid (version 0.9.0)
PHP Version: 5.2.9 OS: Windoze
Roadmaps: (Not assigned)    
Subscription  


 [2009-03-09 23:27 UTC] bbaumer (ben baumer)
Description: ------------ The ORDER clause of a SQL query is not stripped out when performing a SELECT COUNT(*) FROM ... operation in order to getRecordCount(). This causes the query to fail if the DataGrid is sorted by a column which is not actually a field present in the DB table. For example, this happens anytime you sort by a column that you have name using the AS construct. This is easily fixable by adding something like: $query = preg_replace('#ORDER\s+BY\s.+sc#', '', $query); to the function DataSource::count() right after you strip out the SELECT clauses. Also, the ORDER clause does not affect the number of rows returned, so there is no harm in doing this. Test script: --------------- $dg->bind("SELECT column as ColumnName FROM table ORDER BY ColumnName"); echo "You found ".$dg->getRecordCount()." records"; Expected result: ---------------- You found 47 records Actual result: -------------- You found MDB2 Error: no such field records

Comments

 [2011-12-26 23:06 UTC] doconnor (Daniel O'Connor)
-Status: Open +Status: Closed -Assigned To: +Assigned To: doconnor
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.