mirror of
https://github.com/vrana/adminer.git
synced 2025-08-12 17:44:07 +02:00
Fix insertUpdate for mssql
Signed-off-by: Takashi SHIRAI <shirai@nintendo.co.jp>
This commit is contained in:
committed by
Jakub Vrana
parent
2f237dfa04
commit
0ed3c5cb19
@@ -186,19 +186,25 @@ if (isset($_GET["mssql"])) {
|
|||||||
class Min_Driver extends Min_SQL {
|
class Min_Driver extends Min_SQL {
|
||||||
|
|
||||||
function insertUpdate($table, $rows, $primary) {
|
function insertUpdate($table, $rows, $primary) {
|
||||||
|
$fields = fields($table);
|
||||||
foreach ($rows as $set) {
|
foreach ($rows as $set) {
|
||||||
$update = array();
|
$update = array();
|
||||||
|
$insert = array();
|
||||||
$where = array();
|
$where = array();
|
||||||
foreach ($set as $key => $val) {
|
foreach ($set as $key => $val) {
|
||||||
$update[] = "$key = $val";
|
$name = idf_unescape($key);
|
||||||
if (isset($primary[idf_unescape($key)])) {
|
if (!$fields[$name]["auto_increment"]) {
|
||||||
|
$update[] = "$key = $val";
|
||||||
|
$insert[$key] = $val;
|
||||||
|
}
|
||||||
|
if (isset($primary[$name])) {
|
||||||
$where[] = "$key = $val";
|
$where[] = "$key = $val";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//! can use only one query for all rows
|
//! can use only one query for all rows
|
||||||
if (!queries("MERGE " . table($table) . " USING (VALUES(" . implode(", ", $set) . ")) AS source (c" . implode(", c", range(1, count($set))) . ") ON " . implode(" AND ", $where) //! source, c1 - possible conflict
|
if (!queries("MERGE " . table($table) . " USING (VALUES(" . implode(", ", $set) . ")) AS source (c" . implode(", c", range(1, count($set))) . ") ON " . implode(" AND ", $where) //! source, c1 - possible conflict
|
||||||
. " WHEN MATCHED THEN UPDATE SET " . implode(", ", $update)
|
. " WHEN MATCHED THEN UPDATE SET " . implode(", ", $update)
|
||||||
. " WHEN NOT MATCHED THEN INSERT (" . implode(", ", array_keys($set)) . ") VALUES (" . implode(", ", $set) . ");" // ; is mandatory
|
. " WHEN NOT MATCHED THEN INSERT (" . implode(", ", array_keys($insert)) . ") VALUES (" . implode(", ", $insert) . ");" // ; is mandatory
|
||||||
)) {
|
)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user