]> git.joonet.de Git - adminer.git/commitdiff
MySQL: Display generated value in table structure
authorJakub Vrana <jakub@vrana.cz>
Thu, 6 Mar 2025 20:12:11 +0000 (21:12 +0100)
committerJakub Vrana <jakub@vrana.cz>
Fri, 7 Mar 2025 02:58:33 +0000 (03:58 +0100)
adminer/drivers/mysql.inc.php
changes.txt

index c48a317dead3c99f7821a1c12f56e7940f3d6cb5..81068321a682b093c49a2ddbda2b23a147f0e3f9 100644 (file)
@@ -595,24 +595,34 @@ if (!defined('Adminer\DRIVER')) {
        */
        function fields($table) {
                $return = array();
-               foreach (get_rows("SHOW FULL COLUMNS FROM " . table($table)) as $row) {
-                       preg_match('~^([^( ]+)(?:\((.+)\))?( unsigned)?( zerofill)?$~', $row["Type"], $match);
-                       $return[$row["Field"]] = array(
-                               "field" => $row["Field"],
-                               "full_type" => $row["Type"],
+               foreach (get_rows("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = " . q(DB) . " AND TABLE_NAME = " . q($table) . " ORDER BY ORDINAL_POSITION") as $row) {
+                       $field = $row["COLUMN_NAME"];
+                       $default = $row["COLUMN_DEFAULT"];
+                       $type = $row["COLUMN_TYPE"];
+                       // https://mariadb.com/kb/en/library/show-columns/, https://github.com/vrana/adminer/pull/359#pullrequestreview-276677186
+                       $generated = preg_match('~^(VIRTUAL|PERSISTENT|STORED)~', $row["EXTRA"]);
+                       preg_match('~^([^( ]+)(?:\((.+)\))?( unsigned)?( zerofill)?$~', $type, $match);
+                       $return[$field] = array(
+                               "field" => $field,
+                               "full_type" => $type,
                                "type" => $match[1],
                                "length" => $match[2],
                                "unsigned" => ltrim($match[3] . $match[4]),
-                               "default" => ($row["Default"] != "" || preg_match("~char|set~", $match[1]) ? (preg_match('~text~', $match[1]) ? stripslashes(preg_replace("~^'(.*)'\$~", '\1', $row["Default"])) : $row["Default"]) : null),
-                               "null" => ($row["Null"] == "YES"),
-                               "auto_increment" => ($row["Extra"] == "auto_increment"),
-                               "on_update" => (preg_match('~^on update (.+)~i', $row["Extra"], $match) ? $match[1] : ""), //! available since MySQL 5.1.23
-                               "collation" => $row["Collation"],
-                               "privileges" => array_flip(preg_split('~, *~', $row["Privileges"])),
-                               "comment" => $row["Comment"],
-                               "primary" => ($row["Key"] == "PRI"),
-                               // https://mariadb.com/kb/en/library/show-columns/, https://github.com/vrana/adminer/pull/359#pullrequestreview-276677186
-                               "generated" => preg_match('~^(VIRTUAL|PERSISTENT|STORED)~', $row["Extra"]),
+                               "default" => ($generated
+                                       ? $row["GENERATION_EXPRESSION"]
+                                       : ($default != "" || preg_match("~char|set~", $match[1])
+                                               ? (preg_match('~text~', $match[1]) ? stripslashes(preg_replace("~^'(.*)'\$~", '\1', $default)) : $default)
+                                               : null
+                                       )
+                               ),
+                               "null" => ($row["IS_NULLABLE"] == "YES"),
+                               "auto_increment" => ($row["EXTRA"] == "auto_increment"),
+                               "on_update" => (preg_match('~\bon update (\w+)~i', $row["EXTRA"], $match) ? $match[1] : ""), //! available since MySQL 5.1.23
+                               "collation" => $row["COLLATION_NAME"],
+                               "privileges" => array_flip(explode(",", $row["PRIVILEGES"])),
+                               "comment" => $row["COLUMN_COMMENT"],
+                               "primary" => ($row["COLUMN_KEY"] == "PRI"),
+                               "generated" => $generated,
                        );
                }
                return $return;
index a5488ed32784cd9581e25f7ced93e230380ba287..3c3f0eacafb05c85143a8c8977385dc04510a571 100644 (file)
@@ -2,6 +2,7 @@ Adminer dev:
 Speed up with disabled output buffering
 Don't autofocus computed fields in insert form
 Skip generated columns in multi-edit (bug #882)
+MySQL: Display generated value in table structure
 PostgreSQL: Compute size of all databases (bug #881)
 PostgreSQL: Do not alter indexes with expressions
 PostgreSQL: Fix export of indexes with expressions (bug #768)