Details
Description
In the fetchRow() method in Zend_Db_Table_Abstract I find this:
if (!($where instanceof Zend_Db_Table_Select)) { /* snip */ } else { $select = $where->limit(1); }
So whenever you pass a Zend_Db_Table_Select object including a limit with an offset, say LIMIT 1 OFFSET 10, it overrules it with just LIMIT 1, even though in both cases the resulting rowset contains a maximum of 1 rows. This is unexpected and silently breaks the meaning of the select, resulting in a wrong row being returned.
Steps to reproduce:
$select = $teams->select()
->where('colour = ?', 'orange')
->order('result')
->limit(1,10);
echo (string) $teams;
// SELECT `teams`.* FROM `teams` WHERE (colour = 'orange') ORDER BY `result` ASC LIMIT 1 OFFSET 10
$teams->fetchRow($teams);
// SELECT `teams`.* FROM `teams` WHERE (colour = 'orange') ORDER BY `result` ASC LIMIT 1
Suggested fix:
$select = $where->limit(1, $where->getPart(Zend_Db_Select::LIMIT_OFFSET));
Attachments
Issue Links
| This issue is duplicated by: | ||||
| ZF-10598 | Zend Select odd behavior |
|
|
|
Sorry for the repeated edits