- if ($this->idfield_editable && $id != Post::v($this->idfield))
- XDB::execute("UPDATE {$this->table} SET {$this->idfield} = {?} WHERE {$this->idfield} = {?} AND {$this->whereclause}", Post::v($this->idfield), $id);
- XDB::execute("REPLACE INTO {$this->table} VALUES ($values)");
+ if (!$new) {
+ $update = array();
+ foreach ($values as $field => $value) {
+ $update[] = $field . ' = ' . $value;
+ }
+ $update = implode(', ', $update);
+ XDB::rawExecute("UPDATE {$this->table}
+ SET {$update}
+ WHERE {$this->idfield} = " . XDB::escape($id) . "
+ AND {$this->whereclause}");
+ } else {
+ $fields = implode(', ', array_keys($values));
+ $values = implode(', ', $values);
+ XDB::rawExecute("INSERT INTO {$this->table} ({$fields})
+ VALUES ({$values})");
+ }