ZF-2142: Allow the where() method of Zend_Db_Select to accept multiple arguments for automatic quoting
Description
Currently the where method of Zend_Db_Select allows to call the where() method with a second parameter that gets quoted substituted into the first parameter and replaces the placeholder (question mark). Since the where() method can be called multiple times, multiple parameters can be quoted.
$select = $db->select()
->from("products")
->where("product_name = ?", $prod)
->where("price < ?", $minimumPrice)
->orWhere("price > ?", $maximumPrice);
Unfortunately this usage makes it more difficult when you need to evaluate Boolean expressions in a specific order. In certain cases it becomes necessary to use the non-quoted format in order to clarify the query because AND has higher precedence than OR. Quoting must be done separately.
$minPriceQuoted = $db->quote($minimumPrice);
$maxPriceQuoted = $db->quote($maximumPrice);
$select = $db->select()
->from("products")
->where("product_name = ?", $prod)
->where("price < $minPriceQuoted OR price > $maxPriceQuoted");
If the where() method accepted multiple parameters for quoting, the usage would be much less awkward:
$select = $db->select()
->from("products")
->where("product_name = ? AND (price < ? OR price > ?)", $prod, $minimumPrice, $maximumPrice);
Comments
Posted by Darby Felton (darby) on 2007-11-05T14:46:19.000+0000
Assigning to [~thomas].
Posted by Thomas Weidner (thomas) on 2007-11-17T07:07:35.000+0000
Integrated to trunk... Please check SVN8640 or later and give us feedback.
Posted by Thomas Weidner (thomas) on 2007-11-22T03:08:35.000+0000
Solution not accepted by community and main author. Reverted the changes.
Posted by Thomas Weidner (thomas) on 2007-11-22T03:35:46.000+0000
Unassigned as original additional where methodology was not accepted.
Posted by Thomas Weidner (thomas) on 2008-01-25T13:41:44.000+0000
Integrated with SVN7576. Cored with Release 1.5
Posted by Thomas Weidner (thomas) on 2008-03-12T13:01:17.000+0000
Erased from core for review of complete component
Posted by Ralph Schindler (ralph) on 2009-01-10T10:31:46.000+0000
Will evaluate within 2 weeks