mirror of
https://github.com/vrana/adminer.git
synced 2025-08-12 09:34:10 +02:00
MySQL: Display generated value in table structure
This commit is contained in:
@@ -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;
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user