public static function extractColumnSpec($columnspec)
{
$first_bracket_pos = mb_strpos($columnspec, '(');
if ($first_bracket_pos) {
$spec_in_brackets = chop(mb_substr($columnspec, $first_bracket_pos + 1, mb_strrpos($columnspec, ')') - $first_bracket_pos - 1));
// convert to lowercase just to be sure
$type = mb_strtolower(chop(mb_substr($columnspec, 0, $first_bracket_pos)));
} else {
// Split trailing attributes such as unsigned,
// binary, zerofill and get data type name
$type_parts = explode(' ', $columnspec);
$type = mb_strtolower($type_parts[0]);
$spec_in_brackets = '';
}
if ('enum' == $type || 'set' == $type) {
// Define our working vars
$enum_set_values = self::parseEnumSetValues($columnspec, false);
$printtype = $type . '(' . str_replace("','", "', '", $spec_in_brackets) . ')';
$binary = false;
$unsigned = false;
$zerofill = false;
} else {
$enum_set_values = array();
/* Create printable type name */
$printtype = mb_strtolower($columnspec);
// Strip the "BINARY" attribute, except if we find "BINARY(" because
// this would be a BINARY or VARBINARY column type;
// by the way, a BLOB should not show the BINARY attribute
// because this is not accepted in MySQL syntax.
if (preg_match('@binary@', $printtype) && !preg_match('@binary[\\(]@', $printtype)) {
$printtype = preg_replace('@binary@', '', $printtype);
$binary = true;
} else {
$binary = false;
}
$printtype = preg_replace('@zerofill@', '', $printtype, -1, $zerofill_cnt);
$zerofill = $zerofill_cnt > 0;
$printtype = preg_replace('@unsigned@', '', $printtype, -1, $unsigned_cnt);
$unsigned = $unsigned_cnt > 0;
$printtype = trim($printtype);
}
$attribute = ' ';
if ($binary) {
$attribute = 'BINARY';
}
if ($unsigned) {
$attribute = 'UNSIGNED';
}
if ($zerofill) {
$attribute = 'UNSIGNED ZEROFILL';
}
$can_contain_collation = false;
if (!$binary && preg_match("@^(char|varchar|text|tinytext|mediumtext|longtext|set|enum)@", $type)) {
$can_contain_collation = true;
}
// for the case ENUM('–','“')
$displayed_type = htmlspecialchars($printtype);
if (mb_strlen($printtype) > $GLOBALS['cfg']['LimitChars']) {
$displayed_type = '<abbr title="' . htmlspecialchars($printtype) . '">';
$displayed_type .= htmlspecialchars(mb_substr($printtype, 0, $GLOBALS['cfg']['LimitChars']) . '...');
$displayed_type .= '</abbr>';
}
return array('type' => $type, 'spec_in_brackets' => $spec_in_brackets, 'enum_set_values' => $enum_set_values, 'print_type' => $printtype, 'binary' => $binary, 'unsigned' => $unsigned, 'zerofill' => $zerofill, 'attribute' => $attribute, 'can_contain_collation' => $can_contain_collation, 'displayed_type' => $displayed_type);
}