Commit efc8404a authored by ramil@mysql.com's avatar ramil@mysql.com

fix (bug #11964: ALTER TABLE gives wrong error message with sql-mode TRADITIONAL (timestamp)).

parent 35b66a40
...@@ -1258,3 +1258,24 @@ select * from t1; ...@@ -1258,3 +1258,24 @@ select * from t1;
d d
2000-10-01 2000-10-01
drop table t1; drop table t1;
set @@sql_mode='traditional';
create table t1(a int, b timestamp);
alter table t1 add primary key(a);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) NOT NULL default '0',
`b` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t1(a int, b timestamp default 20050102030405);
alter table t1 add primary key(a);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) NOT NULL default '0',
`b` timestamp NOT NULL default '2005-01-02 03:04:05',
PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
...@@ -1118,3 +1118,17 @@ insert into t1 values ('2000-10-01'); ...@@ -1118,3 +1118,17 @@ insert into t1 values ('2000-10-01');
update t1 set d = 1100; update t1 set d = 1100;
select * from t1; select * from t1;
drop table t1; drop table t1;
#
# Bug #11964: alter table with timestamp field
#
set @@sql_mode='traditional';
create table t1(a int, b timestamp);
alter table t1 add primary key(a);
show create table t1;
drop table t1;
create table t1(a int, b timestamp default 20050102030405);
alter table t1 add primary key(a);
show create table t1;
drop table t1;
...@@ -8462,7 +8462,10 @@ create_field::create_field(Field *old_field,Field *orig_field) ...@@ -8462,7 +8462,10 @@ create_field::create_field(Field *old_field,Field *orig_field)
def=0; def=0;
if (!(flags & (NO_DEFAULT_VALUE_FLAG | BLOB_FLAG)) && if (!(flags & (NO_DEFAULT_VALUE_FLAG | BLOB_FLAG)) &&
!old_field->is_real_null() && !old_field->is_real_null() &&
old_field->ptr && orig_field) old_field->ptr && orig_field &&
(sql_type != FIELD_TYPE_TIMESTAMP || /* set def only if */
old_field->table->timestamp_field != old_field || /* timestamp field */
unireg_check == Field::TIMESTAMP_UN_FIELD)) /* has default val */
{ {
char buff[MAX_FIELD_WIDTH],*pos; char buff[MAX_FIELD_WIDTH],*pos;
String tmp(buff,sizeof(buff), charset), *res; String tmp(buff,sizeof(buff), charset), *res;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment