Issues

ZF-2227: Allow where method to accept multiple placeholders

Issue Type: Improvement Created: 2007-11-22T15:03:11.000+0000 Last Updated: 2012-05-05T23:37:51.000+0000 Status: Closed Fix version(s): Reporter: Thomas Weidner (thomas) Assignee: Adam Lundrigan (adamlundrigan) Tags: - Zend_Db_Select

Related issues: - ZF-2142

Attachments:

Description

Allow where() to accept multiple placeholders.

This would allow users to build clauses which are not possible with the actual implementation.

<pre class="highlight">
->where("((price > ? or price <= ?) and name like ?) or price in (?)", 1, 5, 'user%', 20, 30, 40, 50);
// where ((price > 1 or price <= 5) and name like 'user%') or price in (20, 30, 40, 50)

Multiple placeholders are quite easy to implement. Just 3 rules which are relevant: * If the amount of placeholders and values are equal replace each placeholder with the value * If there are more placeholders than values some placeholders would stay within the query * If there are more values than placeholders the not filled values would be compressed with ", value"

Usecase:

<pre class="highlight">
->where("(price > ? and price < ?) or name like (?)", 2, 5, 'demo%');
// where (price > 2 and price < 5) or name like ('demo%')

Usecase:

<pre class="highlight">
->where("(price > ? and price < ?) or name like (?)", 2, 5);
// where (price > 2 and price < 5) or name like (?)

There are two possibilities... Eigther allow not filled placeholders, or throw an exception if placeholders are not filled.

Usecase:

<pre class="highlight">
->where("(price > ? and price < ?) or price IN (?)", 2, 5, 20, 30, 40, 50);
// where (price > 2 and price < 5) or price like (20, 30, 40, 50)

This way the old undocumented behaviour would also be accepted... Usecase:

<pre class="highlight">
->where("price IN (?)", 20, 30, 40, 50);
// where price like (20, 30, 40, 50)

Comments

Posted by Thomas Weidner (thomas) on 2008-01-25T13:47:31.000+0000

Integrated with SVN7576. Cored with Release 1.5

Posted by C Snover (snover) on 2008-03-10T19:11:49.000+0000

Documentation should be updated to reflect this change. Currently it says (Section 10.4 Example 10.54): {quote} This method accepts only one parameter. If you have an expression into which you need to substitute multiple variables, you must format the string manually, interpolating variables and performing quoting yourself. {quote}

Posted by Thomas Weidner (thomas) on 2008-03-11T03:25:41.000+0000

Documentation change necessary

Posted by Wil Sinclair (wil) on 2008-12-08T16:38:33.000+0000

Thomas, are you planning to update the docs? If not, please reassign to Ralph.

Posted by Thomas Weidner (thomas) on 2008-12-09T00:24:21.000+0000

Reassigned to component lead.

Posted by Adam Lundrigan (adamlundrigan) on 2012-05-05T23:37:34.000+0000

AFAIK, this was never actually implemented in trunk or has been reverted between 1.5 and now as the where method does not work as described by OP. Regardless, this is a duplicate of ZF-2142 so closing as duplicate.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts