Skip to content

Commit 5c9c8ef

Browse files
author
Alexander Barkov
committed
MDEV-3929 Add system variable explicit_defaults_for_timestamp for compatibility with MySQL
1 parent 89af0f1 commit 5c9c8ef

File tree

111 files changed

+844
-219
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+844
-219
lines changed

mysql-test/extra/binlog_tests/mysqlbinlog_row_engine.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ eval CREATE TABLE t1 (
7777
#
7878
c28 DATE,
7979
c29 DATETIME,
80-
c30 TIMESTAMP,
80+
c30 TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
8181
c31 TIME,
8282
c32 YEAR,
8383
#

mysql-test/extra/rpl_tests/rpl_extra_col_slave.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ sync_slave_with_master;
398398
STOP SLAVE;
399399
RESET SLAVE;
400400
eval CREATE TABLE t9 (a INT KEY, b BLOB, c CHAR(5),
401-
d TIMESTAMP,
401+
d TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
402+
ON UPDATE CURRENT_TIMESTAMP,
402403
e INT NOT NULL,
403404
f text not null,
404405
g text,

mysql-test/include/ctype_numconv.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ create table t2 as select concat(a) from t1;
11661166
show create table t2;
11671167
drop table t1, t2;
11681168

1169-
create table t1 (a timestamp);
1169+
create table t1 (a timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
11701170
insert into t1 values (0);
11711171
insert into t1 values (20010203040506);
11721172
insert into t1 values (19800203040506);
@@ -1478,7 +1478,7 @@ select hex(a) from v1;
14781478
drop table t1;
14791479
drop view v1;
14801480

1481-
create table t1 (a timestamp);
1481+
create table t1 (a timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
14821482
insert into t1 values (0);
14831483
insert into t1 values (20010203040506);
14841484
insert into t1 values (19800203040506);

mysql-test/include/mix2.inc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ drop table t1;
500500
# Test of opening table twice and timestamps
501501
#
502502
set @a:=now();
503-
eval CREATE TABLE t1 (a int not null, b timestamp not null, primary key (a)) engine=$engine_type;
503+
eval CREATE TABLE t1 (a int not null, b timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, primary key (a)) engine=$engine_type;
504504
insert into t1 (a) values(1),(2),(3);
505505
select t1.a from t1 natural join t1 as t2 where t1.b >= @a order by t1.a;
506506
select a from t1 natural join t1 as t2 where b >= @a order by a;
@@ -727,9 +727,9 @@ eval CREATE TABLE t1 (
727727
cname char(15) NOT NULL default '',
728728
carrier_id smallint(6) NOT NULL default '0',
729729
privacy tinyint(4) NOT NULL default '0',
730-
last_mod_date timestamp NOT NULL,
730+
last_mod_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
731731
last_mod_id smallint(6) NOT NULL default '0',
732-
last_app_date timestamp NOT NULL,
732+
last_app_date timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
733733
last_app_id smallint(6) default '-1',
734734
version smallint(6) NOT NULL default '0',
735735
assigned_scps int(11) default '0',
@@ -746,9 +746,9 @@ eval CREATE TABLE t2 (
746746
cname char(15) NOT NULL default '',
747747
carrier_id smallint(6) NOT NULL default '0',
748748
privacy tinyint(4) NOT NULL default '0',
749-
last_mod_date timestamp NOT NULL,
749+
last_mod_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
750750
last_mod_id smallint(6) NOT NULL default '0',
751-
last_app_date timestamp NOT NULL,
751+
last_app_date timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
752752
last_app_id smallint(6) default '-1',
753753
version smallint(6) NOT NULL default '0',
754754
assigned_scps int(11) default '0',

mysql-test/include/mtr_warnings.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ INSERT INTO global_suppressions VALUES
165165

166166
("The slave I.O thread stops because a fatal error is encountered when it try to get the value of SERVER_ID variable from master."),
167167

168+
/*It will print a warning if server is run without --explicit_defaults_for_timestamp.*/
169+
("TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details)*"),
170+
168171
/* Added 2009-08-XX after fixing Bug #42408 */
169172

170173
("Although a path was specified for the .* option, log tables are used"),

mysql-test/include/ps_create.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ eval create table t9
3333
c1 tinyint, c2 smallint, c3 mediumint, c4 int,
3434
c5 integer, c6 bigint, c7 float, c8 double,
3535
c9 double precision, c10 real, c11 decimal(7, 4), c12 numeric(8, 4),
36-
c13 date, c14 datetime, c15 timestamp, c16 time,
36+
c13 date, c14 datetime, c15 timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
37+
ON UPDATE CURRENT_TIMESTAMP, c16 time,
3738
c17 year, c18 tinyint, c19 bool, c20 char,
3839
c21 char(10), c22 varchar(30), c23 tinyblob, c24 tinytext,
3940
c25 blob, c26 text, c27 mediumblob, c28 mediumtext,

mysql-test/include/type_hrtime.inc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ alter table t1 engine=innodb;
2525
select * from t1 order by a;
2626
select * from t1 order by a+0;
2727
drop table t1;
28-
eval create table t1 (a $type(4)) engine=innodb;
28+
let attr=;
29+
if ($type == timestamp)
30+
{
31+
let attr=NOT NULL DEFAULT CURRENT_TIMESTAMP(4) ON UPDATE CURRENT_TIMESTAMP(4);
32+
}
33+
eval create table t1 (a $type(4)$attr) engine=innodb;
2934
insert t1 values ('2010-12-11 01:02:03.456789');
3035
select * from t1;
3136
select extract(microsecond from a + interval 100 microsecond) from t1 where a>'2010-11-12 01:02:03.456';
@@ -93,7 +98,12 @@ drop table t1, t2;
9398
#
9499
# SP
95100
#
96-
eval create table t1 (a $type(6), b $type(6));
101+
let attr=;
102+
if ($type == timestamp)
103+
{
104+
let attr=NOT NULL DEFAULT '0000-00-00 00:00:00.000000';
105+
}
106+
eval create table t1 (a $type(6)$attr, b $type(6)$attr);
97107
eval create procedure foo(x $type, y $type(4)) insert into t1 values (x, y);
98108
call foo('2010-02-03 4:5:6.789123', '2010-02-03 4:5:6.789123');
99109
select * from t1;

mysql-test/r/create.result

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ a b c d e f g h dd
494494
1 -7 7 2000-01-01 b 2000-01-01 00:00:00 05:04:03 yet another binary data 02:00:00
495495
2 -2 2 1825-12-14 a 2003-01-01 03:02:01 04:03:02 binary data 02:00:00
496496
drop table t1, t2;
497-
create table t1 (a tinyint, b smallint, c mediumint, d int, e bigint, f float(3,2), g double(4,3), h decimal(5,4), i year, j date, k timestamp, l datetime, m enum('a','b'), n set('a','b'), o char(10));
497+
create table t1 (a tinyint, b smallint, c mediumint, d int, e bigint, f float(3,2), g double(4,3), h decimal(5,4), i year, j date, k timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, l datetime, m enum('a','b'), n set('a','b'), o char(10));
498498
create table t2 select ifnull(a,a), ifnull(b,b), ifnull(c,c), ifnull(d,d), ifnull(e,e), ifnull(f,f), ifnull(g,g), ifnull(h,h), ifnull(i,i), ifnull(j,j), ifnull(k,k), ifnull(l,l), ifnull(m,m), ifnull(n,n), ifnull(o,o) from t1;
499499
show create table t2;
500500
Table Create Table
@@ -1972,14 +1972,14 @@ DROP TABLE IF EXISTS t1;
19721972
DROP TABLE IF EXISTS t2;
19731973
DROP TABLE IF EXISTS t3;
19741974

1975-
CREATE TABLE t1(c1 TIMESTAMP, c2 TIMESTAMP);
1975+
CREATE TABLE t1(c1 TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, c2 TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00');
19761976

19771977
SET sql_mode = NO_ZERO_DATE;
19781978

19791979
CREATE TABLE t2(c1 TIMESTAMP, c2 TIMESTAMP DEFAULT 0);
19801980
ERROR 42000: Invalid default value for 'c2'
19811981

1982-
CREATE TABLE t2(c1 TIMESTAMP, c2 TIMESTAMP);
1982+
CREATE TABLE t2(c1 TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, c2 TIMESTAMP NOT NULL);
19831983
ERROR 42000: Invalid default value for 'c2'
19841984

19851985
# -- Check that NULL column still can be created.

mysql-test/r/ctype_binary.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,7 +2076,7 @@ t2 CREATE TABLE `t2` (
20762076
`concat(a)` varbinary(64) DEFAULT NULL
20772077
) ENGINE=MyISAM DEFAULT CHARSET=latin1
20782078
drop table t1, t2;
2079-
create table t1 (a timestamp);
2079+
create table t1 (a timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
20802080
insert into t1 values (0);
20812081
insert into t1 values (20010203040506);
20822082
insert into t1 values (19800203040506);
@@ -2388,7 +2388,7 @@ hex(a)
23882388
0000000000000001
23892389
drop table t1;
23902390
drop view v1;
2391-
create table t1 (a timestamp);
2391+
create table t1 (a timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
23922392
insert into t1 values (0);
23932393
insert into t1 values (20010203040506);
23942394
insert into t1 values (19800203040506);

mysql-test/r/ctype_cp1251.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,7 +2470,7 @@ t2 CREATE TABLE `t2` (
24702470
`concat(a)` varbinary(64) DEFAULT NULL
24712471
) ENGINE=MyISAM DEFAULT CHARSET=latin1
24722472
drop table t1, t2;
2473-
create table t1 (a timestamp);
2473+
create table t1 (a timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
24742474
insert into t1 values (0);
24752475
insert into t1 values (20010203040506);
24762476
insert into t1 values (19800203040506);
@@ -2782,7 +2782,7 @@ hex(a)
27822782
0000000000000001
27832783
drop table t1;
27842784
drop view v1;
2785-
create table t1 (a timestamp);
2785+
create table t1 (a timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
27862786
insert into t1 values (0);
27872787
insert into t1 values (20010203040506);
27882788
insert into t1 values (19800203040506);

0 commit comments

Comments
 (0)