diff --git a/adminer/create.inc.php b/adminer/create.inc.php index 7d355ba01..bcc8b48aa 100644 --- a/adminer/create.inc.php +++ b/adminer/create.inc.php @@ -44,6 +44,12 @@ if ($field["field"] != "") { if (!$field["has_default"]) { $field["default"] = null; + } elseif (in_array($field["has_default"], array('STORED', 'VIRTUAL'))) { + $field["default"] = "GENERATED ALWAYS AS ($field[default]) $field[has_default]"; + $field["collation"] = null; + } elseif (in_array($orig_field["has_default"], array('STORED', 'VIRTUAL'))) { + $orig_field["default"] = "GENERATED ALWAYS AS ($orig_field[default]) $orig_field[virtual]"; + $orig_field["collation"] = null; } if ($key == $row["auto_increment_col"]) { $field["auto_increment"] = true; @@ -132,7 +138,7 @@ $row["Auto_increment"] = ""; } foreach ($orig_fields as $field) { - $field["has_default"] = isset($field["default"]); + $field["has_default"] = isset($field["has_default"]) ? $field["has_default"] : $field["default"]; $row["fields"][] = $field; } diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index 82ea8fc10..0f9e1bee0 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -535,23 +535,30 @@ function fk_support($table_status) { */ 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"], + $rows = get_rows("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = " . q($table)); + + foreach ($rows as $row) { + preg_match('~^([^( ]+)(?:\((.+)\))?( unsigned)?( zerofill)?$~', $row["COLUMN_TYPE"], $match); + $return[$row["COLUMN_NAME"]] = array( + "field" => $row["COLUMN_NAME"], + "full_type" => $row["COLUMN_TYPE"], "type" => $match[1], "length" => $match[2], "unsigned" => ltrim($match[3] . $match[4]), - "default" => ($row["Default"] != "" || preg_match("~char|set~", $match[1]) ? $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"), + "default" => ($row["COLUMN_DEFAULT"] != "" || preg_match("~char|set~", $match[1])) ? trim($row["COLUMN_DEFAULT"], "'") : null, // COLUMN_DEFAULT => "'my_value'" + "null" => ($row["IS_NULLABLE"] == "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_NAME"], + "privileges" => array_flip(preg_split('~, *~', $row["PRIVILEGES"])), + "comment" => $row["COLUMN_COMMENT"], + "primary" => ($row["COLUMN_KEY"] == "PRI") ); + + if ($virtual = $row["EXTRA"] == "STORED GENERATED" ? 'STORED' : ($row["EXTRA"] == "VIRTUAL GENERATED" ? 'VIRTUAL' : false)) { + $return[$row["COLUMN_NAME"]]["has_default"] = $virtual; + $return[$row["COLUMN_NAME"]]["default"] = isset($row['GENERATION_EXPRESSION']) ? $row['GENERATION_EXPRESSION'] : null; + } } return $return; } diff --git a/adminer/edit.inc.php b/adminer/edit.inc.php index a62831617..6209c34cb 100644 --- a/adminer/edit.inc.php +++ b/adminer/edit.inc.php @@ -7,6 +7,9 @@ if (!isset($field["privileges"][$update ? "update" : "insert"]) || $adminer->fieldName($field) == "") { unset($fields[$name]); } + if (in_array($field["has_default"], array('STORED', 'VIRTUAL'))) { + unset($fields[$name]); + } } if ($_POST && !$error && !isset($_GET["select"])) { diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index 11fe6bfaf..e3c336ad5 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -811,6 +811,12 @@ function dumpData($table, $style, $query) { echo truncate_sql($table) . ";\n"; } $fields = fields($table); + foreach ($fields as $name => $field) { + //exclude virtual columns + if (in_array($field["has_default"], array('STORED', 'VIRTUAL'))) { + $fields[$name] = false; + } + } } $result = $connection->query($query, 1); // 1 - MYSQLI_USE_RESULT //! enum and set as numbers if ($result) { @@ -824,6 +830,12 @@ function dumpData($table, $style, $query) { $values = array(); foreach ($row as $val) { $field = $result->fetch_field(); + if ($_POST["format"] == "sql") { + //skip virtual columns + if (!$fields[$field->name]) { + continue; + } + } $keys[] = $field->name; $key = idf_escape($field->name); $values[] = "$key = VALUES($key)"; @@ -842,6 +854,11 @@ function dumpData($table, $style, $query) { } foreach ($row as $key => $val) { $field = $fields[$key]; + //skip virtual columns + if (!$field) { + unset($row[$key]); + continue; + } $row[$key] = ($val !== null ? unconvert_field($field, preg_match(number_type(), $field["type"]) && $val != '' ? $val : q(($val === false ? 0 : $val))) : "NULL" diff --git a/adminer/include/editing.inc.php b/adminer/include/editing.inc.php index 405efdb59..4825d3a05 100644 --- a/adminer/include/editing.inc.php +++ b/adminer/include/editing.inc.php @@ -193,6 +193,15 @@ function process_type($field, $collate = "COLLATE") { * @return array array("field", "type", "NULL", "DEFAULT", "ON UPDATE", "COMMENT", "AUTO_INCREMENT") */ function process_field($field, $type_field) { + if (in_array($field["has_default"], array('STORED', 'VIRTUAL'))) { + return array( + idf_escape(trim($field["field"])), + process_type($field), + " $field[default]", + (support("comment") && $field["comment"] != "" ? " COMMENT " . q($field["comment"]) : ""), + ); + } + return array( idf_escape(trim($field["field"])), process_type($type_field), @@ -239,7 +248,7 @@ function type_class($type) { * @return null */ function edit_fields($fields, $collations, $type = "TABLE", $foreign_keys = array(), $comments = false) { - global $inout; + global $inout, $jush; $fields = array_values($fields); ?> @@ -277,8 +286,17 @@ function edit_fields($fields, $collations, $type = "TABLE", $foreign_keys = arra -" aria-labelledby="label-default"> +" aria-labelledby="label-default">" : ""); } echo ""; diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 4a7bd6a4a..9c7f48a6c 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -1422,6 +1422,9 @@ function edit_form($TABLE, $fields, $row, $update) { echo "" . script("qsl('table').onkeydown = editingKeydown;"); foreach ($fields as $name => $field) { + if (in_array($field["has_default"], array('STORED', 'VIRTUAL'))) { + continue; + } echo "
" . $adminer->fieldName($field); $default = $_GET["set"][bracket_escape($name)]; if ($default === null) {