View Issue Details

IDProjectCategoryView StatusLast Update
165PHPOF2Defaultpublic16 Apr 2009 07:29
Reportermrosenquist Assigned Totimj  
PrioritynormalSeveritymajorReproducibilityhave not tried
Status closedResolutionfixed 
Target Version0.11.1Fixed in Version0.11.1 
Summary165: DBRow::update() doesn't work if primary key fields are manually filled
DescriptionObscure issue, update wont work if all row fields are manually created.

There is a internal value for _orig_prikey is initally set to '' not NULL

which is set in the construct
call stack
__construct -> clear -> initChangeRecording()

It is usually reset by calls to get or fillFromResult for update() cases.

However in the row is manually populated (including the primary keys), this value never gets reset.

When an update is called it uses the _orig_prikey to generate the where clause.
If it is '', then the where in the update is like the following:
UPDATE table SET field='foo' WHERE pri_field='';

and so no records are updated.

The fix for solution 1. is attached
Additional InformationNot quite sure the best solution.
However the solutions in order of preference
1.
serialisePriKey(); should return null if there is no primary key values
on update() check for _orig_prikey == null if null should set it to serialisePriKey()

2.
on update() check for empty(_orig_prikey) if null should set it to serialisePriKey()
TagsNo tags attached.
Attached Files
DBRow.php.patch (870 bytes)   
Index: DBRow.php
===================================================================
--- DBRow.php	(revision 14749)
+++ DBRow.php	(working copy)
@@ -151,7 +151,9 @@
 	 */
 	public function serialisePriKey()
 	{
-		
+		if (!$this->primaryKeyFilled()) {
+			return null;
+		}
 		$keys = array();
 		foreach($this->pri_keys as $field){
 			$keys[] = $this->{$field};
@@ -560,7 +562,10 @@
 			// If we know what the original pri key of this row was, check to
 			// see if it has changed: if so, we need to update the pri key
 			// columns too
-			if ($this->_orig_prikey !== null) {
+			// In the case it was empty reset it
+			if ($this->_orig_prikey === null) {
+				$this->_orig_prikey = $this->serialisePriKey();
+			} else {
 				if ($this->_orig_prikey != $this->serialisePriKey()) {
 					$fields_to_update = array_merge($fields_to_update, $this->pri_keys);
 				}
DBRow.php.patch (870 bytes)   

Activities

timj

15 Apr 2009 16:45

manager   ~194

Fixed in SVN r1611

Issue History

Date Modified Username Field Change
12 Feb 2009 14:55 mrosenquist New Issue
12 Feb 2009 14:55 mrosenquist File Added: DBRow.php.patch
15 Apr 2009 13:31 timj Target Version => 0.11.1
15 Apr 2009 16:43 timj Assigned To => timj
15 Apr 2009 16:43 timj Status new => assigned
15 Apr 2009 16:45 timj Note Added: 194
15 Apr 2009 16:45 timj Status assigned => resolved
15 Apr 2009 16:45 timj Resolution open => fixed
15 Apr 2009 16:45 timj Fixed in Version => 0.11.1
16 Apr 2009 07:08 timj Summary Obscure issue, update don't work if all row fields are manually created => DBRow::update() doesn't work if primary key fields are manually filled
16 Apr 2009 07:29 timj Status resolved => closed