Zend Framework

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

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: N/A N/A
  • Resolution: Fixed
  • Affects Version/s: 1.8.4
  • Fix Version/s: 1.9.6
  • Component/s: Zend_Db_Select
  • Labels:
    None

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.

Activity

Hide
Mickael Perraud added a comment -

Fixed with r19154

Show
Mickael Perraud added a comment - Fixed with r19154
Hide
Michael Beaumont added a comment -

This goes against the documentation. Please see http://framework.zend.com/manual/en/zend.db.select.html#zend.db.select.building.limit 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.

Show
Michael Beaumont added a comment - This goes against the documentation. Please see http://framework.zend.com/manual/en/zend.db.select.html#zend.db.select.building.limit 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.
Hide
Nicolas Lenepveu added a comment -

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.

Show
Nicolas Lenepveu added a comment - 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.
Hide
Mickael Perraud added a comment -

@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/Standard_Library/standard/trunk/library/Zend/Db/Select.php?r1=18750&r2=19154, for real modifications to the code or http://framework.zend.com/code/browse/Standard_Library/standard/trunk/tests/Zend/Db/Select/StaticTest.php?r1=19153&r2=19154 for the associated test:

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

produces

'SELECT "table1".* FROM "table1" LIMIT ' . PHP_INT_MAX . ' OFFSET 5'
Show
Mickael Perraud added a comment - @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/Standard_Library/standard/trunk/library/Zend/Db/Select.php?r1=18750&r2=19154, for real modifications to the code or http://framework.zend.com/code/browse/Standard_Library/standard/trunk/tests/Zend/Db/Select/StaticTest.php?r1=19153&r2=19154 for the associated test:
$select->from('table1')->limit(0, 5);
produces
'SELECT "table1".* FROM "table1" LIMIT ' . PHP_INT_MAX . ' OFFSET 5'
Hide
Mickael Perraud added a comment -

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

Show
Mickael Perraud added a comment - @Michael Beaumont: It appears that it's a documentation issue (see ZF-6237)

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: