diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index b3c21d00..b64d2045 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -767,10 +767,10 @@ if (!defined("DRIVER")) { /** Insert or update data in the table * @param string * @param array - * @param array + * @param array columns in keys * @return bool */ - function insert_update($table, $set, $indexes) { + function insert_update($table, $set, $primary) { foreach ($set as $key => $val) { $set[$key] = "$key = $val"; } diff --git a/adminer/drivers/pgsql.inc.php b/adminer/drivers/pgsql.inc.php index 34c969a8..96526726 100644 --- a/adminer/drivers/pgsql.inc.php +++ b/adminer/drivers/pgsql.inc.php @@ -467,20 +467,13 @@ 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) { + function insert_update($table, $set, $primary) { 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)) { + if (isset($primary[$key])) { $where[] = "$key = $val"; } } diff --git a/adminer/drivers/sqlite.inc.php b/adminer/drivers/sqlite.inc.php index 43f7c70f..bf5c3097 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, $indexes) { + function insert_update($table, $set, $primary) { 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 9ec8a945..8b76c3b0 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -28,17 +28,18 @@ $group_by = ($group && count($group) < count($select) ? "\nGROUP BY " . implode( if ($_POST && !$error) { $where_check = "(" . implode(") OR (", array_map('where_check', (array) $_POST["check"])) . ")"; - $primary = null; + $primary = $unselected = null; foreach ($indexes as $index) { if ($index["type"] == "PRIMARY") { - $primary = ($select ? array_flip($index["columns"]) : array()); // empty array means that all primary fields are selected + $primary = array_flip($index["columns"]); + $unselected = ($select ? $primary : array()); break; } } foreach ($select as $key => $val) { $val = $_GET["columns"][$key]; if (!$val["fun"]) { - unset($primary[$val["col"]]); + unset($unselected[$val["col"]]); } } if ($_POST["export"]) { @@ -54,7 +55,7 @@ if ($_POST && !$error) { } dump_csv($row); } - if (!is_array($_POST["check"]) || $primary === array()) { + if (!is_array($_POST["check"]) || $unselected === array()) { $where2 = $where; if (is_array($_POST["check"])) { $where2[] = "($where_check)"; @@ -99,7 +100,7 @@ if ($_POST && !$error) { $command = "INSERT"; $query = "INTO $query"; } - if ($_POST["all"] || ($primary === array() && $_POST["check"]) || count($group) < count($select)) { + if ($_POST["all"] || ($unselected === array() && $_POST["check"]) || count($group) < count($select)) { $result = queries($command . " $query" . ($_POST["all"] ? ($where ? "\nWHERE " . implode(" AND ", $where) : "") : "\nWHERE $where_check")); $affected = $connection->affected_rows; } else { @@ -154,7 +155,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, $indexes); + $result = insert_update($TABLE, $set, $primary); if (!$result) { break; }