From e427ad302f86f07f328faa0d2156929e64dedba7 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Mon, 23 Apr 2012 20:50:16 +0200 Subject: [PATCH] MDL-32595 fix mysql int and lob defaults during conversion Integer columns can not have empty string default, lobs fields handle empty strings defaults automatically too if null not allowed. --- lib/db/upgradelib.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/db/upgradelib.php b/lib/db/upgradelib.php index 7696d06d22f..e0fb4210df4 100644 --- a/lib/db/upgradelib.php +++ b/lib/db/upgradelib.php @@ -70,7 +70,7 @@ function upgrade_mysql_fix_unsigned_columns() { if (stripos($column->type, 'unsigned') !== false) { $type = preg_replace('/unsigned/i', 'signed', $column->type); $notnull = ($column->null === 'NO') ? 'NOT NULL' : 'NULL'; - $default = !is_null($column->default) ? "DEFAULT '$column->default'" : ''; + $default = (!is_null($column->default) and $column->default !== '') ? "DEFAULT '$column->default'" : ''; $autoinc = (stripos($column->extra, 'auto_increment') !== false) ? 'AUTO_INCREMENT' : ''; // primary and unique not necessary here, change_database_structure does not add prefix $sql = "ALTER TABLE `{$prefix}$table` MODIFY COLUMN `$column->field` $type $notnull $default $autoinc"; @@ -118,14 +118,14 @@ function upgrade_mysql_fix_lob_columns() { $column = (object)array_change_key_case((array)$column, CASE_LOWER); if ($column->type === 'tinytext' or $column->type === 'mediumtext' or $column->type === 'text') { $notnull = ($column->null === 'NO') ? 'NOT NULL' : 'NULL'; - $default = !is_null($column->default) ? "DEFAULT '$column->default'" : ''; + $default = (!is_null($column->default) and $column->default !== '') ? "DEFAULT '$column->default'" : ''; // primary, unique and inc are not supported for texts $sql = "ALTER TABLE `{$prefix}$table` MODIFY COLUMN `$column->field` LONGTEXT $notnull $default"; $DB->change_database_structure($sql); } if ($column->type === 'tinyblob' or $column->type === 'mediumblob' or $column->type === 'blob') { $notnull = ($column->null === 'NO') ? 'NOT NULL' : 'NULL'; - $default = !is_null($column->default) ? "DEFAULT '$column->default'" : ''; + $default = (!is_null($column->default) and $column->default !== '') ? "DEFAULT '$column->default'" : ''; // primary, unique and inc are not supported for blobs $sql = "ALTER TABLE `{$prefix}$table` MODIFY COLUMN `$column->field` LONGBLOB $notnull $default"; $DB->change_database_structure($sql);