weird Zend_Db_Table_Abstract behaviour

5 messages Options
Embed this post
Permalink
nulele

weird Zend_Db_Table_Abstract behaviour

Reply Threaded More More options
Print post
Permalink
Hello,
I don't know why, but when I call the method below and there's nothing to update (datas are not changed) it returns false... I mean is this normal?
Even if datas are not changed I would expect a successful result of the update operation... it simply would update nothing!!

class Model_DbTable_Users extends Zend_Db_Table_Abstract
{
        protected $_name = 'users';
        protected $_primary = 'id_user';

....

        public function updateData($data, $id)
        {
                $id = (int)$id;
    if($this->update($data, "id_user = " . $id))
    {
    return true;
    }
    return false;
        }

...

}

Maybe the problem could be NOT NULL fileds in the db?
I know, would be better to include the update code in a try/catch statement, but I want to hear your opinion on this weird behaviour.

Thanks
till

Re: weird Zend_Db_Table_Abstract behaviour

Reply Threaded More More options
Print post
Permalink
On Fri, Oct 30, 2009 at 9:00 PM, nulele <[hidden email]> wrote:

>
> Hello,
> I don't know why, but when I call the method below and there's nothing to
> update (datas are not changed) it returns false... I mean is this normal?
> Even if datas are not changed I would expect a successful result of the
> update operation... it simply would update nothing!!
>
> class Model_DbTable_Users extends Zend_Db_Table_Abstract
> {
>        protected $_name = 'users';
>        protected $_primary = 'id_user';
>
> ....
>
>        public function updateData($data, $id)
>        {
>                $id = (int)$id;

Maybe $id is casted to 0 here, and nothing matches?

Till

>        if($this->update($data, "id_user = " . $id))
>        {
>                return true;
>        }
>        return false;
>        }
>
> ...
>
> }
>
> Maybe the problem could be NOT NULL fileds in the db?
> I know, would be better to include the update code in a try/catch statement,
> but I want to hear your opinion on this weird behaviour.
>
> Thanks
> --
> View this message in context: http://old.nabble.com/weird-Zend_Db_Table_Abstract-behaviour-tp26136108p26136108.html
> Sent from the Zend DB mailing list archive at Nabble.com.
>
>
nulele

Re: weird Zend_Db_Table_Abstract behaviour

Reply Threaded More More options
Print post
Permalink
I'm sure all input parameters are valid... the problem only occurs if datas don't need to be updated.

I can extend my question: how do you check db operation (insert/update/delete) if something goes wrong?

bye



tfk wrote:
On Fri, Oct 30, 2009 at 9:00 PM, nulele <nulele@gmail.com> wrote:
>
> Hello,
> I don't know why, but when I call the method below and there's nothing to
> update (datas are not changed) it returns false... I mean is this normal?
> Even if datas are not changed I would expect a successful result of the
> update operation... it simply would update nothing!!
>
> class Model_DbTable_Users extends Zend_Db_Table_Abstract
> {
>        protected $_name = 'users';
>        protected $_primary = 'id_user';
>
> ....
>
>        public function updateData($data, $id)
>        {
>                $id = (int)$id;

Maybe $id is casted to 0 here, and nothing matches?

Till

>        if($this->update($data, "id_user = " . $id))
>        {
>                return true;
>        }
>        return false;
>        }
>
> ...
>
> }
>
> Maybe the problem could be NOT NULL fileds in the db?
> I know, would be better to include the update code in a try/catch statement,
> but I want to hear your opinion on this weird behaviour.
>
> Thanks
> --
> View this message in context: http://old.nabble.com/weird-Zend_Db_Table_Abstract-behaviour-tp26136108p26136108.html
> Sent from the Zend DB mailing list archive at Nabble.com.
>
>
prodigitalson

Re: weird Zend_Db_Table_Abstract behaviour

Reply Threaded More More options
Print post
Permalink
In reply to this post by nulele
The result is successful. Update returns the number of affected rows. IF there is nothing to update it will retun 0 which is going to eval to false. IF something goes wrong in the query its going to throw an exception, not return false.

if you want to check that the qurey went through then wrap your update in a try catch and return false in the catch.

If on the other hand you are expecting to at least have one row modified then you can test agianst > 0.

nulele wrote:
Hello,
I don't know why, but when I call the method below and there's nothing to update (datas are not changed) it returns false... I mean is this normal?
Even if datas are not changed I would expect a successful result of the update operation... it simply would update nothing!!

class Model_DbTable_Users extends Zend_Db_Table_Abstract
{
        protected $_name = 'users';
        protected $_primary = 'id_user';

....

        public function updateData($data, $id)
        {
                $id = (int)$id;
    if($this->update($data, "id_user = " . $id))
    {
    return true;
    }
    return false;
        }

...

}

Maybe the problem could be NOT NULL fileds in the db?
I know, would be better to include the update code in a try/catch statement, but I want to hear your opinion on this weird behaviour.

Thanks
nulele

Re: weird Zend_Db_Table_Abstract behaviour

Reply Threaded More More options
Print post
Permalink
Yes... I would have thought it...
I'll follow your suggestion to wrap the update in a try/catch statement.
Many thanks!!


prodigitalson wrote:
The result is successful. Update returns the number of affected rows. IF there is nothing to update it will retun 0 which is going to eval to false. IF something goes wrong in the query its going to throw an exception, not return false.

if you want to check that the qurey went through then wrap your update in a try catch and return false in the catch.

If on the other hand you are expecting to at least have one row modified then you can test agianst > 0.

nulele wrote:
Hello,
I don't know why, but when I call the method below and there's nothing to update (datas are not changed) it returns false... I mean is this normal?
Even if datas are not changed I would expect a successful result of the update operation... it simply would update nothing!!

class Model_DbTable_Users extends Zend_Db_Table_Abstract
{
        protected $_name = 'users';
        protected $_primary = 'id_user';

....

        public function updateData($data, $id)
        {
                $id = (int)$id;
    if($this->update($data, "id_user = " . $id))
    {
    return true;
    }
    return false;
        }

...

}

Maybe the problem could be NOT NULL fileds in the db?
I know, would be better to include the update code in a try/catch statement, but I want to hear your opinion on this weird behaviour.

Thanks