[PEAR-DEV] [PATCH] WHERE clause in DB_DataObjects::update()
by Michael Henry other posts by this author
Nov 14 2006 5:09PM messages near this date
[PEAR-DEV] Latest actions as PEAR_PackageFileManager XO
|
Re: [PEAR-DEV] [PATCH] WHERE clause in DB_DataObjects::update()
Hi all,
None of the keys on my tables are detected when I run createTables.php.
That is a problem I'll deal with later but it has highlighted another
problem in the DB_DataObjects::update() method.
DB_DataObjects::update() calls _build_condition() which generates the
"where" clause based on:
1. the keys for the table, or
2. all the columns in the table in the case where no keys have been
specified.
_build_condition() does not take into account the column which is being
updated - that is, it will add a "where" condition for the column whose
data has changed. Obviously that condition will never be true.
I have made a few small changes which are in the patch below.
Regards,
Michael
Index: DataObject.php
===================================================================
RCS file: /repository/pear/DB_DataObject/DataObject.php,v
retrieving revision 1.422
diff -u -r1.422 DataObject.php
--- DataObject.php 11 Nov 2006 04:05:02 -0000 1.422
+++ DataObject.php 15 Nov 2006 00:57:31 -0000
@@ -1169,6 +1169,7 @@
$this-> raiseError("update:No table definition for
{$this-> __table}", DB_DATAOBJECT_ERROR_INVALIDCONFIG);
return false;
}
+ $update_cols = array();
$datasaved = 1;
$settings = '';
$this-> _connect();
@@ -1186,6 +1187,9 @@
// dont write things that havent changed..
if (($dataObject !== false) && isset($dataObject-> $k) &&
($dataObject-> $k === $this->$k)) {
continue;
+ } else {
+ // Add column to $update_cols so that it isn't included
in the "where" condition
+ $update_cols[] = $k;
}
// - dont write keys to left.!!!
@@ -1256,7 +1260,7 @@
$this-> debug("got keys as ".serialize($keys),3);
}
if ($dataObject !== true) {
- $this-> _build_condition($items,$keys);
+ $this-> _build_condition($items,$keys,$update_cols);
} else {
// prevent wiping out of data!
if (empty($this-> _query['condition'])) {
Thread:
Michael Henry
Alan Knowles
Michael Henry
Alan Knowles
|