]> git.joonet.de Git - adminer.git/commitdiff
CSV import for MS SQL
authorJakub Vrana <jakub@vrana.cz>
Tue, 3 Aug 2010 15:47:26 +0000 (17:47 +0200)
committerJakub Vrana <jakub@vrana.cz>
Tue, 3 Aug 2010 15:47:26 +0000 (17:47 +0200)
adminer/drivers/mssql.inc.php
adminer/drivers/pgsql.inc.php

index 6967928279d001628ef0ab2542b80f568d5cff75..83764e77423b859d94e02209579514faf24edc44 100644 (file)
@@ -476,6 +476,22 @@ WHERE OBJECT_NAME(indexes.object_id) = " . $connection2->quote($table)
                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
index b4d615b6f742529067ec2bec1726839c39d8b204..02e60b011cb7e2f23c631573caf8ebfbc35c2ca1 100644 (file)
@@ -473,7 +473,7 @@ WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name = " . $connection->qu
                $where = array();
                foreach ($set as $key => $val) {
                        $update[] = "$key = $val";
-                       if (isset($primary[$key])) {
+                       if (isset($primary[idf_unescape($key)])) {
                                $where[] = "$key = $val";
                        }
                }