]> git.joonet.de Git - adminer.git/commitdiff
MySQL: Stop treating enum as set as numbers (bug #475)
authorJakub Vrana <jakub@vrana.cz>
Mon, 10 Mar 2025 22:32:28 +0000 (23:32 +0100)
committerJakub Vrana <jakub@vrana.cz>
Mon, 10 Mar 2025 22:40:07 +0000 (23:40 +0100)
adminer/call.inc.php
adminer/edit.inc.php
adminer/include/functions.inc.php
changes.txt
plugins/enum-option.php

index 1800ee1621a04eb4eecd676a970e1a940437f8ae..b46eccd8820327c6545eedeea8465eec1f453333 100644 (file)
@@ -73,11 +73,8 @@ if ($in) {
                echo "<tr><th>" . $adminer->fieldName($field);
                $value = $_POST["fields"][$name];
                if ($value != "") {
-                       if ($field["type"] == "enum") {
-                               $value = +$value;
-                       }
                        if ($field["type"] == "set") {
-                               $value = array_sum($value);
+                               $value = implode(",", $value);
                        }
                }
                input($field, $value, (string) $_POST["function"][$name]); // param name can be empty
index 7014853517f26bd13a58f0d7c3a0c9e3b8e750b6..07381151232b3e537fc3f9c60abcca9ca50d5b52 100644 (file)
@@ -68,13 +68,7 @@ if ($_POST["save"]) {
        $select = array();
        foreach ($fields as $name => $field) {
                if (isset($field["privileges"]["select"])) {
-                       $as = convert_field($field);
-                       if ($_POST["clone"] && $field["auto_increment"]) {
-                               $as = "''";
-                       }
-                       if (JUSH == "sql" && preg_match("~enum|set~", $field["type"])) {
-                               $as = "1*" . idf_escape($name);
-                       }
+                       $as = ($_POST["clone"] && $field["auto_increment"] ? "''" : convert_field($field));
                        $select[] = ($as ? "$as AS " : "") . idf_escape($name);
                }
        }
index 0dcb1bd13a0cb21ad72c8b86519f2bd7336bccae..fbc086de628c080a72ddb841de721676737be876 100644 (file)
@@ -891,18 +891,18 @@ function column_foreign_keys($table) {
 * @param string "radio"|"checkbox"
 * @param string
 * @param array
-* @param mixed int|string|array
+* @param mixed string|array
 * @param string
 * @return null
 */
 function enum_input($type, $attrs, $field, $value, $empty = null) {
        global $adminer;
        preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches);
-       $return = ($empty !== null ? "<label><input type='$type'$attrs value='$empty'" . ((is_array($value) ? in_array($empty, $value) : $value === 0) ? " checked" : "") . "><i>" . lang('empty') . "</i></label>" : "");
+       $return = ($empty !== null ? "<label><input type='$type'$attrs value='$empty'" . ((is_array($value) ? in_array($empty, $value) : $value === $empty) ? " checked" : "") . "><i>" . lang('empty') . "</i></label>" : "");
        foreach ($matches[1] as $i => $val) {
                $val = stripcslashes(str_replace("''", "'", $val));
-               $checked = (is_int($value) ? $value == $i+1 : (is_array($value) ? in_array($i+1, $value) : $value === $val));
-               $return .= " <label><input type='$type'$attrs value='" . (JUSH == "sql" ? $i+1 : h($val)) . "'" . ($checked ? ' checked' : '') . '>' . h($adminer->editVal($val, $field)) . '</label>';
+               $checked = (is_array($value) ? in_array($val, $value) : $value === $val);
+               $return .= " <label><input type='$type'$attrs value='" . h($val) . "'" . ($checked ? ' checked' : '') . '>' . h($adminer->editVal($val, $field)) . '</label>';
        }
        return $return;
 }
@@ -949,12 +949,12 @@ function input($field, $value, $function) {
                } elseif (preg_match('~bool~', $field["type"])) {
                        echo "<input type='hidden'$attrs value='0'>"
                                . "<input type='checkbox'" . (preg_match('~^(1|t|true|y|yes|on)$~i', $value) ? " checked='checked'" : "") . "$attrs value='1'>";
-               } elseif ($field["type"] == "set") { //! 64 bits
+               } elseif ($field["type"] == "set") {
                        preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches);
                        foreach ($matches[1] as $i => $val) {
                                $val = stripcslashes(str_replace("''", "'", $val));
-                               $checked = (is_int($value) ? ($value >> $i) & 1 : in_array($val, explode(",", $value), true));
-                               echo " <label><input type='checkbox' name='fields[$name][$i]' value='" . (1 << $i) . "'" . ($checked ? ' checked' : '') . ">" . h($adminer->editVal($val, $field)) . '</label>';
+                               $checked = in_array($val, explode(",", $value), true);
+                               echo " <label><input type='checkbox' name='fields[$name][$i]' value='" . h($val) . "'" . ($checked ? ' checked' : '') . ">" . h($adminer->editVal($val, $field)) . '</label>';
                        }
                } elseif (preg_match('~blob|bytea|raw|file~', $field["type"]) && ini_bool("file_uploads")) {
                        echo "<input type='file' name='fields-$name'>";
@@ -1023,9 +1023,6 @@ function process_input($field) {
                        return "NULL";
                }
        }
-       if ($field["type"] == "enum") {
-               return +$value;
-       }
        if ($field["auto_increment"] && $value == "") {
                return null;
        }
@@ -1036,7 +1033,7 @@ function process_input($field) {
                return "NULL";
        }
        if ($field["type"] == "set") {
-               return array_sum((array) $value);
+               $value = implode(",", (array) $value);
        }
        if ($function == "json") {
                $function = "";
@@ -1440,8 +1437,8 @@ function edit_form($table, $fields, $row, $update) {
                                }
                        }
                        $value = ($row !== null
-                               ? ($row[$name] != "" && JUSH == "sql" && preg_match("~enum|set~", $field["type"])
-                                       ? (is_array($row[$name]) ? array_sum($row[$name]) : +$row[$name])
+                               ? ($row[$name] != "" && JUSH == "sql" && preg_match("~enum|set~", $field["type"]) && is_array($row[$name])
+                                       ? implode(",", $row[$name])
                                        : (is_bool($row[$name]) ? +$row[$name] : $row[$name])
                                )
                                : (!$update && $field["auto_increment"]
index a6092a4892af313663122dc8046185a9c0dccf08..410fa9ea3d18b23f5723cb6fe501d91de567739c 100644 (file)
@@ -3,6 +3,7 @@ Fix gzip export (bug #896)
 Fix importing multiple SQL files not terminated by semicolon
 Use <datalist> for altering collations
 MySQL: Allow setting default values of text column
+MySQL: Stop treating enum as set as numbers (bug #475)
 MySQL, MariaDB: Fix default values with ' (bug #895)
 MariaDB: Fix creating and altering generated columns (bug #897)
 
index 7ad0d2132abf42087ee20b2c8a7b3669c995dad7..418561b164f9c14e856492de6d8cbe0aed1534c9 100644 (file)
@@ -20,20 +20,16 @@ class AdminerEnumOption {
                        }
                        if ($field["null"]) {
                                $options[""] = "NULL";
-                               if ($value === null && !isset($_GET["select"])) {
+                               if ($selected === null) {
                                        $selected = "";
                                }
                        }
-                       $options[0] = Adminer\lang('empty');
                        preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches);
-                       foreach ($matches[1] as $i => $val) {
+                       foreach ($matches[1] as $val) {
                                $val = stripcslashes(str_replace("''", "'", $val));
-                               $options[$i + 1] = $val;
-                               if ($value === $val) {
-                                       $selected = $i + 1;
-                               }
+                               $options[$val] = $val;
                        }
-                       return "<select$attrs>" . Adminer\optionlist($options, (string) $selected, 1) . "</select>"; // 1 - use keys
+                       return "<select$attrs>" . Adminer\optionlist($options, $selected, 1) . "</select>"; // 1 - use keys
                }
        }
 }