mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
A patch for Bug#18834: ALTER TABLE ADD INDEX on table with
two timestamp fields. The actual problem here was that CREATE TABLE allowed zero date as a default value for a TIMESTAMP column in NO_ZERO_DATE mode. The thing is that for TIMESTAMP date type specific rule is applied: column_name TIMESTAMP == column_name TIMESTAMP DEFAULT 0 whever for any other date data type column_name TYPE == column_name TYPE DEFAULT NULL The fix is to raise an error when we're in NO_ZERO_DATE mode and there is TIMESTAMP column w/o default value. mysql-test/r/create.result: Update result file. mysql-test/t/create.test: Test case for Bug#18834: ALTER TABLE ADD INDEX on table with two timestamp fields. sql/sql_table.cc: Report an error if NO_ZERO_MODE is set and we have zero date as a default.
This commit is contained in:
@ -1789,4 +1789,48 @@ DROP TABLE t2;
|
||||
|
||||
# -- End of test case for Bug#21380.
|
||||
|
||||
# --
|
||||
# -- Bug#18834: ALTER TABLE ADD INDEX on table with two timestamp fields
|
||||
# --
|
||||
|
||||
DROP TABLE IF EXISTS t1;
|
||||
DROP TABLE IF EXISTS t2;
|
||||
DROP TABLE IF EXISTS t3;
|
||||
|
||||
CREATE TABLE t1(c1 TIMESTAMP, c2 TIMESTAMP);
|
||||
|
||||
SET sql_mode = NO_ZERO_DATE;
|
||||
|
||||
CREATE TABLE t2(c1 TIMESTAMP, c2 TIMESTAMP DEFAULT 0);
|
||||
ERROR 42000: Invalid default value for 'c2'
|
||||
|
||||
CREATE TABLE t2(c1 TIMESTAMP, c2 TIMESTAMP);
|
||||
ERROR 42000: Invalid default value for 'c2'
|
||||
|
||||
# -- Check that NULL column still can be created.
|
||||
CREATE TABLE t2(c1 TIMESTAMP NULL);
|
||||
|
||||
# -- Check ALTER TABLE.
|
||||
ALTER TABLE t1 ADD INDEX(c1);
|
||||
ERROR 42000: Invalid default value for 'c2'
|
||||
|
||||
# -- Check DATETIME.
|
||||
SET sql_mode = '';
|
||||
|
||||
CREATE TABLE t3(c1 DATETIME NOT NULL);
|
||||
INSERT INTO t3 VALUES (0);
|
||||
|
||||
SET sql_mode = TRADITIONAL;
|
||||
|
||||
ALTER TABLE t3 ADD INDEX(c1);
|
||||
ERROR 22007: Incorrect datetime value: '0000-00-00 00:00:00' for column 'c1' at row 1
|
||||
|
||||
# -- Cleanup.
|
||||
SET sql_mode = '';
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t2;
|
||||
DROP TABLE t3;
|
||||
|
||||
# -- End of Bug#18834.
|
||||
|
||||
End of 5.1 tests
|
||||
|
Reference in New Issue
Block a user