=== modified file 'includes/database/mysql/query.inc' --- includes/database/mysql/query.inc Thu Aug 21 21:36:36 2008 +++ includes/database/mysql/query_odku_values.inc Mon Sep 01 05:04:17 2008 @@ -81,13 +81,11 @@ $update_fields = $this->updateFields; } else { - $update_fields = $this->insertFields; - // If there are no exclude fields, this is a no-op. - foreach ($this->excludeFields as $exclude_field) { - unset($update_fields[$exclude_field]); - } + // When update fields are derived from insert fields, we don't need placeholders + // since we can tell MySQL to reuse insert supplied values. ie. field=VALUES(field) + $update_fields = array(); } - + $insert_fields = $this->insertFields + $this->keyFields; $max_placeholder = 0; @@ -106,7 +104,7 @@ } unset($update_fields[$field]); } - + // Because we filter $fields the same way here and in __toString(), the // placeholders will all match up properly. $max_placeholder = 0; @@ -123,7 +121,6 @@ public function __toString() { // Set defaults. - $update_fields = array(); if ($this->updateFields) { $update_fields = $this->updateFields; } @@ -134,7 +131,7 @@ unset($update_fields[$exclude_field]); } } - + $insert_fields = $this->insertFields + $this->keyFields; $query = "INSERT INTO {" . $this->table . '} (' . implode(', ', array_keys($insert_fields)) . ') VALUES '; @@ -147,7 +144,7 @@ } $query .= '(' . implode(', ', $values) . ') ON DUPLICATE KEY UPDATE '; - + // Expressions take priority over literal fields, so we process those first // and remove any literal fields that conflict. $max_placeholder = 0; @@ -157,10 +154,17 @@ unset($update_fields[$field]); } + // Build update fields clausules based on caller supplied list, + // or derived from insert supplied values (shorter statement). foreach ($update_fields as $field => $value) { - $update[] = ($field . '=:db_update_placeholder_' . $max_placeholder++); + if ($this->updateFields) { + $update[] = ($field . '=:db_update_placeholder_' . $max_placeholder++); + } + else { + $update[] = ($field . '=VALUES(' . $field . ')'); + } } - + $query .= implode(', ', $update); return $query;