mirror of
https://github.com/vrana/adminer.git
synced 2025-08-13 18:14:07 +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) {
|
function fields($table) {
|
||||||
$return = array();
|
$return = array();
|
||||||
foreach (get_rows("SHOW FULL COLUMNS FROM " . table($table)) as $row) {
|
foreach (get_rows("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = " . q(DB) . " AND TABLE_NAME = " . q($table) . " ORDER BY ORDINAL_POSITION") as $row) {
|
||||||
preg_match('~^([^( ]+)(?:\((.+)\))?( unsigned)?( zerofill)?$~', $row["Type"], $match);
|
$field = $row["COLUMN_NAME"];
|
||||||
$return[$row["Field"]] = array(
|
$default = $row["COLUMN_DEFAULT"];
|
||||||
"field" => $row["Field"],
|
$type = $row["COLUMN_TYPE"];
|
||||||
"full_type" => $row["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],
|
"type" => $match[1],
|
||||||
"length" => $match[2],
|
"length" => $match[2],
|
||||||
"unsigned" => ltrim($match[3] . $match[4]),
|
"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),
|
"default" => ($generated
|
||||||
"null" => ($row["Null"] == "YES"),
|
? $row["GENERATION_EXPRESSION"]
|
||||||
"auto_increment" => ($row["Extra"] == "auto_increment"),
|
: ($default != "" || preg_match("~char|set~", $match[1])
|
||||||
"on_update" => (preg_match('~^on update (.+)~i', $row["Extra"], $match) ? $match[1] : ""), //! available since MySQL 5.1.23
|
? (preg_match('~text~', $match[1]) ? stripslashes(preg_replace("~^'(.*)'\$~", '\1', $default)) : $default)
|
||||||
"collation" => $row["Collation"],
|
: null
|
||||||
"privileges" => array_flip(preg_split('~, *~', $row["Privileges"])),
|
)
|
||||||
"comment" => $row["Comment"],
|
),
|
||||||
"primary" => ($row["Key"] == "PRI"),
|
"null" => ($row["IS_NULLABLE"] == "YES"),
|
||||||
// https://mariadb.com/kb/en/library/show-columns/, https://github.com/vrana/adminer/pull/359#pullrequestreview-276677186
|
"auto_increment" => ($row["EXTRA"] == "auto_increment"),
|
||||||
"generated" => preg_match('~^(VIRTUAL|PERSISTENT|STORED)~', $row["Extra"]),
|
"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;
|
return $return;
|
||||||
|
@@ -2,6 +2,7 @@ Adminer dev:
|
|||||||
Speed up with disabled output buffering
|
Speed up with disabled output buffering
|
||||||
Don't autofocus computed fields in insert form
|
Don't autofocus computed fields in insert form
|
||||||
Skip generated columns in multi-edit (bug #882)
|
Skip generated columns in multi-edit (bug #882)
|
||||||
|
MySQL: Display generated value in table structure
|
||||||
PostgreSQL: Compute size of all databases (bug #881)
|
PostgreSQL: Compute size of all databases (bug #881)
|
||||||
PostgreSQL: Do not alter indexes with expressions
|
PostgreSQL: Do not alter indexes with expressions
|
||||||
PostgreSQL: Fix export of indexes with expressions (bug #768)
|
PostgreSQL: Fix export of indexes with expressions (bug #768)
|
||||||
|
Reference in New Issue
Block a user