using mysql's REPLACE syntax instead of doing first a select to determine if the column exists and then an update or insert accordingly

This commit is contained in:
Ralf Becker 2004-09-18 15:18:48 +00:00
parent bbe871a450
commit 355beade2a

View File

@ -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 "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app') sql='$sql'</p>\n";
return $this->query($sql,$line,$file);