--source include/have_innodb.inc

#
# testing of temporal data types with InnoDB
#


--echo #
--echo # MDEV-9604 crash in Item::save_in_field with empty enum value
--echo #

SELECT TIME'00:00:00'='';

CREATE TABLE t1 (a ENUM('a'), b TIME, c INT, KEY(b)) ENGINE=InnoDB;
INSERT IGNORE INTO t1 VALUES ('','00:00:00',0);
SELECT * FROM t1 WHERE b='';
SELECT * FROM t1 IGNORE KEY (b) WHERE b='';
SELECT * FROM t1 WHERE a=b;
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b;

ALTER TABLE t1 ENGINE=MyISAM;
SELECT * FROM t1 WHERE b='';
SELECT * FROM t1 IGNORE KEY (b) WHERE b='';
SELECT * FROM t1 WHERE a=b;
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b;
DROP TABLE t1;


SELECT DATE'0000-00-00'='';

CREATE TABLE t1 (a ENUM('a'), b DATE, c INT, KEY(b)) ENGINE=InnoDB;
INSERT IGNORE INTO t1 VALUES ('','0000-00-00',0);
SELECT * FROM t1 WHERE b='';
SELECT * FROM t1 IGNORE KEY (b) WHERE b='';
SELECT * FROM t1 WHERE a=b;
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b;

ALTER TABLE t1 ENGINE=MyISAM;
SELECT * FROM t1 WHERE b='';
SELECT * FROM t1 IGNORE KEY (b) WHERE b='';
SELECT * FROM t1 WHERE a=b;
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b;
DROP TABLE t1;


SELECT TIMESTAMP'0000-00-00 00:00:00'='';

CREATE TABLE t1 (a ENUM('a'), b DATETIME, c INT, KEY(b)) ENGINE=InnoDB;
INSERT IGNORE INTO t1 VALUES ('','0000-00-00 00:00:00',0);
SELECT * FROM t1 WHERE b='';
SELECT * FROM t1 IGNORE KEY (b) WHERE b='';
SELECT * FROM t1 WHERE a=b;
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b;

ALTER TABLE t1 ENGINE=MyISAM;
SELECT * FROM t1 WHERE b='';
SELECT * FROM t1 IGNORE KEY (b) WHERE b='';
SELECT * FROM t1 WHERE a=b;
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b;
DROP TABLE t1;

#
# MDEV-15570 Assertion `Item_cache_temporal::field_type() != MYSQL_TYPE_TIME' failed in Item_cache_temporal::val_datetime_packed
#
CREATE TABLE t1 (d DATE) ENGINE=InnoDB;
INSERT INTO t1 VALUES ('2012-12-21');
SELECT * FROM t1 WHERE LEAST( UTC_TIME(), d );
DROP TABLE t1;

--echo #
--echo # MDEV-17969 Assertion `name' failed in THD::push_warning_truncated_value_for_field
--echo #

CREATE TABLE t1 (c1 DATE , c2 TIMESTAMP) ENGINE=InnoDB;
INSERT INTO t1  VALUES ('2006-07-17','0000-00-00 00:00:00');
CREATE TABLE t2 (pk INT, a1 TIME) Engine=InnoDB;
INSERT INTO t2 VALUES (6,'00:00:00');
SET SESSION sql_mode= 'strict_all_tables,no_zero_date';
--error ER_TRUNCATED_WRONG_VALUE
CREATE TABLE tbl SELECT * FROM t1 WHERE t1.c1 = (SELECT c2 FROM t2 WHERE pk = 6);
# ^^^ there is no column c2 in table t2
DROP TABLE t1,t2;
SET sql_mode=DEFAULT;

--echo #
--echo # End of 10.3 tests
--echo #

--echo #
--echo # MDEV-19166 Assertion `!is_zero_datetime()' failed in Timestamp_or_zero_datetime::tv
--echo #

CREATE TABLE t1 (f TIMESTAMP DEFAULT 0) ENGINE=InnoDB;
INSERT INTO t1 VALUES ('2024-02-29');
SELECT * FROM t1 WHERE SUBSTR(1 FROM BIT_LENGTH(f) FOR DEFAULT(f));
DROP TABLE t1;

--echo #
--echo # End of 10.4 tests
--echo #
