mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 02:28:44 +02:00
N°2490 MariaDB compat : changes after code review
* DEFAULT value unquoting is done with preg_replace now (clearer that we want to do a string replacement) * DEFAULT value unquoting works even if DEFAULT is not the last keyword * change test datasource for more readability (use double quotes when needed)
This commit is contained in:
@@ -1168,14 +1168,19 @@ class CMDBSource
|
||||
$sDbFieldOtherOptions = substr($sDbFieldOtherOptions, 0, -strlen($sMariaDbDefaultNull));
|
||||
}
|
||||
// remove quotes around default values (always present in MariaDB)
|
||||
if (preg_match('/ DEFAULT \'([^\']+)\'$/', $sDbFieldOtherOptions, $aMatches) === 1)
|
||||
{
|
||||
if (($sItopFieldDataType !== 'ENUM') && is_numeric($aMatches[1]))
|
||||
{
|
||||
$sDbFieldOtherOptions = substr($sDbFieldOtherOptions, 0, -(strlen($aMatches[1]) + 2))
|
||||
.$aMatches[1];
|
||||
}
|
||||
}
|
||||
$sDbFieldOtherOptions = preg_replace_callback(
|
||||
'/( DEFAULT )\'([^\']+)\'/',
|
||||
function ($aMatches) use ($sItopFieldDataType) {
|
||||
// ENUM default values should keep quotes, but all other numeric values don't have quotes
|
||||
if (is_numeric($aMatches[2]) && ($sItopFieldDataType !== 'ENUM'))
|
||||
{
|
||||
return $aMatches[1].$aMatches[2];
|
||||
}
|
||||
|
||||
return $aMatches[0];
|
||||
},
|
||||
$sDbFieldOtherOptions);
|
||||
|
||||
if (strcasecmp($sItopFieldOtherOptions, $sDbFieldOtherOptions) !== 0)
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -48,53 +48,58 @@ class CMDBSourceTest extends ItopTestCase
|
||||
'same int declaration, different case on data type' => array(true, 'INT(11)', 'int(11)'),
|
||||
'same enum declaration, same case' => array(
|
||||
true,
|
||||
'ENUM(\'error\',\'idle\',\'planned\',\'running\')',
|
||||
'ENUM(\'error\',\'idle\',\'planned\',\'running\')',
|
||||
"ENUM('error','idle','planned','running')",
|
||||
"ENUM('error','idle','planned','running')",
|
||||
),
|
||||
'same enum declaration, different case on data type' => array(
|
||||
true,
|
||||
'ENUM(\'error\',\'idle\',\'planned\',\'running\')',
|
||||
'enum(\'error\',\'idle\',\'planned\',\'running\')',
|
||||
"ENUM('error','idle','planned','running')",
|
||||
"enum('error','idle','planned','running')",
|
||||
),
|
||||
'same enum declaration, different case on type options' => array(
|
||||
false,
|
||||
'ENUM(\'ERROR\',\'IDLE\',\'planned\',\'running\')',
|
||||
'ENUM(\'error\',\'idle\',\'planned\',\'running\')',
|
||||
"ENUM('ERROR','IDLE','planned','running')",
|
||||
"ENUM('error','idle','planned','running')",
|
||||
),
|
||||
'same enum declaration, different case on both data type and type options' => array(
|
||||
false,
|
||||
'ENUM(\'ERROR\',\'IDLE\',\'planned\',\'running\')',
|
||||
'enum(\'error\',\'idle\',\'planned\',\'running\')',
|
||||
"ENUM('ERROR','IDLE','planned','running')",
|
||||
"enum('error','idle','planned','running')",
|
||||
),
|
||||
'MariaDB 10.2 nullable datetime' => array(
|
||||
true,
|
||||
'DATETIME',
|
||||
'datetime DEFAULT \'NULL\'',
|
||||
"datetime DEFAULT 'NULL'",
|
||||
),
|
||||
'MariaDB 10.2 nullable text' => array(
|
||||
true,
|
||||
'TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci',
|
||||
'text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT \'NULL\'',
|
||||
"text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT 'NULL'",
|
||||
),
|
||||
'MariaDB 10.2 nullable unsigned int' => array(
|
||||
true,
|
||||
'INT(11) UNSIGNED',
|
||||
'int(11) unsigned DEFAULT \'NULL\'',
|
||||
"int(11) unsigned DEFAULT 'NULL'",
|
||||
),
|
||||
'MariaDB 10.2 varchar with default value' => array(
|
||||
true,
|
||||
'VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT 0',
|
||||
'varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT \'0\'',
|
||||
"varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '0'",
|
||||
),
|
||||
'varchar with default value not at the end' => array(
|
||||
true,
|
||||
"VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT 0 COMMENT 'my comment'",
|
||||
"varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '0' COMMENT 'my comment'",
|
||||
),
|
||||
'MariaDB 10.2 Enum with string default value' => array(
|
||||
true,
|
||||
'ENUM(\'error\',\'idle\',\'planned\',\'running\') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT \'planned\'',
|
||||
'enum(\'error\',\'idle\',\'planned\',\'running\') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT \'planned\'',
|
||||
"ENUM('error','idle','planned','running') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT 'planned'",
|
||||
"enum('error','idle','planned','running') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT 'planned'",
|
||||
),
|
||||
'MariaDB 10.2 Enum with numeric default value' => array(
|
||||
true,
|
||||
'ENUM(\'1\',\'2\',\'3\') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT \'1\'',
|
||||
'enum(\'1\',\'2\',\'3\') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT \'1\'',
|
||||
"ENUM('1','2','3') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '1'",
|
||||
"enum('1','2','3') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '1'",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user