Commit 482f9b52 authored by yched's avatar yched

#108094 - fix MySQL5 error on text field creation

parent 0e765dc2
......@@ -471,3 +471,35 @@ function content_update_1005() {
return $ret;
}
/**
* Set text db columns to accept NULL values for mysql (see http://drupal.org/node/108094)
*/
function content_update_1006() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
include_once('./'. drupal_get_path('module', 'content') .'/content.module');
include_once('./'. drupal_get_path('module', 'content') .'/content_admin.inc');
$types = content_types();
$fields = content_fields();
foreach ($fields as $field) {
$db_info = content_database_info($field);
foreach ($db_info['columns'] as $column => $attributes) {
if (in_array($attributes['type'], array('text', 'mediumtext', 'longtext'))) {
content_db_change_column($db_info['table'], $attributes['column'], $attributes['column'], $attributes['type'], $attributes);
$ret[] = array(
'query' => strtr('The text field %field has been updated to accept NULL values.', array('%field' => $field['field_name'])),
'success' => TRUE
);
}
}
}
}
return $ret;
}
......@@ -1337,6 +1337,8 @@ function content_db_add_column($table, $column, $type, $attributes = array()) {
// MySQL allows no DEFAULT value for text (and blob) columns
if (in_array($type, array('text', 'mediumtext', 'longtext'))) {
$default = '';
// We also allow NULL values to account for CCK's per field INSERTs
$not_null = '';
}
db_query('ALTER TABLE {'. $table .'} ADD COLUMN '. $column .' '. $type .' '. $not_null .' '. $default);
break;
......@@ -1437,6 +1439,8 @@ function content_db_change_column($table, $column, $column_new, $type, $attribut
// MySQL allows no DEFAULT value for text (and blob) columns
if (in_array($type, array('text', 'mediumtext', 'longtext'))) {
$default = '';
// We also allow NULL values to account for CCK's per field INSERTs
$not_null = '';
}
db_query('ALTER TABLE {'. $table .'} CHANGE '. $column .' '. $column_new .' '. $type .' '. $not_null .' '. $default);
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment