1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

Fix for bugs #1885, #2464, #2539. Proper handling of default

values for TIMESTAMP columns. The solution is not perfect since
we just silently ignoring default value for first TIMESTAMP 
column and properly reflecting this fact in SHOW CREATE TABLE.
We can't give a warning or simply support standard syntax 
(niladic functions as legal value for default) for first field 
since it is 4.0 tree.


mysql-test/r/type_timestamp.result:
  Added test for bugs #1885, #2464, #2539
  (proper support of default values for TIMESTAMP columns)
mysql-test/t/type_timestamp.test:
  Added test for bugs #1885, #2464, #2539
  (proper support of default values for TIMESTAMP columns)
sql/field.cc:
  Enabled copying of defaults for TIMESTAMP fields when we are 
  creating table with CREATE TABLE x (SELECT ...)
sql/field.h:
  Set proper DEFAULT value for non-first TIMESTAMP column.
sql/sql_parse.cc:
  Allowed default values for TIMESTAMP column.
sql/sql_show.cc:
  Enabled printing of default values in SHOW CREATE TABLE and 
  SHOW COLUMNS for all TIMESTAMP columns except first one.
This commit is contained in:
unknown
2004-01-30 15:13:19 +03:00
parent c9f4333897
commit a96ffb2925
6 changed files with 98 additions and 16 deletions

View File

@ -508,6 +508,12 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild,
field->sql_type(type);
net_store_data(packet,convert,type.ptr(),type.length());
/*
Altough TIMESTAMP fields can't contain NULL as its value they
will accept NULL if you will try to insert such value and will
convert it to current TIMESTAMP. So YES here means that NULL
is allowed for assignment but can't be returned.
*/
pos=(byte*) ((flags & NOT_NULL_FLAG) &&
field->type() != FIELD_TYPE_TIMESTAMP ?
"" : "YES");
@ -517,7 +523,11 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild,
(field->flags & MULTIPLE_KEY_FLAG) ? "MUL":"");
net_store_data(packet,convert,(char*) pos);
if (field->type() == FIELD_TYPE_TIMESTAMP ||
/*
We handle first TIMESTAMP column in special way because its
default value is ignored and current timestamp used instead.
*/
if (table->timestamp_field == field ||
field->unireg_check == Field::NEXT_NUMBER)
null_default_value=1;
if (!null_default_value && !field->is_null())
@ -888,7 +898,7 @@ store_create_info(THD *thd, TABLE *table, String *packet)
packet->append(type.ptr(),type.length());
has_default= (field->type() != FIELD_TYPE_BLOB &&
field->type() != FIELD_TYPE_TIMESTAMP &&
table->timestamp_field != field &&
field->unireg_check != Field::NEXT_NUMBER);
if (flags & NOT_NULL_FLAG)
packet->append(" NOT NULL", 9);