From: Jakub Vrana Date: Thu, 22 Jul 2010 12:04:57 +0000 (+0200) Subject: PostgreSQL import support X-Git-Tag: v3.0.0~51 X-Git-Url: https://git.joonet.de/?a=commitdiff_plain;h=c505440194322dccff0344e8d53a9c084b43a16c;p=adminer.git PostgreSQL import support --- diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index de449d2a..b3c21d00 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -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"; } diff --git a/adminer/drivers/pgsql.inc.php b/adminer/drivers/pgsql.inc.php index 4255144b..34c969a8 100644 --- a/adminer/drivers/pgsql.inc.php +++ b/adminer/drivers/pgsql.inc.php @@ -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 } diff --git a/adminer/drivers/sqlite.inc.php b/adminer/drivers/sqlite.inc.php index 99d4ce55..43f7c70f 100644 --- a/adminer/drivers/sqlite.inc.php +++ b/adminer/drivers/sqlite.inc.php @@ -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) . ")"); } diff --git a/adminer/select.inc.php b/adminer/select.inc.php index 21e3e2ac..17e6ff87 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -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; }