mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-04 17:21:39 +09:00
Use latin1 charset for ASCII-only columns that need to be short for indexing
This commit is contained in:
parent
9d040e10d7
commit
f751d59708
4 changed files with 24 additions and 13 deletions
|
|
@ -11,7 +11,7 @@ class Column
|
|||
public $type;
|
||||
public $xetype;
|
||||
public $size;
|
||||
public $utf8mb4 = true;
|
||||
public $charset = 'utf8mb4';
|
||||
public $default_value;
|
||||
public $not_null = false;
|
||||
public $is_indexed = false;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class Table
|
|||
foreach ($this->columns as $column)
|
||||
{
|
||||
$columndef = ' `' . $column->name . '`' . ' ' . strtoupper($column->type);
|
||||
$max_size = $column->utf8mb4 ? 191 : 255;
|
||||
$max_size = ($column->charset === 'utf8mb4' && $charset === 'utf8mb4') ? 191 : 255;
|
||||
if (preg_match('/char/i', $column->type) && $column->size > $max_size && ($column->is_unique || $column->is_primary_key))
|
||||
{
|
||||
$adjusted_sizes[$column->name] = $max_size;
|
||||
|
|
@ -42,9 +42,16 @@ class Table
|
|||
{
|
||||
$columndef .= '(' . (isset($adjusted_sizes[$column->name]) ? $adjusted_sizes[$column->name] : $column->size) . ')';
|
||||
}
|
||||
if ($column->utf8mb4 === false && $charset === 'utf8mb4')
|
||||
if ($column->charset !== 'utf8mb4' && $column->charset !== $charset)
|
||||
{
|
||||
$columndef .= ' CHARACTER SET utf8 COLLATE utf8_unicode_ci';
|
||||
if ($column->charset === 'utf8')
|
||||
{
|
||||
$columndef .= ' CHARACTER SET ' . $column->charset . ' COLLATE ' . $column->charset . '_unicode_ci';
|
||||
}
|
||||
else
|
||||
{
|
||||
$columndef .= ' CHARACTER SET ' . $column->charset . ' COLLATE ' . $column->charset . '_general_ci';
|
||||
}
|
||||
}
|
||||
if ($column->not_null)
|
||||
{
|
||||
|
|
@ -84,7 +91,7 @@ class Table
|
|||
{
|
||||
$column_info = $this->columns[$column_name];
|
||||
$current_size = isset($adjusted_sizes[$column_name]) ? $adjusted_sizes[$column_name] : $column_info->size;
|
||||
$max_size = $column_info->utf8mb4 ? 191 : 255;
|
||||
$max_size = ($column_info->charset === 'utf8mb4' && $charset === 'utf8mb4') ? 191 : 255;
|
||||
if (preg_match('/char/i', $column_info->type) && $current_size > $max_size)
|
||||
{
|
||||
$prefix_size = $max_size;
|
||||
|
|
|
|||
|
|
@ -78,10 +78,14 @@ class DBTableParser extends BaseParser
|
|||
// Get all attributes.
|
||||
$attribs = self::_getAttributes($column_info);
|
||||
|
||||
// Get the utf8mb4 attribute.
|
||||
if (isset($attribs['utf8mb4']))
|
||||
// Get the charset/utf8mb4 attribute.
|
||||
if (isset($attribs['charset']))
|
||||
{
|
||||
$column->utf8mb4 = toBool($attribs['utf8mb4']);
|
||||
$column->charset = $attribs['charset'];
|
||||
}
|
||||
elseif (isset($attribs['utf8mb4']))
|
||||
{
|
||||
$column->charset = toBool($attribs['utf8mb4']) ? 'utf8mb4' : 'utf8';
|
||||
}
|
||||
|
||||
// Get the default value.
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<table name="module_trigger">
|
||||
<column name="trigger_name" type="varchar" size="80" notnull="notnull" unique="idx_trigger" utf8mb4="false" />
|
||||
<column name="called_position" type="varchar" size="15" notnull="notnull" unique="idx_trigger" utf8mb4="false" />
|
||||
<column name="module" type="varchar" size="80" notnull="notnull" unique="idx_trigger" utf8mb4="false" />
|
||||
<column name="type" type="varchar" size="15" notnull="notnull" unique="idx_trigger" utf8mb4="false" />
|
||||
<column name="called_method" type="varchar" size="80" notnull="notnull" unique="idx_trigger" utf8mb4="false" />
|
||||
<column name="trigger_name" type="varchar" size="80" notnull="notnull" unique="idx_trigger" charset="latin1" />
|
||||
<column name="called_position" type="varchar" size="20" notnull="notnull" unique="idx_trigger" charset="latin1" />
|
||||
<column name="module" type="varchar" size="80" notnull="notnull" unique="idx_trigger" charset="latin1" />
|
||||
<column name="type" type="varchar" size="80" notnull="notnull" unique="idx_trigger" charset="latin1" />
|
||||
<column name="called_method" type="varchar" size="80" notnull="notnull" unique="idx_trigger" charset="latin1" />
|
||||
</table>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue