]> git.joonet.de Git - adminer.git/commitdiff
PostgreSQL: Fix setting NULL and original value on enum (bug #884)
authorJakub Vrana <jakub@vrana.cz>
Sat, 8 Mar 2025 05:44:12 +0000 (06:44 +0100)
committerJakub Vrana <jakub@vrana.cz>
Sat, 8 Mar 2025 05:44:12 +0000 (06:44 +0100)
adminer/drivers/mysql.inc.php
adminer/drivers/pgsql.inc.php
adminer/include/driver.inc.php
adminer/include/functions.inc.php
changes.txt

index 4a1e71e969335f77aed2fbb43531a3e1ad4a780a..8e2df305d02bebc529d3223c422f4bc5a5894456 100644 (file)
@@ -1159,7 +1159,7 @@ if (!defined('Adminer\DRIVER')) {
 
        /** Convert value in edit after applying functions back
        * @param array one element from fields()
-       * @param string
+       * @param string SQL expression
        * @return string
        */
        function unconvert_field($field, $return) {
index 57875bdc56ed49545ce597217de618dcdee03a5f..1df2040c8053b61a8959515e2fbfd544e2fa6a91 100644 (file)
@@ -234,6 +234,11 @@ if (isset($_GET["pgsql"])) {
                        }
                }
 
+               function enumLength($field) {
+                       $enum = $this->types[lang('User types')][$field["type"]];
+                       return ($enum ? type_values($enum) : "");
+               }
+
                function setUserTypes($types) {
                        $this->types[lang('User types')] = array_flip($types);
                }
index 7e75edacad9d555104e704d6c212c3af0d52b477..2bf48a2559f628301599eef4f65ba9e1f36671c0 100644 (file)
@@ -59,6 +59,13 @@ abstract class SqlDriver {
                return array_map('array_keys', $this->types);
        }
 
+       /** Get enum values
+       * @param array
+       * @return string or null
+       */
+       function enumLength($field) {
+       }
+
        /** Select data from table
        * @param string
        * @param array result of $adminer->selectColumnsProcess()[0]
index e1bd69a0ec41830073aaf22f95c036f5c160795d..e8bedb0792abec7beac7217db328ec57916c0fdf 100644 (file)
@@ -924,14 +924,10 @@ function input($field, $value, $function) {
        $functions = (isset($_GET["select"]) || $reset ? array("orig" => lang('original')) : array()) + $adminer->editFunctions($field);
        $disabled = stripos($field["default"], "GENERATED ALWAYS AS ") === 0 ? " disabled=''" : "";
        $attrs = " name='fields[$name]'$disabled";
-       $types = $driver->types();
-       $structured_types = $driver->structuredTypes();
-       if (in_array($field["type"], (array) $structured_types[lang('User types')])) {
-               $enums = type_values($types[$field["type"]]);
-               if ($enums) {
-                       $field["type"] = "enum";
-                       $field["length"] = $enums;
-               }
+       $enums = $driver->enumLength($field);
+       if ($enums) {
+               $field["type"] = "enum";
+               $field["length"] = $enums;
        }
        if ($field["type"] == "enum") {
                echo h($functions[""]) . "<td>" . $adminer->editInput($_GET["edit"], $field, $attrs, $value);
@@ -970,6 +966,7 @@ function input($field, $value, $function) {
                        echo "<textarea$attrs cols='50' rows='12' class='jush-js'>" . h($value) . '</textarea>';
                } else {
                        // int(3) is only a display hint
+                       $types = $driver->types();
                        $maxlength = (!preg_match('~int~', $field["type"]) && preg_match('~^(\d+)(,(\d+))?$~', $field["length"], $match)
                                ? ((preg_match("~binary~", $field["type"]) ? 2 : 1) * $match[1] + ($match[3] ? 1 : 0) + ($match[2] && !$field["unsigned"] ? 1 : 0))
                                : ($types[$field["type"]] ? $types[$field["type"]] + ($field["unsigned"] ? 0 : 1) : 0)
@@ -1014,13 +1011,15 @@ function process_input($field) {
        $idf = bracket_escape($field["field"]);
        $function = $_POST["function"][$idf];
        $value = $_POST["fields"][$idf];
-       if ($field["type"] == "enum") {
+       if ($field["type"] == "enum" || $driver->enumLength($field)) {
                if ($value == -1) {
                        return false;
                }
                if ($value == "") {
                        return "NULL";
                }
+       }
+       if ($field["type"] == "enum") {
                return +$value;
        }
        if ($field["auto_increment"] && $value == "") {
index 3a3c56e9db2f2e6dc41d89eb34a165f27ed318a0..e664e773150ed8ba6fe2a16fe835a19e549f0d9b 100644 (file)
@@ -1,4 +1,5 @@
 Adminer dev:
+PostgreSQL: Fix setting NULL and original value on enum (bug #884)
 CockroachDB: Add support via PostgreSQL driver
 
 Adminer 5.0.1 (released 2025-03-07):