>
> Hello,
>
> Handling priority of WHERE clause statements with the current API can be
> disgraceful.
> What if an easier method was to use the Reverse Polish Notation to handle
> it :
>
> // a > min and a < max
> ->where('a > ?', $min)
> ->where('a < ?', $max)
> ->and()
>
> // a = 42 or (a > min and a < max)
> ->where('a > ?', $min)
> ->where('a < ?', $max)
> ->and()
> ->where('a = ?', 42)
> ->or()
>
> // it can also be written :
> ->where('a = ?', 42)
> ->where('a > ?', $min)
> ->where('a < ?', $max)
> ->and()
> ->or()
>
> RPN is an "elegant" way of managing priority in general, and easy to
> implement with a stack.
>
> Marc Dassonneville
>
>
+1
very good idea, because this example isn't good:
// Build this query:
// SELECT product_id, product_name, price
// FROM "products"
// WHERE (price < 100.00 OR price > 500.00)
// AND (product_name = 'Apple')
$select = $db->select()
->from('products',
array('product_id', 'product_name', 'price'))
->where("price < $minimumPrice OR price > $maximumPrice")
->where('product_name = ?', $prod);
It's possible in this example write the ->where("price < $minimumPrice OR
price > $maximumPrice") OR statment not in the string but throught
->orWhere somehow ?
But +1 for Marc Dassonneville's suggestion
--
View this message in context: http://www.nabble.com/Zend_Db_Select%2C-WHERE-clause-API-tp22498322p22539254.html
Sent from the Zend DB mailing list archive at Nabble.com.
没有评论:
发表评论