Issue 3358; Avoid key length problems when changing collation

This commit is contained in:
Michael 2017-04-20 05:24:08 +00:00
parent d94e930065
commit 2354cc243e
1 changed files with 36 additions and 7 deletions

View File

@ -280,12 +280,11 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
// Compare the field definition // Compare the field definition
$field_definition = $database[$name]["fields"][$fieldname]; $field_definition = $database[$name]["fields"][$fieldname];
// Define the default collation if not given // We change the collation after the indexes had been changed.
if (!isset($parameters['Collation']) AND !is_null($field_definition['Collation'])) { // This is done to avoid index length problems.
$parameters['Collation'] = 'utf8mb4_general_ci'; // So here we always ensure that there is no need to change it.
} else { unset($parameters['Collation']);
$parameters['Collation'] = null; unset($field_definition['Collation']);
}
$current_field_definition = implode(",", $field_definition); $current_field_definition = implode(",", $field_definition);
$new_field_definition = implode(",", $parameters); $new_field_definition = implode(",", $parameters);
@ -342,9 +341,39 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
} }
} }
} }
if ($sql3 != "") {
$sql3 .= "; ";
}
// Now have a look at the field collations
// Compare the field structure field by field
foreach ($structure["fields"] AS $fieldname => $parameters) {
// Compare the field definition
$field_definition = $database[$name]["fields"][$fieldname];
// Define the default collation if not given
if (!isset($parameters['Collation']) AND !is_null($field_definition['Collation'])) {
$parameters['Collation'] = 'utf8mb4_general_ci';
} else {
$parameters['Collation'] = null;
}
if ($field_definition['Collation'] != $parameters['Collation']) {
$sql2 = db_modify_table_field($fieldname, $parameters);
if (($sql3 == "") OR (substr($sql3, -2, 2) == "; ")) {
$sql3 .= "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
} else {
$sql3 .= ", ".$sql2;
}
}
}
} }
if ($sql3 != "") { if ($sql3 != "") {
$sql3 .= ";"; if (substr($sql3, -2, 2) != "; ") {
$sql3 .= ";";
}
if ($verbose) { if ($verbose) {
// Ensure index conversion to unique removes duplicates // Ensure index conversion to unique removes duplicates