Issue moved from calendar module: http://drupal.org/node/293759

Because I found this problem while using the calendar and could not reproduce this problem with a normal views with date fields, I thought it was a problem with the calendar.
I now think this problem has more to do with the date module than the calendar.

The problem is that mySQL concat does not support any fields being concatenated being null. Concat is used in the date_sql_concat() function.

The only 2 place I can find that it is being used is date_views.inc and calendar.inc.

http://dev.mysql.com/doc/refman/5.0/en/problems-with-null.html

Comments

NaX’s picture

Status: Active » Needs review

I think the best way and simplest way to solve this problem is to change the database columns to have a default value of an empty string. This way we avoid NULL values.

The easiest way to create NULL values for value2 is to create a date with a To field optional or required, then create a few nodes, then remove the To field, then put the To field back. Then try to use the calendar module.

Because the database column value2 gets created then dropped then created again all nodes will have NULL values for value2.

Since this is all just as simple as editing the field’s settings this could be a very likely scenario while developing a new site without a clear plan, I believe it to be quite serious.

Please not that I have not been able to test my theory yet. I also do not now if there are any repercussions to changing the fields to not allow nulls.

From: (/date/date/date_admin.inc)

/**
 *  Callback for field columns.
 */
function date_columns($field) {
  if ($field['type'] == 'date') {
    $db_columns['value'] = array('type' => 'varchar', 'length' => 20, 'not null' => FALSE, 'sortable' => TRUE);
  }
  
  ...
}

To:

/**
 *  Callback for field columns.
 */
function date_columns($field) {
  if ($field['type'] == 'date') {
    $db_columns['value'] = array('type' => 'varchar', 'length' => 20, 'not null' => TRUE, 'default' => "''", 'sortable' => TRUE);
  }
  
  ...
}
karens’s picture

No, all CCK columns must default to NULL so the content module can set them to empty in a way that will always work for all field types. This is not required in the D5 version, but is required in D6 and I'm starting it now so the D5 and D6 versions will work the same.

We also need a cross-database solution, we can't use things that only work in MYSQL. I'm thinking we might be able to wrap a CAST() around each value to cast it to a string before the concat. I suspect a method like that could work reasonably the same in different databases.

The other solution is to get rid of the concat code altogether and do the from/to date processing differently.

I need to think about this.

karens’s picture

Status: Needs review » Fixed

OK, 'COALESCE' is our magic bullet here. It works the same in MYSQL and PostgreSQL, and it works in all versions of MYSQL. We can pass in an array of possible values and it will return the first non-NULL option.

I'm committing this fix.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.