Issue Type: Bug Created: 2010-05-03T17:07:14.000+0000 Last Updated: 2012-11-14T09:55:31.000+0000 Status: Open Fix version(s): Reporter: Joseph Crawford (jcrawford) Assignee: Ralph Schindler (ralph) Tags: - Zend_Db_Select
Related issues: - ZF-7666
If you do something like the below:
require_once 'Zend/Db/Select.php'; require_once 'Zend/Db/Adapter/Mysqli.php'; $select = new Zend_Db_Select(new Zend_Db_Adapter_Mysqli(array('dbname' => 'foo','password' =>'foo','username' =>'foo'))); $select->limit(0, 10); echo $select;
it returns the following query:
LIMIT 2147483647 OFFSET 10
notice how the 0 was changed to PHP_INT_MAX value? Someone in the IRC channel confirmed this is a bug because the validation in Zend_Db_Select calls !empty(0)
Posted by Paul Court (gargoyle) on 2010-05-03T17:33:04.000+0000
Obviously, passing 0 as the limit does not make much sense, but the Zend_Db_Select::limit() function is explicitly setting the value to PHP_INT_MAX before it calls the adapter specific version of the limit() function.
So the exceptions that would otherwise be thrown by each specific adapter, do not get seen!
There is also possibly another logic problem in the limit() function. If you were to remove the setting of the limit count to PHP_INT_MAX, then the adaptor limit() function would not get called at all!
Even more bizarre, mysql will actually take limit 0 and offset 10 and give you exactly what you asked for... nothing - should Zend_Db be treating this as an error if mysql doesn't?
I am thinking that Zend_Db_Select::limit() should simply hand the values over to the adaptors and let them decide if it is valid or not.
Posted by Michal Novotny (clime) on 2012-11-14T09:55:31.000+0000
I have just hit this issue. The behavior with zero explicitly set is totally unexpected. Ye, If i put there zero, give me zero rows and NOT all. I just wanted to test part of a script and cause of this i run it sharp.
Have you found an issue?
See the Overview section for more details.