]> git.joonet.de Git - adminer.git/commitdiff
PostgreSQL import support
authorJakub Vrana <jakub@vrana.cz>
Thu, 22 Jul 2010 12:04:57 +0000 (14:04 +0200)
committerJakub Vrana <jakub@vrana.cz>
Thu, 22 Jul 2010 12:04:57 +0000 (14:04 +0200)
adminer/drivers/mysql.inc.php
adminer/drivers/pgsql.inc.php
adminer/drivers/sqlite.inc.php
adminer/select.inc.php

index de449d2a2a6c7b8fbcec2f912d2761a2c9951558..b3c21d00f5a144fbbe17d071a2a47a15979beeb2 100644 (file)
@@ -767,9 +767,10 @@ if (!defined("DRIVER")) {
        /** Insert or update data in the table
        * @param string
        * @param array
+       * @param array
        * @return bool
        */
-       function insert_update($table, $set) {
+       function insert_update($table, $set, $indexes) {
                foreach ($set as $key => $val) {
                        $set[$key] = "$key = $val";
                }
index 4255144b1ba9e4ec6906ab60483c2ea0ada5861e..34c969a8d3f3d7fe144f5d989b972f47550d1f37 100644 (file)
@@ -467,6 +467,28 @@ WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name = " . $connection->qu
                return queries("INSERT INTO " . table($table) . ($set ? " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")" : "DEFAULT VALUES"));
        }
        
+       function insert_update($table, $set, $indexes) {
+               global $connection;
+               $primary = array();
+               foreach ($indexes as $index) {
+                       if ($index["type"] == "PRIMARY") {
+                               $primary = array_map("idf_escape", $index["columns"]);
+                               break;
+                       }
+               }
+               $update = array();
+               $where = array();
+               foreach ($set as $key => $val) {
+                       $update[] = "$key = $val";
+                       if (in_array($key, $primary)) {
+                               $where[] = "$key = $val";
+                       }
+               }
+               return ($where && queries("UPDATE " . table($table) . " SET " . implode(", ", $update) . " WHERE " . implode(" AND ", $where)) && $connection->affected_rows)
+                       || queries("INSERT INTO " . table($table) . " (" . implode(", ", array_keys($set)) . ") VALUES (" . implode(", ", $set) . ")")
+               ;
+       }
+       
        function last_id() {
                return 0; // there can be several sequences
        }
index 99d4ce55f8dede7117cb24b7781b0894815f602d..43f7c70f9d9bce6a4807d75e5445b4b6d64daafa 100644 (file)
@@ -492,7 +492,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
                return queries("INSERT INTO " . table($table) . ($set ? " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")" : "DEFAULT VALUES"));
        }
        
-       function insert_update($table, $set) {
+       function insert_update($table, $set, $indexes) {
                return queries("REPLACE INTO " . table($table) . " (" . implode(", ", array_keys($set)) . ") VALUES (" . implode(", ", $set) . ")");
        }
        
index 21e3e2ac0c45b108da6c7b64eb7c21bd68fef1a3..17e6ff8705d477b47010060a3ea78ca793f22e75 100644 (file)
@@ -148,7 +148,7 @@ if ($_POST && !$error) {
                                        foreach ($matches2[1] as $i => $col) {
                                                $set[idf_escape($cols[$i])] = ($col == "" && $fields[$cols[$i]]["null"] ? "NULL" : $connection->quote(str_replace('""', '"', preg_replace('~^"|"$~', '', $col))));
                                        }
-                                       $result = insert_update($TABLE, $set);
+                                       $result = insert_update($TABLE, $set, $indexes);
                                        if (!$result) {
                                                break;
                                        }