#At file:///home/martin/bzrroot/wl5874/mysql-trunk-hackish/ based on revid:marko.makela@strippedgq5gwkdq2py6aaos
3239 Martin Hansson 2011-06-29
Worklog # 5874 rethought.
added:
mysql-test/r/datetime_now.result
mysql-test/t/datetime_now.test
modified:
mysql-test/r/create.result
mysql-test/r/type_timestamp.result
mysql-test/t/create.test
sql/field.cc
sql/field.h
sql/share/errmsg-utf8.txt
sql/sql_parse.cc
sql/sql_table.cc
sql/table.h
=== modified file 'mysql-test/r/create.result'
--- a/mysql-test/r/create.result 2011-02-21 02:57:30 +0000
+++ b/mysql-test/r/create.result 2011-06-29 14:18:43 +0000
@@ -54,10 +54,6 @@ create table `aaaaaaaaaaaaaaaaaaaaaaaaaa
ERROR 42000: Incorrect table name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
create table a (`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` int);
ERROR 42000: Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long
-create table t1 (a datetime default now());
-ERROR 42000: Invalid default value for 'a'
-create table t1 (a datetime on update now());
-ERROR HY000: Invalid ON UPDATE clause for 'a' column
create table t1 (a int default 100 auto_increment);
ERROR 42000: Invalid default value for 'a'
create table t1 (a tinyint default 1000);
=== added file 'mysql-test/r/datetime_now.result'
--- a/mysql-test/r/datetime_now.result 1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/datetime_now.result 2011-06-29 14:18:43 +0000
@@ -0,0 +1,131 @@
+#
+# Worklog#5874: CURRENT_TIMESTAMP as DEFAULT for DATETIME columns
+#
+SET TIME_ZONE = "+00:00";
+CREATE TABLE t1 ( a DATETIME NOT NULL );
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime NOT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
+CREATE TABLE t1 ( a TIMESTAMP DEFAULT CURRENT_TIMESTAMP, b INT );
+# 2011-04-19 07:22:02 UTC
+SET TIMESTAMP = 1303197722;
+INSERT INTO t1 ( b ) VALUES ( 1 );
+SELECT * FROM t1;
+a b
+2011-04-19 07:22:02 1
+DROP TABLE t1;
+CREATE TABLE t1 ( a DATETIME DEFAULT CURRENT_TIMESTAMP, b INT );
+# 1970-09-21 09:11:12 UTC
+SET TIMESTAMP = 22756272;
+INSERT INTO t1 ( b ) VALUES ( 1 );
+SELECT * FROM t1;
+a b
+1970-09-21 09:11:12 1
+# 2011-04-19 07:22:02 UTC
+SET TIMESTAMP = 1303197722;
+UPDATE t1 SET b = 2;
+SELECT * FROM t1;
+a b
+1970-09-21 09:11:12 2
+DROP TABLE t1;
+CREATE TABLE t1 ( a DATETIME ON UPDATE CURRENT_TIMESTAMP, b INT );
+# 1970-09-21 09:11:12 UTC
+SET TIMESTAMP = 22756272;
+INSERT INTO t1 ( b ) VALUES ( 1 );
+SELECT * FROM t1;
+a b
+NULL 1
+# 2011-04-19 07:22:02 UTC
+SET TIMESTAMP = 1303197722;
+UPDATE t1 SET b = 2;
+SELECT * FROM t1;
+a b
+2011-04-19 07:22:02 2
+DROP TABLE t1;
+CREATE TABLE t1 (
+a DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+b INT
+);
+# 1970-09-21 09:11:12 UTC
+SET TIMESTAMP = 22756272;
+INSERT INTO t1 ( b ) VALUES ( 1 );
+SELECT * FROM t1;
+a b
+1970-09-21 09:11:12 1
+# 2011-04-19 07:22:02 UTC
+SET TIMESTAMP = 1303197722;
+UPDATE t1 SET b = 2;
+SELECT * FROM t1;
+a b
+2011-04-19 07:22:02 2
+DROP TABLE t1;
+CREATE TABLE t1 (
+a TIMESTAMP,
+b DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
+);
+ERROR HY000: Incorrect table definition; there can be only one column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
+CREATE TABLE t1 (a TIMESTAMP, b DATETIME DEFAULT CURRENT_TIMESTAMP);
+ERROR HY000: Incorrect table definition; there can be only one column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
+CREATE TABLE t1 (a TIMESTAMP, b DATETIME ON UPDATE CURRENT_TIMESTAMP);
+ERROR HY000: Incorrect table definition; there can be only one column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
+CREATE TABLE t1 (a DATETIME, b DATETIME ON UPDATE CURRENT_TIMESTAMP);
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
+CREATE TABLE t1 (a DATETIME ON UPDATE CURRENT_TIMESTAMP, b DATETIME);
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
+ `b` datetime DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
+CREATE TABLE t1 (a DATETIME, b DATETIME DEFAULT CURRENT_TIMESTAMP);
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` datetime DEFAULT CURRENT_TIMESTAMP
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
+CREATE TABLE t1 (a DATETIME DEFAULT CURRENT_TIMESTAMP, b DATETIME);
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT CURRENT_TIMESTAMP,
+ `b` datetime DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
+CREATE TABLE t1 (
+a DATETIME ON UPDATE CURRENT_TIMESTAMP,
+b DATETIME DEFAULT CURRENT_TIMESTAMP
+);
+ERROR HY000: Incorrect table definition; there can be only one column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
+CREATE TABLE t1 (
+a DATETIME DEFAULT CURRENT_TIMESTAMP,
+b DATETIME ON UPDATE CURRENT_TIMESTAMP
+);
+ERROR HY000: Incorrect table definition; there can be only one column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
+CREATE TABLE t1 (a TIMESTAMP, b DATETIME);
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ `b` datetime DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
+CREATE TABLE t1 (a DATETIME, b TIMESTAMP);
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
=== modified file 'mysql-test/r/type_timestamp.result'
--- a/mysql-test/r/type_timestamp.result 2011-04-18 08:47:41 +0000
+++ b/mysql-test/r/type_timestamp.result 2011-06-29 14:18:43 +0000
@@ -148,15 +148,15 @@ ix+0
20030101000000
drop table t1;
create table t1 (t1 timestamp, t2 timestamp default now());
-ERROR HY000: Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
+ERROR HY000: Incorrect table definition; there can be only one column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
create table t1 (t1 timestamp, t2 timestamp on update now());
-ERROR HY000: Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
+ERROR HY000: Incorrect table definition; there can be only one column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
create table t1 (t1 timestamp, t2 timestamp default now() on update now());
-ERROR HY000: Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
+ERROR HY000: Incorrect table definition; there can be only one column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
create table t1 (t1 timestamp default now(), t2 timestamp on update now());
-ERROR HY000: Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
+ERROR HY000: Incorrect table definition; there can be only one column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
create table t1 (t1 timestamp on update now(), t2 timestamp default now() on update now());
-ERROR HY000: Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
+ERROR HY000: Incorrect table definition; there can be only one column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
create table t1 (t1 timestamp default '2003-01-01 00:00:00', t2 datetime, t3 timestamp);
SET TIMESTAMP=1000000000;
insert into t1 values ();
=== modified file 'mysql-test/t/create.test'
--- a/mysql-test/t/create.test 2011-02-21 02:57:30 +0000
+++ b/mysql-test/t/create.test 2011-06-29 14:18:43 +0000
@@ -56,10 +56,6 @@ create table a (`aaaaaaaaaaaaaaaaaaaaaaa
# Some wrong defaults, so these creates should fail too (Bug #5902)
#
--error 1067
-create table t1 (a datetime default now());
---error 1294
-create table t1 (a datetime on update now());
---error 1067
create table t1 (a int default 100 auto_increment);
--error 1067
create table t1 (a tinyint default 1000);
=== added file 'mysql-test/t/datetime_now.test'
--- a/mysql-test/t/datetime_now.test 1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/datetime_now.test 2011-06-29 14:18:43 +0000
@@ -0,0 +1,119 @@
+--echo #
+--echo # Worklog#5874: CURRENT_TIMESTAMP as DEFAULT for DATETIME columns
+--echo #
+SET TIME_ZONE = "+00:00";
+
+CREATE TABLE t1 ( a DATETIME NOT NULL );
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+
+CREATE TABLE t1 ( a TIMESTAMP DEFAULT CURRENT_TIMESTAMP, b INT );
+
+--echo # 2011-04-19 07:22:02 UTC
+SET TIMESTAMP = 1303197722;
+INSERT INTO t1 ( b ) VALUES ( 1 );
+SELECT * FROM t1;
+DROP TABLE t1;
+
+
+CREATE TABLE t1 ( a DATETIME DEFAULT CURRENT_TIMESTAMP, b INT );
+
+--echo # 1970-09-21 09:11:12 UTC
+SET TIMESTAMP = 22756272;
+INSERT INTO t1 ( b ) VALUES ( 1 );
+SELECT * FROM t1;
+
+--echo # 2011-04-19 07:22:02 UTC
+SET TIMESTAMP = 1303197722;
+UPDATE t1 SET b = 2;
+SELECT * FROM t1;
+
+DROP TABLE t1;
+
+
+CREATE TABLE t1 ( a DATETIME ON UPDATE CURRENT_TIMESTAMP, b INT );
+
+--echo # 1970-09-21 09:11:12 UTC
+SET TIMESTAMP = 22756272;
+INSERT INTO t1 ( b ) VALUES ( 1 );
+SELECT * FROM t1;
+
+--echo # 2011-04-19 07:22:02 UTC
+SET TIMESTAMP = 1303197722;
+UPDATE t1 SET b = 2;
+SELECT * FROM t1;
+
+DROP TABLE t1;
+
+
+CREATE TABLE t1 (
+ a DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ b INT
+);
+
+--echo # 1970-09-21 09:11:12 UTC
+SET TIMESTAMP = 22756272;
+INSERT INTO t1 ( b ) VALUES ( 1 );
+SELECT * FROM t1;
+
+--echo # 2011-04-19 07:22:02 UTC
+SET TIMESTAMP = 1303197722;
+UPDATE t1 SET b = 2;
+SELECT * FROM t1;
+
+DROP TABLE t1;
+
+--error ER_TOO_MUCH_AUTO_TIMESTAMP_COLS
+CREATE TABLE t1 (
+ a TIMESTAMP,
+ b DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
+);
+
+--error ER_TOO_MUCH_AUTO_TIMESTAMP_COLS
+CREATE TABLE t1 (a TIMESTAMP, b DATETIME DEFAULT CURRENT_TIMESTAMP);
+
+--error ER_TOO_MUCH_AUTO_TIMESTAMP_COLS
+CREATE TABLE t1 (a TIMESTAMP, b DATETIME ON UPDATE CURRENT_TIMESTAMP);
+
+
+CREATE TABLE t1 (a DATETIME, b DATETIME ON UPDATE CURRENT_TIMESTAMP);
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+
+CREATE TABLE t1 (a DATETIME ON UPDATE CURRENT_TIMESTAMP, b DATETIME);
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a DATETIME, b DATETIME DEFAULT CURRENT_TIMESTAMP);
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+
+CREATE TABLE t1 (a DATETIME DEFAULT CURRENT_TIMESTAMP, b DATETIME);
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+
+--error ER_TOO_MUCH_AUTO_TIMESTAMP_COLS
+CREATE TABLE t1 (
+ a DATETIME ON UPDATE CURRENT_TIMESTAMP,
+ b DATETIME DEFAULT CURRENT_TIMESTAMP
+);
+
+--error ER_TOO_MUCH_AUTO_TIMESTAMP_COLS
+CREATE TABLE t1 (
+ a DATETIME DEFAULT CURRENT_TIMESTAMP,
+ b DATETIME ON UPDATE CURRENT_TIMESTAMP
+);
+
+
+CREATE TABLE t1 (a TIMESTAMP, b DATETIME);
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+
+CREATE TABLE t1 (a DATETIME, b TIMESTAMP);
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
=== modified file 'sql/field.cc'
--- a/sql/field.cc 2011-06-10 16:57:01 +0000
+++ b/sql/field.cc 2011-06-29 14:18:43 +0000
@@ -4707,8 +4707,9 @@ Field_timestamp::Field_timestamp(bool ma
Returns value indicating during which operations this TIMESTAMP field
should be auto-set to current timestamp.
*/
-timestamp_auto_set_type Field_timestamp::get_auto_set_type() const
+timestamp_auto_set_type Field::get_auto_set_type() const
{
+ DBUG_ASSERT(type() == MYSQL_TYPE_TIMESTAMP || type() == MYSQL_TYPE_DATETIME);
switch (unireg_check)
{
case TIMESTAMP_DN_FIELD:
@@ -6025,6 +6026,19 @@ int Field_datetime::store_time(MYSQL_TIM
return error;
}
+
+void Field_datetime::set_time()
+{
+ MYSQL_TIME now_time;
+ THD *thd= current_thd;
+ const my_time_t query_start= static_cast<my_time_t>(thd->query_start());
+ thd->variables.time_zone->gmt_sec_to_TIME(&now_time, query_start);
+ thd->time_zone_used= true;
+ set_notnull();
+ const int error= store_time(&now_time, MYSQL_TIMESTAMP_DATETIME);
+ DBUG_ASSERT(error == 0);
+}
+
bool Field_datetime::send_binary(Protocol *protocol)
{
MYSQL_TIME tm;
@@ -9554,6 +9568,26 @@ bool Create_field::init(THD *thd, char *
break;
case MYSQL_TYPE_DATETIME:
length= MAX_DATETIME_WIDTH;
+ if (fld_default_value != NULL &&
+ fld_default_value->type() == Item::FUNC_ITEM &&
+ static_cast<Item_func*>(fld_default_value)->functype() ==
+ Item_func::NOW_FUNC)
+ {
+ unireg_check= Field::TIMESTAMP_DN_FIELD;
+ /*
+ The default value is part of the parse tree and hence it is risky to
+ keep a reference to it in a structure which has a longer life cycle.
+ Alas, everything is handled by unireg_check from this point on.
+ */
+ def= NULL;
+ }
+ if (fld_on_update_value != NULL &&
+ fld_on_update_value->type() == Item::FUNC_ITEM &&
+ static_cast<Item_func*>(fld_on_update_value)->functype() ==
+ Item_func::NOW_FUNC)
+ unireg_check= (unireg_check == Field::TIMESTAMP_DN_FIELD ?
+ Field::TIMESTAMP_DNUN_FIELD :
+ Field::TIMESTAMP_UN_FIELD);
break;
case MYSQL_TYPE_SET:
{
@@ -9878,7 +9912,7 @@ Field *make_field(TABLE_SHARE *share, uc
unireg_check, field_name, field_charset);
case MYSQL_TYPE_DATETIME:
return new Field_datetime(ptr,null_pos,null_bit,
- unireg_check, field_name, field_charset);
+ unireg_check, field_name, share, field_charset);
case MYSQL_TYPE_NULL:
return new Field_null(ptr, field_length, unireg_check, field_name,
field_charset);
=== modified file 'sql/field.h'
--- a/sql/field.h 2011-05-26 15:20:09 +0000
+++ b/sql/field.h 2011-06-29 14:18:43 +0000
@@ -227,6 +227,16 @@ public:
virtual int reset(void) { memset(ptr, 0, pack_length()); return 0; }
virtual void reset_fields() {}
+ timestamp_auto_set_type get_auto_set_type() const;
+ virtual void set_time()
+ { DBUG_ASSERT(0); } // Only Field_timestamp and Field_datetime are allowed
+ virtual long get_timestamp(my_bool *null_value)
+ {
+ DBUG_ASSERT(0); // Only Field_timestamp and Field_datetime are allowed
+ return 0;
+ }
+ virtual void store_timestamp(my_time_t timestamp)
+ { DBUG_ASSERT(0); } // Only Field_timestamp and Field_datetime are allowed
virtual void set_default()
{
my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->s->default_values -
@@ -1645,10 +1655,21 @@ class Field_datetime :public Field_str {
public:
Field_datetime(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
enum utype unireg_check_arg, const char *field_name_arg,
+ TABLE_SHARE *share,
const CHARSET_INFO *cs)
:Field_str(ptr_arg, MAX_DATETIME_WIDTH, null_ptr_arg, null_bit_arg,
unireg_check_arg, field_name_arg, cs)
- { flags|= BINARY_FLAG; }
+ {
+ flags|= BINARY_FLAG;
+ if (!share->timestamp_field && unireg_check != NONE)
+ {
+ /* This DATETIME columns is hereby assumed to posess auto-update */
+ share->timestamp_field= this;
+ flags|= TIMESTAMP_FLAG;
+ if (unireg_check != TIMESTAMP_DN_FIELD)
+ flags|= ON_UPDATE_NOW_FLAG;
+ }
+ }
Field_datetime(bool maybe_null_arg, const char *field_name_arg,
const CHARSET_INFO *cs)
:Field_str((uchar*) 0, MAX_DATETIME_WIDTH, maybe_null_arg ? (uchar*) "": 0,0,
@@ -1704,6 +1725,7 @@ public:
{
return unpack_int64(to, from, low_byte_first);
}
+ void set_time();
};
=== modified file 'sql/share/errmsg-utf8.txt'
--- a/sql/share/errmsg-utf8.txt 2011-06-10 07:38:06 +0000
+++ b/sql/share/errmsg-utf8.txt 2011-06-29 14:18:43 +0000
@@ -5054,10 +5054,10 @@ ER_TRUNCATED_WRONG_VALUE 22007
por "Truncado errado %-.32s valor: '%-.128s'"
spa "Equivocado truncado %-.32s valor: '%-.128s'"
ER_TOO_MUCH_AUTO_TIMESTAMP_COLS
- eng "Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause"
- ger "Fehlerhafte Tabellendefinition. Es kann nur eine einzige TIMESTAMP-Spalte mit CURRENT_TIMESTAMP als DEFAULT oder in einer ON-UPDATE-Klausel geben"
- por "Incorreta definição de tabela; Pode ter somente uma coluna TIMESTAMP com CURRENT_TIMESTAMP em DEFAULT ou ON UPDATE cláusula"
- spa "Incorrecta definición de tabla; Solamente debe haber una columna TIMESTAMP con CURRENT_TIMESTAMP en DEFAULT o ON UPDATE cláusula"
+ eng "Incorrect table definition; there can be only one column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause"
+ ger "Fehlerhafte Tabellendefinition. Es kann nur eine einzige Spalte mit CURRENT_TIMESTAMP als DEFAULT oder in einer ON-UPDATE-Klausel geben"
+ por "Incorreta definição de tabela; Pode ter somente uma coluna com CURRENT_TIMESTAMP em DEFAULT ou ON UPDATE cláusula"
+ spa "Incorrecta definición de tabla; Solamente debe haber una columna con CURRENT_TIMESTAMP en DEFAULT o ON UPDATE cláusula"
ER_INVALID_ON_UPDATE
eng "Invalid ON UPDATE clause for '%-.192s' column"
ger "Ungültige ON-UPDATE-Klausel für Spalte '%-.192s'"
=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc 2011-06-24 09:29:07 +0000
+++ b/sql/sql_parse.cc 2011-06-29 14:18:43 +0000
@@ -5836,8 +5836,10 @@ bool add_field_to_list(THD *thd, LEX_STR
NOW() as default for TIMESTAMP type.
*/
if (default_value->type() == Item::FUNC_ITEM &&
- !(((Item_func*)default_value)->functype() == Item_func::NOW_FUNC &&
- type == MYSQL_TYPE_TIMESTAMP))
+ static_cast<Item_func*>(default_value)->functype() ==
+ Item_func::NOW_FUNC &&
+ type != MYSQL_TYPE_TIMESTAMP &&
+ type != MYSQL_TYPE_DATETIME)
{
my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
DBUG_RETURN(1);
@@ -5859,7 +5861,9 @@ bool add_field_to_list(THD *thd, LEX_STR
}
}
- if (on_update_value && type != MYSQL_TYPE_TIMESTAMP)
+ if (on_update_value &&
+ type != MYSQL_TYPE_TIMESTAMP &&
+ type != MYSQL_TYPE_DATETIME)
{
my_error(ER_INVALID_ON_UPDATE, MYF(0), field_name->str);
DBUG_RETURN(1);
=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc 2011-06-20 12:07:06 +0000
+++ b/sql/sql_table.cc 2011-06-29 14:18:43 +0000
@@ -2856,6 +2856,11 @@ int prepare_create_field(Create_field *s
case MYSQL_TYPE_NEWDATE:
case MYSQL_TYPE_TIME:
case MYSQL_TYPE_DATETIME:
+ if (sql_field->unireg_check == Field::TIMESTAMP_DN_FIELD ||
+ sql_field->unireg_check == Field::TIMESTAMP_UN_FIELD ||
+ sql_field->unireg_check == Field::TIMESTAMP_DNUN_FIELD)
+ ++(*timestamps_with_niladic);
+ /* fall-through */
case MYSQL_TYPE_NULL:
sql_field->pack_flag=f_settype((uint) sql_field->sql_type);
break;
=== modified file 'sql/table.h'
--- a/sql/table.h 2011-06-16 06:30:16 +0000
+++ b/sql/table.h 2011-06-29 14:18:43 +0000
@@ -986,7 +986,7 @@ public:
Field *next_number_field; /* Set if next_number is activated */
Field *found_next_number_field; /* Set on open */
- Field_timestamp *timestamp_field;
+ Field *timestamp_field;
/* Table's triggers, 0 if there are no of them */
Table_triggers_list *triggers;
Attachment: [text/bzr-bundle] bzr/martin.hansson@oracle.com-20110629141843-xl0ky3t8q46dimp1.bundle
| Thread |
|---|
| • bzr commit into mysql-trunk branch (martin.hansson:3239) | Martin Hansson | 29 Jun |