ZF-12459: Sqlsrv driver limit/offset handling assumes the machine can add numbers above int_max
Description
For some reason Zend_Db_Select tries to be clever and set the limit to PHP_INT_MAX if only offset is supplied. This, for one, means you can't offset into a table with more than 2^31 rows, but also causes strange differences compared to using the freetds driver on linux. This is because it actually tries to add the $offset onto the $count, even though $count is already at int max!
Basically, in the SQLsrv adapter, line 633 or so, this:
$end = $offset + $count;
$sql = "WITH outer_tbl AS ($sql) SELECT * FROM outer_tbl WHERE \"ZEND_DB_ROWNUM\" BETWEEN $start AND $end";
Needs to be changed to:
if ($count == PHP_INT_MAX) {
$sql = "WITH outer_tbl AS ($sql) SELECT * FROM outer_tbl WHERE \"ZEND_DB_ROWNUM\" >= $start";
}
else {
$end = $offset + $count;
$sql = "WITH outer_tbl AS ($sql) SELECT * FROM outer_tbl WHERE \"ZEND_DB_ROWNUM\" BETWEEN $start AND $end";
}
Comments
Posted by Chris Kings-Lynne (chriskl) on 2012-10-31T09:33:19.000+0000
Seems similar
Posted by Rob Allen (rob) on 2012-11-06T20:03:45.000+0000
Does this solve itself with a 64-bit version of PHP?
Posted by Rob Allen (rob) on 2012-11-06T20:07:18.000+0000
Resolved on trunk (25076) and release-1.12 (25077)