mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
A patch for Bug#18834: ALTER TABLE ADD INDEX on table with
two timestamp fields. The actual problem here was that CREATE TABLE allowed zero date as a default value for a TIMESTAMP column in NO_ZERO_DATE mode. The thing is that for TIMESTAMP date type specific rule is applied: column_name TIMESTAMP == column_name TIMESTAMP DEFAULT 0 whever for any other date data type column_name TYPE == column_name TYPE DEFAULT NULL The fix is to raise an error when we're in NO_ZERO_DATE mode and there is TIMESTAMP column w/o default value.
This commit is contained in:
@ -3001,6 +3001,37 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
|
||||
(qsort_cmp) sort_keys);
|
||||
create_info->null_bits= null_fields;
|
||||
|
||||
/* Check fields. */
|
||||
it.rewind();
|
||||
while ((sql_field=it++))
|
||||
{
|
||||
Field::utype type= (Field::utype) MTYP_TYPENR(sql_field->unireg_check);
|
||||
|
||||
if (thd->variables.sql_mode & MODE_NO_ZERO_DATE &&
|
||||
!sql_field->def &&
|
||||
sql_field->sql_type == MYSQL_TYPE_TIMESTAMP &&
|
||||
(sql_field->flags & NOT_NULL_FLAG) &&
|
||||
(type == Field::NONE || type == Field::TIMESTAMP_UN_FIELD))
|
||||
{
|
||||
/*
|
||||
An error should be reported if:
|
||||
- NO_ZERO_DATE SQL mode is active;
|
||||
- there is no explicit DEFAULT clause (default column value);
|
||||
- this is a TIMESTAMP column;
|
||||
- the column is not NULL;
|
||||
- this is not the DEFAULT CURRENT_TIMESTAMP column.
|
||||
|
||||
In other words, an error should be reported if
|
||||
- NO_ZERO_DATE SQL mode is active;
|
||||
- the column definition is equivalent to
|
||||
'column_name TIMESTAMP DEFAULT 0'.
|
||||
*/
|
||||
|
||||
my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
DBUG_RETURN(FALSE);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user