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

Bug #18855 Incorrect check for the last "ORDER BY" clause
Submitted: 2011-09-21 04:14 UTC
From: kouber Assigned: doconnor
Status: Closed Package: Structures_DataGrid_DataSource_PDO (version 0.1.1dev1)
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  


 [2011-09-21 04:14 UTC] kouber (Kouber Saparev)
Description: ------------ Using PostgreSQL window functions (available since PostgreSQL 8.4) breaks the general ORDER BY check, since there's an internal "window" ORDER BY clause which comes even before the FROM clause of the query. So, the query doesn't have an ORDER BY at the end, but such is detected and it is omitted when composing the final query sent to the server, hence the entire query breaks. Test script: --------------- $query = "SELECT ROW_NUMBER() OVER (ORDER BY id) AS row_num, id FROM xxx"; $this->bind($query, array('dbc' => Database::getInstance())); Expected result: ---------------- Normal execution of the query, with a proper ORDER BY added at the end with a column specified by setDefaultSort(). Actual result: -------------- SQL error, since only a comma is added, instead of an entire ORDER BY. A work-around is to add "ORDER BY TRUE" every time a window function is used and no other ORDER BY is present.

Comments

 [2011-09-21 04:17 UTC] kouber (Kouber Saparev)
 [2011-09-23 04:52 UTC] doconnor (Daniel O'Connor)
Thanks for the patch Kouber
 [2011-12-27 11:30 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.