]> git.joonet.de Git - adminer.git/commitdiff
Don't use LIMIT 1 if updating unique row (bug #3613109)
authorJakub Vrana <jakub@vrana.cz>
Sat, 11 May 2013 20:03:39 +0000 (13:03 -0700)
committerJakub Vrana <jakub@vrana.cz>
Sat, 11 May 2013 20:05:40 +0000 (13:05 -0700)
adminer/edit.inc.php
adminer/include/functions.inc.php
adminer/select.inc.php
changes.txt

index 554d0e220b910b95028ce90b768bb6620636b7fd..856d8d442551f397868dcd23d640d2cfa5cd0e25 100644 (file)
@@ -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);
index 1fb4725c56147c740bb1671ff1d049825f7e80ef..e94edc95164850422a23a61b71574a0f233fc4cc 100644 (file)
@@ -303,7 +303,7 @@ function get_rows($query, $connection2 = null, $error = "<p class='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
index 383567625690f6652f21d33d21ddfd00b87d6b50..36fbe557cf59803b6b287eb0700b22bdb697fe9b 100644 (file)
@@ -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) {
index b6dbc59aa7d7548392d63e39ade5ed3735423b33..fdac2a94f216a611677f0aa7089df55671bd54cb 100644 (file)
@@ -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