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

Bug #17355 setLimit in conjunction with SELECT DISTINCT builds invalid SQL
Submitted: 2010-04-28 19:34 UTC
From: mspecht Assigned:
Status: Open Package: MDB2_Driver_mssql (version 1.2.1)
PHP Version: 5.2.10 OS: Linux (Debian Lenny)
Roadmaps: (Not assigned)    
Subscription  


 [2010-04-28 19:34 UTC] mspecht (Martin Specht)
Description: ------------ When using setLimit() and there SQL query starts with 'SELECT DISTINCT column FROM ...' the Limiter TOP is inserted between SELECT and DISTINCT, which results in an invalid query. There is similar closed bug (#8206) with limitQuery, but with queryCol it still seems to exist. Test script: --------------- $str_sql = 'SELECT DISTINCT event_incident.id FROM event_incident LEFT JOIN event_incidentbuilding ON (event_incidentbuilding.id_incident = event_incident.id)'; $mdb2->setLimit(200, 0); $msc_result = $db->queryCol($str_sql); if (PEAR::isError($msc_result)) { die($msc_result->getDebugInfo()); } var_dump($msc_result); Expected result: ---------------- It should return an array of ids (e.g. 1,2, ....) with a maximum length of 200 Actual result: -------------- getDebugInfo: _doQuery: [Error message: Could not execute statement] [Last executed query: SELECT TOP 200 DISTINCT event_incident.id FROM event_incident LEFT JOIN event_incidentbuilding ON (event_incidentbuilding.id_incident = event_incident.id)] [Native code: 156] [Native message: Incorrect syntax near the keyword 'DISTINCT'.]

Comments