Issues

ZF-7223: In Zend_Db_Select::limit(), an empty first parameter won't be converted to max integer in 32-bits architecture.

Issue Type: Bug Created: 2009-07-08T03:17:05.000+0000 Last Updated: 2012-10-31T09:33:19.000+0000 Status: Resolved Fix version(s): - 1.9.6 (24/Nov/09)

Reporter: Nicolas Lenepveu (arkhamtaro) Assignee: Mickael Perraud (mikaelkael) Tags: - Zend_Db_Select

Related issues: - ZF-12459

Attachments:

Description

In Zend_Db_Select class, the _renderLimitoffset function tries to get the max integer that PHP can support when no count parameter is given but in 32-bits architecture, intval(9223372036854775807) returns 0 instead of reducing to the max integer.

$select->from('Table')->limit(0, 5);

Will give you

SELECT Table.* FROM Table

Instead of

SELECT Table.* FROM Table LIMIT 2147483647 OFFSET 5

Using intval('9223372036854775807') - parameter as a string - will return the max value in both 32-bits and 64-bits architecture but more simply PHP_INT_MAX can be used.

Comments

Posted by Mickael Perraud (mikaelkael) on 2009-11-21T01:36:17.000+0000

Fixed with r19154

Posted by Michael Beaumont (catacaustic) on 2009-12-03T03:27:30.000+0000

This goes against the documentation. Please see http://framework.zend.com/manual/en/… for expected behaviour.

According to the documentation, the function

$select->from('table')->limit(0,5);

Should produce:

SELECT Table.* FROM Table LIMIT 0, 5

Taking the same syntax the the original reporter has for the SQL statement produced, it should be:

SELECT Table.* FROM Table LIMIT 5 OFFEST 0

The current fix gives produces the opposite actions compared to what is provided in the documentation.

Posted by Nicolas Lenepveu (arkhamtaro) on 2009-12-03T04:11:43.000+0000

Fisrt, the aim of the fix is to get the max integer PHP can support.

Second, the documentation is wrong according to the code :

->limit(10, 20); // ->limit($row_count, $offset)

won't get

LIMIT 10, 20 // [offset,] row_count or LIMIT 20 OFFSET 10

but

LIMIT 20, 10 or LIMIT 10 OFFSET 20

Third, in the current logic of the using of limit clause, it is impossible to have a empty row count value.

Posted by Mickael Perraud (mikaelkael) on 2009-12-03T05:01:49.000+0000

@Michael Beaumont: the first parameter is the count and the second is the offset If the count equals 0, we assume that you want all values.

See http://framework.zend.com/code/browse/…, for real modifications to the code or http://framework.zend.com/code/browse/… for the associated test:

<pre class="highlight">
$select->from('table1')->limit(0, 5);

produces

<pre class="highlight">
'SELECT "table1".* FROM "table1" LIMIT ' . PHP_INT_MAX . ' OFFSET 5'

Posted by Mickael Perraud (mikaelkael) on 2009-12-17T13:37:33.000+0000

@Michael Beaumont: It appears that it's a documentation issue (see ZF-6237)

Have you found an issue?

See the Overview section for more details.

Copyright

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

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

Contacts