Make check query for column changes/modifications tolerant
for automatic type changes of text columns, e.g. from TEXT
to MEDIUMTEXT, after conversion from utf8 to utf8mb4, and
fix integer columns without display length for MySQL 8
(see also function "fixInteger" above).
Parameters
- string $type The column type found in the update query
Returns
- string The condition for type check in the check query
Since
/**
* Make check query for column changes/modifications tolerant
* for automatic type changes of text columns, e.g. from TEXT
* to MEDIUMTEXT, after conversion from utf8 to utf8mb4, and
* fix integer columns without display length for MySQL 8
* (see also function "fixInteger" above).
*
* @param string $type The column type found in the update query
*
* @return string The condition for type check in the check query
*
* @since 3.5
*/
private function fixUtf8mb4TypeChecks($type)
{
$uType = strtoupper(str_replace(';', '', $type));
switch ($uType) {
case 'BIGINT UNSIGNED':
case 'INT UNSIGNED':
case 'MEDIUMINT UNSIGNED':
case 'SMALLINT UNSIGNED':
case 'TINYINT UNSIGNED':
// Eg for "INT": "UPPER(type) REGEXP '^INT([(][0-9]+[)])? UNSIGNED$'"
$typeCheck = 'UPPER(type) REGEXP ' . $this->db->quote('^' . str_replace(' ', '([(][0-9]+[)])? ', $uType) . '$');
break;
case 'BIGINT':
case 'INT':
case 'MEDIUMINT':
case 'SMALLINT':
case 'TINYINT':
// Eg for "INT": "UPPER(type) REGEXP '^INT([(][0-9]+[)])?$'"
$typeCheck = 'UPPER(type) REGEXP ' . $this->db->quote('^' . $uType . '([(][0-9]+[)])?$');
break;
case 'MEDIUMTEXT':
$typeCheck = $this->db->hasUTF8mb4Support() ? 'UPPER(type) IN (' . $this->db->quote('MEDIUMTEXT') . ',' . $this->db->quote('LONGTEXT') . ')' : 'UPPER(type) = ' . $this->db->quote('MEDIUMTEXT');
break;
case 'TEXT':
$typeCheck = $this->db->hasUTF8mb4Support() ? 'UPPER(type) IN (' . $this->db->quote('TEXT') . ',' . $this->db->quote('MEDIUMTEXT') . ')' : 'UPPER(type) = ' . $this->db->quote('TEXT');
break;
case 'TINYTEXT':
$typeCheck = $this->db->hasUTF8mb4Support() ? 'UPPER(type) IN (' . $this->db->quote('TINYTEXT') . ',' . $this->db->quote('TEXT') . ')' : 'UPPER(type) = ' . $this->db->quote('TINYTEXT');
break;
default:
$typeCheck = 'UPPER(type) = ' . $this->db->quote($uType);
}
return $typeCheck;
}