Skip to content

Commit

Permalink
CSV import for MS SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
vrana committed Aug 3, 2010
1 parent dba6a90 commit 52e8c03
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions adminer/drivers/mssql.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,22 @@ function insert_into($table, $set) {
return queries("INSERT INTO " . table($table) . ($set ? " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")" : "DEFAULT VALUES"));
}

function insert_update($table, $set, $primary) {
$update = array();
$where = array();
foreach ($set as $key => $val) {
$update[] = "$key = $val";
if (isset($primary[idf_unescape($key)])) {
$where[] = "$key = $val";
}
}
// can use only one query for all rows with different API
return 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 NOT MATCHED THEN INSERT (" . implode(", ", array_keys($set)) . ") VALUES (" . implode(", ", $set) . ");" // ; is mandatory
);
}

function last_id() {
global $connection;
return $connection->result("SELECT SCOPE_IDENTITY()"); // @@IDENTITY can return trigger INSERT
Expand Down
2 changes: 1 addition & 1 deletion adminer/drivers/pgsql.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ function insert_update($table, $set, $primary) {
$where = array();
foreach ($set as $key => $val) {
$update[] = "$key = $val";
if (isset($primary[$key])) {
if (isset($primary[idf_unescape($key)])) {
$where[] = "$key = $val";
}
}
Expand Down

0 comments on commit 52e8c03

Please sign in to comment.