From: Matthias Schmidt Date: Sun, 11 Aug 2019 10:19:21 +0000 (+0200) Subject: Support enum and double columns in MysqlDatabaseEditor::getColumns() X-Git-Tag: 5.2.0_Alpha_4~10 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=4d2bd2ece11133caeac77b6914de12a46c54cfa7;p=GitHub%2FWoltLab%2FWCF.git Support enum and double columns in MysqlDatabaseEditor::getColumns() Close #3011 --- diff --git a/wcfsetup/install/files/lib/system/database/editor/MySQLDatabaseEditor.class.php b/wcfsetup/install/files/lib/system/database/editor/MySQLDatabaseEditor.class.php index 80b2cf98bc..5779a23b5b 100644 --- a/wcfsetup/install/files/lib/system/database/editor/MySQLDatabaseEditor.class.php +++ b/wcfsetup/install/files/lib/system/database/editor/MySQLDatabaseEditor.class.php @@ -30,7 +30,7 @@ class MySQLDatabaseEditor extends DatabaseEditor { */ public function getColumns($tableName) { $columns = []; - $regex = new Regex('([a-z]+)\(([0-9]+)\)', Regex::CASE_INSENSITIVE); + $regex = new Regex('([a-z]+)\((.+)\)', Regex::CASE_INSENSITIVE); $sql = "SHOW COLUMNS FROM `".$tableName."`"; $statement = $this->dbObj->prepareStatement($sql); @@ -39,13 +39,52 @@ class MySQLDatabaseEditor extends DatabaseEditor { $regex->match($row['Type']); $typeMatches = $regex->getMatches(); + $type = $row['Type']; + $length = ''; + $decimals = ''; + $enumValues = ''; + if (!empty($typeMatches)) { + $type = $typeMatches[1]; + + switch ($type) { + case 'enum': + case 'set': + $enumValues = $typeMatches[2]; + break; + + case 'decimal': + case 'double': + case 'float': + $pieces = explode(',', $typeMatches[2]); + switch (count($pieces)) { + case 1: + $length = $pieces[0]; + break; + + case 2: + list($length, $decimals) = $pieces; + break; + } + + break; + + default: + if ($typeMatches[2] == (int)$typeMatches[2]) { + $length = $typeMatches[2]; + } + break; + } + } + $columns[] = ['name' => $row['Field'], 'data' => [ - 'type' => empty($typeMatches) ? $row['Type'] : $typeMatches[1], - 'length' => empty($typeMatches) ? '' : $typeMatches[2], - 'notNull' => ($row['Null'] == 'YES') ? false : true, + 'type' => $type, + 'length' => $length, + 'notNull' => $row['Null'] == 'YES' ? false : true, 'key' => ($row['Key'] == 'PRI') ? 'PRIMARY' : (($row['Key'] == 'UNI') ? 'UNIQUE' : ''), 'default' => $row['Default'], - 'autoIncrement' => $row['Extra'] == 'auto_increment' ? true : false + 'autoIncrement' => $row['Extra'] == 'auto_increment' ? true : false, + 'enumValues' => $enumValues, + 'decimals' => $decimals ]]; }