2009年5月27日星期三

Re: [fw-db] Zend_Db_Table_Abstract delete IN

That's because you're quoting the result of implode(). You can pass in an array to quote() and it will automatically quote each item in the array for you and separate them with commas.

Try this:

        public function deleteBulk($feedId, array $contentIds) {
               return $this->delete(
                       $this->getAdapter()->quoteInto('FeedId = ?', $feedId) .
                       ' AND ContentId IN (' . $this->getAdapter()->quote($contentIds) . ')');
        }

Basically just remove the implode and it should work.

-Hector


On Wed, May 27, 2009 at 9:11 AM, umpirsky <umpirsky@gmail.com> wrote:

Hi people.

I have this method in my model, it receives an id and array of integers
contentIds


 /**
         * Delete contents by FeedId and content ids.
         *
         * @param int $feedId
         * @param arrat $contentIds
         * @return int number of deleted rows
         */
        public function deleteBulk($feedId, array $contentIds) {
               return $this->delete(
                       $this->getAdapter()->quoteInto('FeedId = ?', $feedId) .
                       ' AND ContentId IN (' . implode(',', $contentIds) . ')');
        }

gives

DELETE FROM `Content` WHERE (FeedId = 1 AND ContentId IN
(179218,179217,179216,179215))

This works ok, but is not safe. When I do

/**
         * Delete contents by FeedId and content ids.
         *
         * @param int $feedId
         * @param arrat $contentIds
         * @return int number of deleted rows
         */
        public function deleteBulk($feedId, array $contentIds) {
               return $this->delete(
                       $this->getAdapter()->quoteInto('FeedId = ?', $feedId) .
                       ' AND ContentId IN (' . $this->getAdapter()->quote(implode(',',
$contentIds)) . ')');
        }

or something similar, instead getting

DELETE FROM `Content` WHERE (FeedId = 1 AND ContentId IN
('179218,179217,179216,179215'))

and delete nothing from table.

Where am I doing it wrong.

Regards,
Sasa Stamenkovic
--
View this message in context: http://www.nabble.com/Zend_Db_Table_Abstract-delete-IN-tp23745710p23745710.html
Sent from the Zend DB mailing list archive at Nabble.com.


没有评论: