ZF-1905: where condition
Description
i tried to execute this :
$table->update($data, array('id = ?' => 5));
and the query resulted was :
update table set ........ where (5)
i think the _updateExpr() function should be changed to :
protected function _whereExpr($where)
{
if (empty($where)) {
return $where;
}
if (!is_array($where)) {
$where = array($where);
}
foreach ($where as $key=>&$term) {
if ($term instanceof Zend_Db_Expr) {
$term = $term->__toString();
} else {
if (!is_numeric($key))
{
$term = $this->quoteInto($key,$term);
}
}
$term = '(' . $term . ')';
}
$where = implode(' AND ', $where);
return $where;
}
Comments
Posted by Thomas Weidner (thomas) on 2007-09-08T12:01:05.000+0000
Assigned to Bill
Posted by Wil Sinclair (wil) on 2008-03-21T17:05:30.000+0000
This issue should have been fixed for the 1.5 release.
Posted by Wil Sinclair (wil) on 2008-03-25T20:43:57.000+0000
Please categorize/fix as needed.
Posted by Wil Sinclair (wil) on 2008-04-18T13:11:52.000+0000
This doesn't appear to have been fixed in 1.5.0. Please update if this is not correct.
Posted by Piotr Kabacinski (kabot) on 2008-11-21T03:36:50.000+0000
I prepared patch file with functionality mentioned above and i added one more feature. In most cases where conditions are simple comparision with '=' sign. With attached patch you can prepare where parameter as below:
It works with update and insert method as well.
Posted by Piotr Kabacinski (kabot) on 2008-11-21T03:42:22.000+0000
Of course i meant delete and update method (no insert).
Posted by Wil Sinclair (wil) on 2008-12-04T12:53:16.000+0000
Reassigning as Ralph is the maintainer of Zend_Db
Posted by Ralph Schindler (ralph) on 2009-01-09T14:59:57.000+0000
Will evaluate within 2 weeks
Posted by Wil Sinclair (wil) on 2009-03-16T15:23:51.000+0000
I don't see a use case here where you can't build the where clause string using quote() or quoteInto(). It doesn't seem to be worth the additional complexity. Please reopen if I'm missing something- especially a use case that cannot be handled with this method.
,Wil
Posted by Wil Sinclair (wil) on 2009-03-16T15:34:08.000+0000
Actually, there are several issues for this and a case for matching the behavior of fetch() and fetchAll(). This will be fixed, but for bookkeeping purposes this issue will be closed as a duplicate.
Posted by Piotr Kabacinski (kabot) on 2009-03-16T16:45:44.000+0000
IMHO in this situation it's worth additional complexity beacouse of consistency. In insert method and half of update is used parametrized query but here we need to use quoteInto. Would be nice if i could could use what i have from db engine and not using something like addslashes() - more accurate but still.
Posted by Piotr Kabacinski (kabot) on 2009-03-16T16:46:04.000+0000
IMHO in this situation it's worth additional complexity beacouse of consistency. In insert method and half of update is used parametrized query but here we need to use quoteInto. Would be nice if i could could use what i have from db engine and not using something like addslashes() - more accurate but still.