Home » Database » DB » Bug #3663
getOne/getRow optimization causes query error
Details
| Submitted | 2005-03-01 19:40 UTC |
|---|---|
| From | mark at everytruckjob dot com |
| Assigned | danielc |
| Status | Closed |
| Package | DB |
| PHP Version | Irrelevant |
| OS | Irrelevant |
| Roadmaps | (Not assigned) |
Comments
[2005-03-01 19:40 UTC] mark at everytruckjob dot com
Description:
------------
The optimization changes made to the getOne and getRow functions in revision 1.112 of common.php cause queries which already specify a "LIMIT 1" to fail because the modifyLimitQuery function does not check for an existing LIMIT/OFFSET clause in the query before adding one.
Adding the limit is a good optimization, but I'm guessing it will affect others who added their own "LIMIT 1" before this optimization was automatic. Perhaps the solution would be for the modifyLimitQuery functions to check for the presence of LIMIT and OFFSET before changing the query or to use some regex to replace the existing values with 1 and 0 respectively.
Reproduce code:
---------------
$result = $db->getOne("SELECT col FROM table LIMIT 1");
if (DB::isError($result)) {
$result->getDebugInfo();
} else {
echo $result;
}
Expected result:
----------------
The first column returned from table.
Actual result:
--------------
Postgres Error:
SELECT col FROM table LIMIT 1 LIMIT 1 OFFSET 0 [nativecode=ERROR: syntax error at or near "LIMIT" at character xx]