DB_DataObject - update only if changed
| From: | Geoff Hopson | Date: | Wed, 05 Mar 2003 12:13:05 +0000 |
| Subject: | DB_DataObject - update only if changed | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-4041@lists.php.net to get a copy of this message | ||
Hi,
I'm playing around with the DB_DataObject stuff (very nice - thanks!), but have a requirement only to update columns that have been changed. Right now the update method seems to set all columns to the current attributes of the object. For example, I have a user object with username, password, name attributes. If I change only the name on a form, the update statement is
update users set username='blah', password = 'blah', name = 'newblah' where usr_id = 6;
I would like the statement to be:
update users set name = 'newblah' where usr_id = 6;
Basically, I would like something like setFrom to only set the attributes that have changed and to mark them as dirty somehow.
First question: are there plans to do this?
Now on to my planned solution - all comments appreciated!
In setFrom:
- test the new value against the old value
- if different, set the old value to the new value AND
- set the $items so that the value for the attribute (eg DB_DATAOBJECT_STR) is bitwise-ANDed with a new value DB_DATABASE_DIRTY (which I have set to be 128)
in update():
- rejig the query builder to test for the DB_DATABASE_DIRTY bit, and if the attribute is dirty, use it in the query
I'm playing with this right now - I can post the code if and when I get it working, but just wanted to ensure that I wasn't doing something stoopid (PHP novice...I'm allowed some mistakes :-)
Thanks for any input,
Geoff
--
Geoff Hopson
Objectology Ltd.
http://www.objectology.co.uk/