From 355beade2a1c7244e82a2f6774ee9dae1739c09a Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Sat, 18 Sep 2004 15:18:48 +0000 Subject: [PATCH] using mysql's REPLACE syntax instead of doing first a select to determine if the column exists and then an update or insert accordingly --- phpgwapi/inc/class.db.inc.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/phpgwapi/inc/class.db.inc.php b/phpgwapi/inc/class.db.inc.php index 4711b28072..c6677e48f1 100644 --- a/phpgwapi/inc/class.db.inc.php +++ b/phpgwapi/inc/class.db.inc.php @@ -970,9 +970,8 @@ return "'" . $this->Link_ID->BlobEncode($value) . "'"; case 'I': return $this->Link_ID->BlobEncode($value); - default: - break; // handled like strings } + break; // handled like strings case 'date': return $this->Link_ID->DBDate($value); case 'timestamp': @@ -1139,6 +1138,7 @@ $table_def = $this->get_table_definitions($app,$table); $sql_append = ''; + $cmd = 'INSERT'; if (is_array($where) && count($where)) { switch($this->Type) @@ -1146,6 +1146,9 @@ case 'sapdb': case 'maxdb': $sql_append = ' UPDATE DUPLICATES'; break; + case 'mysql': + $cmd = 'REPLACE'; + break; default: $this->select($table,'count(*)',$where,$line,$file); if ($this->next_record() && $this->f(0)) @@ -1156,7 +1159,7 @@ } $data = array_merge($where,$data); // the checked values need to be inserted too, value in data has precedence } - $sql = "INSERT INTO $table ".$this->column_data_implode(',',$data,'VALUES',False,$table_def['fd']).$sql_append; + $sql = "$cmd INTO $table ".$this->column_data_implode(',',$data,'VALUES',False,$table_def['fd']).$sql_append; if ($this->Debug) echo "

db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app') sql='$sql'

\n"; return $this->query($sql,$line,$file);