summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <dlenev@mysql.com>2004-01-30 15:13:19 +0300
committerunknown <dlenev@mysql.com>2004-01-30 15:13:19 +0300
commita96ffb29258a80f8dfaa11f336d0edaa23ad6cf6 (patch)
treedb761ccd5b1911fe821d56d893c00a18741a4abe /sql
parentc9f4333897e2eb9b5bacaf794ee3a65e43286606 (diff)
downloadmariadb-git-a96ffb29258a80f8dfaa11f336d0edaa23ad6cf6.tar.gz
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.
Diffstat (limited to 'sql')
-rw-r--r--sql/field.cc3
-rw-r--r--sql/field.h5
-rw-r--r--sql/sql_parse.cc12
-rw-r--r--sql/sql_show.cc14
4 files changed, 23 insertions, 11 deletions
diff --git a/sql/field.cc b/sql/field.cc
index 8bcbf8ecc56..687c22bb69b 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -5124,8 +5124,7 @@ create_field::create_field(Field *old_field,Field *orig_field)
interval=0;
def=0;
if (!old_field->is_real_null() && ! (flags & BLOB_FLAG) &&
- old_field->type() != FIELD_TYPE_TIMESTAMP && old_field->ptr &&
- orig_field)
+ old_field->ptr && orig_field)
{
char buff[MAX_FIELD_WIDTH],*pos;
String tmp(buff,sizeof(buff));
diff --git a/sql/field.h b/sql/field.h
index 413a08f08d4..6f049e3809e 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -564,7 +564,10 @@ public:
void set_time();
virtual void set_default()
{
- set_time();
+ if (table->timestamp_field == this)
+ set_time();
+ else
+ Field::set_default();
}
inline long get_timestamp()
{
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 608cdd23282..69257913b5b 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -3056,12 +3056,12 @@ bool add_field_to_list(char *field_name, enum_field_types type,
if (default_value)
{
- if (type == FIELD_TYPE_TIMESTAMP)
- {
- net_printf(&thd->net, ER_INVALID_DEFAULT, field_name);
- DBUG_RETURN(1);
- }
- else if (default_value->type() == Item::NULL_ITEM)
+ /*
+ We allow specifying value for first TIMESTAMP column
+ altough it is silently ignored. This should be fixed in 4.1
+ (by proper warning or real support for default values)
+ */
+ if (default_value->type() == Item::NULL_ITEM)
{
default_value=0;
if ((type_modifier & (NOT_NULL_FLAG | AUTO_INCREMENT_FLAG)) ==
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index d34e2e68067..1aca352a894 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -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);