Index: trunk/kernel/include/itemdb.php =================================================================== diff -u -N -r1566 -r2082 --- trunk/kernel/include/itemdb.php (.../itemdb.php) (revision 1566) +++ trunk/kernel/include/itemdb.php (.../itemdb.php) (revision 2082) @@ -279,59 +279,44 @@ return true; } - function Update($UpdatedBy=NULL,$modificationDate = null) - { - global $Errors, $objSession; - - if(count($this->m_dirtyFieldsMap) == 0) - return true; + function Update($UpdatedBy=NULL,$modificationDate = null) + { + global $Errors, $objSession; - $this->SetModified($UpdatedBy,$modificationDate); - $sql = "UPDATE ".$this->tablename ." SET "; - $first = 1; + if( count($this->m_dirtyFieldsMap) == 0 ) return true; - foreach ($this->m_dirtyFieldsMap as $key => $value) - { - if(!is_numeric($key) && $key != $this->IdField() && $key!='ResourceId') - { - if($first) - { - if(isset($GLOBALS['_CopyFromEditTable'])) - $sql = sprintf("%s %s=%s",$sql,$key,$this->adodbConnection->qstr(($value))); - else - $sql = sprintf("%s %s=%s",$sql,$key,$this->adodbConnection->qstr(stripslashes($value))); - $first = 0; - } - else - { - if(isset($GLOBALS['_CopyFromEditTable'])) - $sql = sprintf("%s, %s=%s",$sql,$key,$this->adodbConnection->qstr(($value))); - else - $sql = sprintf("%s, %s=%s",$sql,$key,$this->adodbConnection->qstr(stripslashes($value))); - } - } - } + $this->SetModified($UpdatedBy, $modificationDate); + $sql = 'UPDATE '.$this->tablename .' SET '; - $sql = sprintf("%s WHERE %s = '%s'",$sql, $this->IdField(), $this->UniqueId()); + foreach ($this->m_dirtyFieldsMap as $key => $value) + { + if(!is_numeric($key) && $key != $this->IdField() && $key!='ResourceId') + { + if( is_null($value) ) + { + $value = 'NULL'; + } + else + { + $value = $this->adodbConnection->qstr( isset($GLOBALS['_CopyFromEditTable']) ? $value : stripslashes($value) ); + } + $sql .= '`'.$key.'` = '.$value.', '; + } + } + $sql = preg_replace('/(.*), $/','\\1',$sql); + + $sql .= ' WHERE '.$this->IdField().' = '.$this->adodbConnection->qstr( $this->UniqueId() ); - if($this->debuglevel>0) - echo $sql."
"; - if ($this->adodbConnection->Execute($sql) === false) - { - $Errors->AddError("error.DatabaseError",NULL,$this->adodbConnection->ErrorMsg(),"",get_class($this),"Update"); - return false; - } - - if ($objSession->GetVariable("HasChanges") == 2) { - $objSession->SetVariable("HasChanges", 1); - } - -/* if ($this->adodbConnection->Affected_Rows() > 0) { - $objSession->SetVariable("HasChanges", 1); - }*/ - - return true; - } + if( $this->debuglevel > 0 ) echo $sql.'
'; + if( $this->adodbConnection->Execute($sql) === false ) + { + $Errors->AddError("error.DatabaseError",NULL,$this->adodbConnection->ErrorMsg(),"",get_class($this),"Update"); + return false; + } + + if( $objSession->GetVariable('HasChanges') == 2 ) $objSession->SetVariable('HasChanges', 1); + return true; + } function ReplaceID($new_id) {