diff --git a/adminer/edit.inc.php b/adminer/edit.inc.php index 554d0e22..856d8d44 100644 --- a/adminer/edit.inc.php +++ b/adminer/edit.inc.php @@ -17,8 +17,17 @@ if ($_POST && !$error && !isset($_GET["select"])) { $location = ME . "select=" . urlencode($TABLE); } + $indexes = indexes($TABLE); + $unique_array = unique_array($_GET["where"], $indexes); + $query_where = "\nWHERE $where"; + if (isset($_POST["delete"])) { - query_redirect("DELETE" . limit1("FROM " . table($TABLE), " WHERE $where"), $location, lang('Item has been deleted.')); + $query = "FROM " . table($TABLE); + query_redirect( + "DELETE" . ($unique_array ? " $query$query_where" : limit1($query, $query_where)), + $location, + lang('Item has been deleted.') + ); } else { $set = array(); foreach ($fields as $name => $field) { @@ -32,7 +41,12 @@ if ($_POST && !$error && !isset($_GET["select"])) { if (!$set) { redirect($location); } - query_redirect("UPDATE" . limit1(table($TABLE) . " SET" . implode(",", $set), "\nWHERE $where"), $location, lang('Item has been updated.')); + $query = table($TABLE) . " SET" . implode(",", $set); + query_redirect( + "UPDATE" . ($unique_array ? " $query$query_where" : limit1($query, $query_where)), + $location, + lang('Item has been updated.') + ); } else { $result = insert_into($TABLE, $set); $last_id = ($result ? last_id() : 0); diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 1fb4725c..e94edc95 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -303,7 +303,7 @@ function get_rows($query, $connection2 = null, $error = "

") { /** Find unique identifier of a row * @param array * @param array result of indexes() -* @return array +* @return array or null if there is no unique identifier */ function unique_array($row, $indexes) { foreach ($indexes as $index) { @@ -318,13 +318,6 @@ function unique_array($row, $indexes) { return $return; } } - $return = array(); - foreach ($row as $key => $val) { - if (!preg_match('~^(COUNT\\((\\*|(DISTINCT )?`(?:[^`]|``)+`)\\)|(AVG|GROUP_CONCAT|MAX|MIN|SUM)\\(`(?:[^`]|``)+`\\))$~', $key)) { //! columns looking like functions - $return[$key] = $val; - } - } - return $return; } /** Create SQL condition from parsed query string diff --git a/adminer/select.inc.php b/adminer/select.inc.php index 38356762..36fbe557 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -332,6 +332,14 @@ if (!$columns) { foreach ($adminer->rowDescriptions($rows, $foreign_keys) as $n => $row) { $unique_array = unique_array($rows[$n], $indexes); + if (!$unique_array) { + $unique_array = array(); + foreach ($rows[$n] as $key => $val) { + if (!preg_match('~^(COUNT\\((\\*|(DISTINCT )?`(?:[^`]|``)+`)\\)|(AVG|GROUP_CONCAT|MAX|MIN|SUM)\\(`(?:[^`]|``)+`\\))$~', $key)) { //! columns looking like functions + $unique_array[$key] = $val; + } + } + } $unique_idf = ""; foreach ($unique_array as $key => $val) { if (strlen($val) > 64) { diff --git a/changes.txt b/changes.txt index b6dbc59a..fdac2a94 100644 --- a/changes.txt +++ b/changes.txt @@ -9,6 +9,7 @@ Remove bzip2 compression support Constraint memory used in TAR export Allow exporting views dependent on each other (bug #3459151) Fix resetting search (bug #3612507) +Don't use LIMIT 1 if updating unique row (bug #3613109) Restrict editing rows without unique identifier to search results Display navigation bellow main content on mobile browsers MySQL: Optimize create table page and Editor navigation