mirror of
https://github.com/vrana/adminer.git
synced 2025-08-12 09:34:10 +02:00
MySQL, MariaDB: Fix default values with ' (fix #895)
This commit is contained in:
@@ -587,15 +587,28 @@ if (!defined('Adminer\DRIVER')) {
|
||||
* @return array [$name => ["field" => , "full_type" => , "type" => , "length" => , "unsigned" => , "default" => , "null" => , "auto_increment" => , "on_update" => , "collation" => , "privileges" => , "comment" => , "primary" => , "generated" => ]]
|
||||
*/
|
||||
function fields($table) {
|
||||
global $connection;
|
||||
$maria = preg_match('~MariaDB~', $connection->server_info);
|
||||
$return = array();
|
||||
foreach (get_rows("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = " . q($table) . " ORDER BY ORDINAL_POSITION") as $row) {
|
||||
$field = $row["COLUMN_NAME"];
|
||||
$default = $row["COLUMN_DEFAULT"];
|
||||
$type = $row["COLUMN_TYPE"];
|
||||
$generation = $row["GENERATION_EXPRESSION"];
|
||||
$extra = $row["EXTRA"];
|
||||
// https://mariadb.com/kb/en/library/show-columns/, https://github.com/vrana/adminer/pull/359#pullrequestreview-276677186
|
||||
preg_match('~^(VIRTUAL|PERSISTENT|STORED)~', $extra, $generated);
|
||||
preg_match('~^([^( ]+)(?:\((.+)\))?( unsigned)?( zerofill)?$~', $type, $match);
|
||||
$default = $row["COLUMN_DEFAULT"];
|
||||
$is_text = preg_match('~text~', $match[1]);
|
||||
if (!$maria && $is_text) {
|
||||
// default value a'b of text column is stored as _utf8mb4\'a\\\'b\' in MySQL
|
||||
$default = preg_replace("~^(_\w+)?('.*')$~", '\2', stripslashes($default));
|
||||
}
|
||||
if ($maria || $is_text) {
|
||||
$default = preg_replace_callback("~^'(.*)'$~", function ($match) {
|
||||
return str_replace("''", "'", stripslashes($match[1]));
|
||||
}, $default);
|
||||
}
|
||||
$return[$field] = array(
|
||||
"field" => $field,
|
||||
"full_type" => $type,
|
||||
@@ -603,11 +616,8 @@ if (!defined('Adminer\DRIVER')) {
|
||||
"length" => $match[2],
|
||||
"unsigned" => ltrim($match[3] . $match[4]),
|
||||
"default" => ($generated
|
||||
? $row["GENERATION_EXPRESSION"]
|
||||
: ($default != "" || preg_match("~char|set~", $match[1])
|
||||
? (preg_match('~text~', $match[1]) ? stripslashes(preg_replace("~^'(.*)'\$~", '\1', $default)) : $default)
|
||||
: null
|
||||
)
|
||||
? ($maria ? $generation : stripslashes($generation))
|
||||
: ($default != "" || preg_match("~char|set~", $match[1]) ? $default : null)
|
||||
),
|
||||
"null" => ($row["IS_NULLABLE"] == "YES"),
|
||||
"auto_increment" => ($extra == "auto_increment"),
|
||||
|
@@ -2,6 +2,7 @@ Adminer dev:
|
||||
Fix gzip export (bug #896)
|
||||
Fix importing multiple SQL files not terminated by semicolon
|
||||
Use <datalist> for altering collations
|
||||
MySQL, MariaDB: Fix default values with ' (bug #895)
|
||||
MariaDB: Fix creating and altering generated columns (bug #897)
|
||||
|
||||
Adminer 5.0.2 (released 2025-03-10):
|
||||
|
Reference in New Issue
Block a user