Issues

ZF-1881: Support associative array argument in Zend_Db_Adapter::_whereExpr()

Issue Type: Sub-task Created: 2007-08-27T05:31:01.000+0000 Last Updated: 2009-03-16T15:43:36.000+0000 Status: Closed Fix version(s): - 1.7.7 (16/Mar/09)

Reporter: Adrian Hope-Bailie (adrianhopebailie) Assignee: Wil Sinclair (wil) Tags: - Zend_Db

Related issues: - ZF-1905

Attachments: - ZF-1881.patch

Description

(Unable to select Zend_Db_Adapter_Abstract in Component list)

Modify _whereExpr in Zend_Db_Adapter_Abstract so that $where parameter for Zend_Db_Table_Abstract update and delete is the same as $where parameter for fetchRow and fetchAll

The Zend_Db_Adapter_Abstract::_whereExpr function needs to be changed to:

<pre class="highlight">
    /**
     * Convert an array, string, or Zend_Db_Expr object
     * into a string to put in a WHERE clause.
     *
     * @param mixed $where
     * @return string
     */
    protected function _whereExpr($where)
    {
        if (empty($where)) {
            return $where;
        }
        if (!is_array($where)) {
            $where = array($where);
        }
        foreach ($where as $cond => &$term) {
            // is $cond an int? (i.e. Not a condition)
            if (is_int($cond)) {
                // $term is the full condition
                if ($term instanceof Zend_Db_Expr) {
                    $term = $term->__toString();
                }
            } else {
                // $cond is the condition with placeholder,
                // and $term is quoted into the condition
                $term = $this->quoteInto($cond, $term);
            }
            $term = '(' . $term . ')';
        }

        $where = implode(' AND ', $where);
        return $where;
    }

Comments

Posted by Bill Karwin (bkarwin) on 2007-08-27T12:45:33.000+0000

Reword summary. Copy old summary text into description.

Posted by Adrian Hope-Bailie (adrianhopebailie) on 2007-09-14T12:03:57.000+0000

Patch to modify Zend_Db_Adaptor_Abstract such that where clauses are consistent between insert, update, delete and select

Posted by Adrian Hope-Bailie (adrianhopebailie) on 2007-09-14T12:05:10.000+0000

Fixed with attached patch

Posted by Darby Felton (darby) on 2007-09-18T12:15:46.000+0000

This change appears not have been applied to SVN; reassigning to [~bkarwin].

Posted by Max Gordon (mgordon) on 2008-03-19T14:19:05.000+0000

Would love to see this issue reimplemented. All of a sudden my deletes where deleting whole tables!

I've changed the code to:

<pre class="highlight">
    /**
     * Convert an array, string, or Zend_Db_Expr object
     * into a string to put in a WHERE clause.
     *
     * @param mixed $where
     * @return string
     */
    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();
            }elseif (is_string($key)) {
                $term = $this->quoteInto($key, $term);
            }
            $term = '(' . $term . ')';
        }
        $where = implode(' AND ', $where);
        return $where;
    }

Posted by Wil Sinclair (wil) on 2008-03-25T20:43:59.000+0000

Please categorize/fix as needed.

Posted by Wil Sinclair (wil) on 2008-03-25T22:06:45.000+0000

Resetting 'fix version priority' and 'fix version' to be re-evaluated for next release.

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

Ralph, please evaluate and decide if/how we should act on this.

Posted by Ralph Schindler (ralph) on 2009-01-09T14:57:55.000+0000

Will evaluate within 2 weeks.

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