1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-17 12:00:41 +02:00

MS SQL: Fix CSV import (bug #859)

This commit is contained in:
Jakub Vrana
2025-02-26 22:40:28 +01:00
parent 81340ff7e5
commit 70f9ff75fc
2 changed files with 11 additions and 6 deletions

View File

@@ -206,12 +206,16 @@ if (isset($_GET["mssql"])) {
foreach ($rows as $set) {
$values[] = "(" . implode(", ", $set) . ")";
}
queries("SET IDENTITY_INSERT " . table($table) . " ON");
$return = queries("MERGE " . table($table) . " USING (VALUES\n\t" . implode(",\n\t", $values) . "\n) AS source ($columns) ON " . implode(" AND ", $where) //! source, c1 - possible conflict
. ($update ? "\nWHEN MATCHED THEN UPDATE SET " . implode(", ", $update) : "")
. "\nWHEN NOT MATCHED THEN INSERT (" . implode(", ", array_keys($set)) . ") VALUES ($columns);" // ; is mandatory
);
queries("SET IDENTITY_INSERT " . table($table) . " OFF");
if ($where) {
queries("SET IDENTITY_INSERT " . table($table) . " ON");
$return = queries("MERGE " . table($table) . " USING (VALUES\n\t" . implode(",\n\t", $values) . "\n) AS source ($columns) ON " . implode(" AND ", $where) //! source, c1 - possible conflict
. ($update ? "\nWHEN MATCHED THEN UPDATE SET " . implode(", ", $update) : "")
. "\nWHEN NOT MATCHED THEN INSERT (" . implode(", ", array_keys($set)) . ") VALUES ($columns);" // ; is mandatory
);
queries("SET IDENTITY_INSERT " . table($table) . " OFF");
} else {
$return = queries("INSERT INTO " . table($table) . " VALUES\n" . implode(",\n", $values));
}
return $return;
}

View File

@@ -7,6 +7,7 @@ SQLite: Display all rows of variable values
SQLite: Remove support for SQLite version 2
MS SQL: Support export (bug #480)
MS SQL: Display foreign keys ON UPDATE and ON DELETE
MS SQL: Fix CSV import (bug #859)
MS SQL: Fix altering foreign key
MS SQL PDO: Support offset
MS SQL: Remove support for MSSQL extension