Permalink
Browse files

Type aliases in routine

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@341 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent 35cc8e8 commit 9fa3b9de664301e742c373f74564cf59cd359131 jakubvrana committed Aug 16, 2007
Showing with 4 additions and 2 deletions.
  1. +4 −2 editing.inc.php
View
@@ -172,16 +172,18 @@ function normalize_enum($match) {
function routine($name, $type) {
global $mysql, $enum_length, $inout;
- $type_pattern = "([a-z]+)(?:\\s*\\(((?:[^'\")]*|$enum_length)+)\\))?\\s*(zerofill\\s*)?(unsigned(?:\\s+zerofill)?)?(?:\\s*(?:CHARSET|CHARACTER\\s+SET)\\s*['\"]?([^'\"\\s]+)['\"]?)?";
+ $aliases = array("bit" => "tinyint", "bool" => "tinyint", "boolean" => "tinyint", "integer" => "int", "double precision" => "float", "real" => "float", "dec" => "decimal", "numeric" => "decimal", "fixed" => "decimal", "national char" => "char", "national varchar" => "varchar");
+ $type_pattern = "([ a-z]+)(?:\\s*\\(((?:[^'\")]*|$enum_length)+)\\))?\\s*(zerofill\\s*)?(unsigned(?:\\s+zerofill)?)?(?:\\s*(?:CHARSET|CHARACTER\\s+SET)\\s*['\"]?([^'\"\\s]+)['\"]?)?";
$pattern = "\\s*(" . ($type == "FUNCTION" ? "" : implode("|", $inout)) . ")?\\s*(?:`((?:[^`]+|``)*)`\\s*|\\b(\\S+)\\s+)$type_pattern";
$create = $mysql->result($mysql->query("SHOW CREATE $type " . idf_escape($name)), 2);
preg_match("~\\(((?:$pattern\\s*,?)*)\\)" . ($type == "FUNCTION" ? "\\s*RETURNS\\s+$type_pattern" : "") . "\\s*(.*)~is", $create, $match);
$fields = array();
preg_match_all("~$pattern\\s*,?~is", $match[1], $matches, PREG_SET_ORDER);
foreach ($matches as $i => $param) {
+ $data_type = strtolower($param[4]);
$fields[$i] = array(
"field" => str_replace("``", "`", $param[2]) . $param[3],
- "type" => strtolower($param[4]), //! type aliases
+ "type" => (isset($aliases[$data_type]) ? $aliases[$data_type] : $data_type),
"length" => preg_replace_callback("~$enum_length~s", 'normalize_enum', $param[5]),
"unsigned" => strtolower(preg_replace('~\\s+~', ' ', trim("$param[7] $param[6]"))),
"inout" => strtoupper($param[1]),

0 comments on commit 9fa3b9d

Please sign in to comment.