ZF-12459: Sqlsrv driver limit/offset handling assumes the machine can add numbers above int_max

Issue Type: Bug Created: 2012-10-31T09:29:03.000+0000 Last Updated: 2012-11-09T10:03:13.000+0000 Status: Resolved Fix version(s): - 1.12.1 (18/Dec/12)

Reporter: Chris Kings-Lynne (chriskl) Assignee: Ralph Schindler (ralph) Tags: - Zend_Db_Select

Related issues: - ZF-7223



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:

<pre class="literal">
            $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:

<pre class="literal">
            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";


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)

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.