diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index c48a317d..81068321 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -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; diff --git a/changes.txt b/changes.txt index a5488ed3..3c3f0eac 100644 --- a/changes.txt +++ b/changes.txt @@ -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)