diff options
47 files changed, 885 insertions, 590 deletions
diff --git a/include/my_time.h b/include/my_time.h index a1eaea90a9c..babd6101eeb 100644 --- a/include/my_time.h +++ b/include/my_time.h @@ -70,9 +70,14 @@ extern uchar days_in_month[]; #define MYSQL_TIME_WARN_TRUNCATED 1U #define MYSQL_TIME_WARN_OUT_OF_RANGE 2U +#define MYSQL_TIME_WARN_EDOM 4U +#define MYSQL_TIME_WARN_ZERO_DATE 8U #define MYSQL_TIME_NOTE_TRUNCATED 16U -#define MYSQL_TIME_WARN_WARNINGS (MYSQL_TIME_WARN_TRUNCATED|MYSQL_TIME_WARN_OUT_OF_RANGE) +#define MYSQL_TIME_WARN_WARNINGS (MYSQL_TIME_WARN_TRUNCATED|\ + MYSQL_TIME_WARN_OUT_OF_RANGE|\ + MYSQL_TIME_WARN_EDOM|\ + MYSQL_TIME_WARN_ZERO_DATE) #define MYSQL_TIME_WARN_NOTES (MYSQL_TIME_NOTE_TRUNCATED) #define MYSQL_TIME_WARN_HAVE_WARNINGS(x) MY_TEST((x) & MYSQL_TIME_WARN_WARNINGS) diff --git a/mysql-test/main/cast.result b/mysql-test/main/cast.result index ca314573581..f1e7eb7b502 100644 --- a/mysql-test/main/cast.result +++ b/mysql-test/main/cast.result @@ -313,7 +313,7 @@ select cast('' as time); cast('' as time) NULL Warnings: -Warning 1292 Truncated incorrect time value: '' +Warning 1292 Incorrect time value: '' select cast(NULL as DATE); cast(NULL as DATE) NULL diff --git a/mysql-test/main/date_formats.result b/mysql-test/main/date_formats.result index 16dbdf7969c..463cce39520 100644 --- a/mysql-test/main/date_formats.result +++ b/mysql-test/main/date_formats.result @@ -442,7 +442,7 @@ f1 f2 f3 Warnings: Warning 1292 Truncated incorrect datetime value: '2003-01-02 10:11:12.0012ABCD' Warning 1292 Truncated incorrect time value: '-01:01:01.01 GGG' -Warning 1292 Truncated incorrect time value: '1997-12-31 23:59:59.01XXXX' +Warning 1292 Truncated incorrect datetime value: '1997-12-31 23:59:59.01XXXX' select str_to_date("2003-04-05 g", "%Y-%m-%d") as f1, str_to_date("2003-04-05 10:11:12.101010234567", "%Y-%m-%d %H:%i:%S.%f") as f2; f1 f2 diff --git a/mysql-test/main/dyncol.result b/mysql-test/main/dyncol.result index 7a5eeac67cc..cc9a94e74be 100644 --- a/mysql-test/main/dyncol.result +++ b/mysql-test/main/dyncol.result @@ -1028,12 +1028,12 @@ select column_get(column_create(1, "2011-02-32 8:46:06.23434" AS CHAR), 1 as tim column_get(column_create(1, "2011-02-32 8:46:06.23434" AS CHAR), 1 as time) NULL Warnings: -Warning 1292 Truncated incorrect time value: '2011-02-32 8:46:06.23434' +Warning 1292 Incorrect time value: '2011-02-32 8:46:06.23434' select column_get(column_create(1, "2011-13-01 8:46:06.23434" AS CHAR), 1 as time); column_get(column_create(1, "2011-13-01 8:46:06.23434" AS CHAR), 1 as time) NULL Warnings: -Warning 1292 Truncated incorrect time value: '2011-13-01 8:46:06.23434' +Warning 1292 Incorrect time value: '2011-13-01 8:46:06.23434' select column_get(column_create(1, "2011-02-30 8:46:06.23434" AS CHAR), 1 as time); column_get(column_create(1, "2011-02-30 8:46:06.23434" AS CHAR), 1 as time) 08:46:06 diff --git a/mysql-test/main/func_in.result b/mysql-test/main/func_in.result index a86781b156c..acf718c453e 100644 --- a/mysql-test/main/func_in.result +++ b/mysql-test/main/func_in.result @@ -481,7 +481,7 @@ SELECT * FROM t4 WHERE a IN ('1972-02-06','19772-07-29'); a 1972-02-06 Warnings: -Warning 1292 Incorrect datetime value: '19772-07-29' +Warning 1292 Truncated incorrect datetime value: '19772-07-29' DROP TABLE t1,t2,t3,t4; CREATE TABLE t1 (id int not null); INSERT INTO t1 VALUES (1),(2); diff --git a/mysql-test/main/func_sapdb.result b/mysql-test/main/func_sapdb.result index 49e597a7811..27f1d74bc41 100644 --- a/mysql-test/main/func_sapdb.result +++ b/mysql-test/main/func_sapdb.result @@ -184,7 +184,7 @@ select time("1997-12-31 25:59:59.000001"); time("1997-12-31 25:59:59.000001") NULL Warnings: -Warning 1292 Truncated incorrect time value: '1997-12-31 25:59:59.000001' +Warning 1292 Incorrect time value: '1997-12-31 25:59:59.000001' select microsecond("1997-12-31 23:59:59.000001"); microsecond("1997-12-31 23:59:59.000001") 1 diff --git a/mysql-test/main/func_time.result b/mysql-test/main/func_time.result index a6def9e70b0..a6e1ed9cb19 100644 --- a/mysql-test/main/func_time.result +++ b/mysql-test/main/func_time.result @@ -941,7 +941,7 @@ f1 select f1 from t1 where cast("2006-1-1" as date) between f1 and cast('zzz' as date); f1 Warnings: -Warning 1292 Incorrect datetime value: 'zzz' +Warning 1292 Truncated incorrect datetime value: 'zzz' select f1 from t1 where makedate(2006,1) between date(f1) and date(f3); f1 2006-01-01 @@ -1105,7 +1105,7 @@ week(20061108), week(20061108.01), week(20061108085411.000002); isnull(week(now() + 0)) isnull(week(now() + 0.2)) week(20061108) week(20061108.01) week(20061108085411.000002) 0 0 45 45 45 Warnings: -Note 1292 Truncated incorrect datetime value: '20061108.01' +Note 1292 Truncated incorrect date value: '20061108.01' End of 4.1 tests select time_format('100:00:00', '%H %k %h %I %l'); time_format('100:00:00', '%H %k %h %I %l') @@ -1382,9 +1382,9 @@ SELECT COUNT(*) FROM t1 GROUP BY TIME_TO_SEC(a); COUNT(*) 2 Warnings: -Warning 1292 Truncated incorrect time value: '' -Warning 1292 Truncated incorrect time value: '' -Warning 1292 Truncated incorrect time value: '' +Warning 1292 Incorrect time value: '' +Warning 1292 Incorrect time value: '' +Warning 1292 Incorrect time value: '' DROP TABLE t1; # # Bug#11766112 59151:UNINITIALIZED VALUES IN EXTRACT_DATE_TIME WITH STR_TO_DATE(SPACE(..) ... @@ -1735,7 +1735,7 @@ select 1 from t1 where 1 < some (select cast(a as datetime) from t1); 1 1 Warnings: -Warning 1292 Incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '1' drop table t1; SET timestamp=DEFAULT; # @@ -1842,7 +1842,7 @@ select cast('131415.123e0' as time); cast('131415.123e0' as time) NULL Warnings: -Warning 1292 Truncated incorrect time value: '131415.123e0' +Warning 1292 Incorrect time value: '131415.123e0' select cast('2010-01-02 03:04:05' as datetime) between null and '2010-01-02 03:04:04'; cast('2010-01-02 03:04:05' as datetime) between null and '2010-01-02 03:04:04' 0 @@ -1918,7 +1918,7 @@ select least(1, f1) from t1; least(1, f1) 0000-00-00 00:00:00 Warnings: -Warning 1292 Incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '1' drop table t1; SET timestamp=UNIX_TIMESTAMP('2014-04-14 10:10:10'); select now() > coalesce(time('21:43:24'), date('2010-05-03')); @@ -6095,14 +6095,14 @@ SELECT TIME('42949672955959-01'), TIME('42949672965959-01'); TIME('42949672955959-01') TIME('42949672965959-01') NULL NULL Warnings: -Warning 1292 Truncated incorrect time value: '42949672955959-01' -Warning 1292 Truncated incorrect time value: '42949672965959-01' +Warning 1292 Incorrect time value: '42949672955959-01' +Warning 1292 Incorrect time value: '42949672965959-01' SELECT TIME('18446744073709551615-01'), TIME('18446744073709551616-01'); TIME('18446744073709551615-01') TIME('18446744073709551616-01') NULL NULL Warnings: -Warning 1292 Truncated incorrect time value: '18446744073709551615-01' -Warning 1292 Truncated incorrect time value: '18446744073709551616-01' +Warning 1292 Incorrect time value: '18446744073709551615-01' +Warning 1292 Incorrect time value: '18446744073709551616-01' # # MDEV-17434 EXTRACT(DAY FROM negative_time) returns wrong result # @@ -6158,7 +6158,7 @@ SELECT TIME('-2001-01-01 10:20:30'); TIME('-2001-01-01 10:20:30') NULL Warnings: -Warning 1292 Truncated incorrect time value: '-2001-01-01 10:20:30' +Warning 1292 Incorrect time value: '-2001-01-01 10:20:30' SELECT TIME('2001-01-01') AS c1, TIME('2001-01-01 ') AS c2; c1 c2 00:20:01 00:20:01 @@ -6210,20 +6210,20 @@ SELECT TIME('-xxx'), TIME('-xxxxxxxxxxxxxxxxxxxx'); TIME('-xxx') TIME('-xxxxxxxxxxxxxxxxxxxx') NULL NULL Warnings: -Warning 1292 Truncated incorrect time value: '-xxx' -Warning 1292 Truncated incorrect time value: '-xxxxxxxxxxxxxxxxxxxx' +Warning 1292 Incorrect time value: '-xxx' +Warning 1292 Incorrect time value: '-xxxxxxxxxxxxxxxxxxxx' SELECT TIME('- '), TIME('- '); TIME('- ') TIME('- ') NULL NULL Warnings: -Warning 1292 Truncated incorrect time value: '- ' -Warning 1292 Truncated incorrect time value: '- ' +Warning 1292 Incorrect time value: '- ' +Warning 1292 Incorrect time value: '- ' SELECT TIME('-'), TIME('-'); TIME('-') TIME('-') NULL NULL Warnings: -Warning 1292 Truncated incorrect time value: '-' -Warning 1292 Truncated incorrect time value: '-' +Warning 1292 Incorrect time value: '-' +Warning 1292 Incorrect time value: '-' SELECT TIME('1-1-1 1:1:1'), TIME('1-1-1 1:1:1.0'); TIME('1-1-1 1:1:1') TIME('1-1-1 1:1:1.0') 01:01:01 01:01:01.0 diff --git a/mysql-test/main/multi_update.result b/mysql-test/main/multi_update.result index c40de47668a..9f9af8f79f8 100644 --- a/mysql-test/main/multi_update.result +++ b/mysql-test/main/multi_update.result @@ -603,11 +603,11 @@ CREATE TABLE t1 (f1 DATE); INSERT INTO t1 VALUES('2001-01-01'); UPDATE IGNORE (SELECT 1 FROM t1 WHERE f1 = (SELECT f1() FROM t1)) x, t1 SET f1 = 1; Warnings: -Warning 1292 Incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '1' CREATE view v1 as SELECT f1() FROM t1; UPDATE IGNORE (SELECT 1 FROM t1 WHERE f1 = (select * from v1)) x, t1 SET f1 = 1; Warnings: -Warning 1292 Incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '1' DROP VIEW v1; DROP FUNCTION f1; DROP TABLE t1; diff --git a/mysql-test/main/null.result b/mysql-test/main/null.result index 2fa89a2d001..6601c5e1ed4 100644 --- a/mysql-test/main/null.result +++ b/mysql-test/main/null.result @@ -515,9 +515,9 @@ NULLIF(TIMESTAMP'2001-01-01 00:00:00',1e0), NULLIF(TIMESTAMP'2001-01-01 00:00:00','2001-01-01'), NULLIF(TIMESTAMP'2001-01-01 00:00:00',TIME'00:00:00'); Warnings: -Warning 1292 Incorrect datetime value: '1' -Warning 1292 Incorrect datetime value: '1.0' -Warning 1292 Incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '1.0' +Warning 1292 Truncated incorrect datetime value: '1' SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( @@ -536,9 +536,9 @@ NULLIF(DATE'2001-01-01',1e0), NULLIF(DATE'2001-01-01','2001-01-01'), NULLIF(DATE'2001-01-01',TIME'00:00:00'); Warnings: -Warning 1292 Incorrect datetime value: '1' -Warning 1292 Incorrect datetime value: '1.0' -Warning 1292 Incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '1.0' +Warning 1292 Truncated incorrect datetime value: '1' SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( @@ -1640,8 +1640,8 @@ CASE WHEN TIMESTAMP'2001-01-01 00:00:00'=1 THEN NULL ELSE TIMESTAMP'2001-01-01 00:00:00' END AS b; Warnings: -Warning 1292 Incorrect datetime value: '1' -Warning 1292 Incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '1' DROP TABLE t1; # # MDEV-8785 Wrong results for EXPLAIN EXTENDED...WHERE NULLIF(latin1_col, _utf8'a' COLLATE utf8_bin) IS NOT NULL diff --git a/mysql-test/main/range.result b/mysql-test/main/range.result index 464c0bf031a..50de308045b 100644 --- a/mysql-test/main/range.result +++ b/mysql-test/main/range.result @@ -1101,7 +1101,7 @@ id select_type table type possible_keys key key_len ref rows Extra SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00'; item started price Warnings: -Warning 1292 Incorrect datetime value: '2005-12-01 24:00:00' +Warning 1292 Truncated incorrect datetime value: '2005-12-01 24:00:00' SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00'; item started price A1 2005-11-01 08:00:00 1000.000 @@ -1113,7 +1113,7 @@ id select_type table type possible_keys key key_len ref rows Extra SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00'; item started price Warnings: -Warning 1292 Incorrect datetime value: '2005-12-01 24:00:00' +Warning 1292 Truncated incorrect datetime value: '2005-12-01 24:00:00' SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00'; item started price A1 2005-11-01 08:00:00 1000.000 @@ -1563,7 +1563,7 @@ str_to_date('2007-10-00', '%Y-%m-%d') >= '' AND str_to_date('2007-10-00', '%Y-%m-%d') <= '2007/10/20' 1 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' SELECT str_to_date('2007-20-00', '%Y-%m-%d') >= '2007/10/20' AND str_to_date('2007-20-00', '%Y-%m-%d') <= ''; str_to_date('2007-20-00', '%Y-%m-%d') >= '2007/10/20' AND @@ -1578,7 +1578,7 @@ SELECT str_to_date('2007-10-00', '%Y-%m-%d') BETWEEN '' AND '2007/10/20'; str_to_date('2007-10-00', '%Y-%m-%d') BETWEEN '' AND '2007/10/20' 1 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' SELECT str_to_date('2007-20-00', '%Y-%m-%d') BETWEEN '2007/10/20' AND ''; str_to_date('2007-20-00', '%Y-%m-%d') BETWEEN '2007/10/20' AND '' NULL diff --git a/mysql-test/main/range_mrr_icp.result b/mysql-test/main/range_mrr_icp.result index b132e63b732..a6c57378f9c 100644 --- a/mysql-test/main/range_mrr_icp.result +++ b/mysql-test/main/range_mrr_icp.result @@ -1103,7 +1103,7 @@ id select_type table type possible_keys key key_len ref rows Extra SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00'; item started price Warnings: -Warning 1292 Incorrect datetime value: '2005-12-01 24:00:00' +Warning 1292 Truncated incorrect datetime value: '2005-12-01 24:00:00' SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00'; item started price A1 2005-11-01 08:00:00 1000.000 @@ -1115,7 +1115,7 @@ id select_type table type possible_keys key key_len ref rows Extra SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00'; item started price Warnings: -Warning 1292 Incorrect datetime value: '2005-12-01 24:00:00' +Warning 1292 Truncated incorrect datetime value: '2005-12-01 24:00:00' SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00'; item started price A1 2005-11-01 08:00:00 1000.000 @@ -1565,7 +1565,7 @@ str_to_date('2007-10-00', '%Y-%m-%d') >= '' AND str_to_date('2007-10-00', '%Y-%m-%d') <= '2007/10/20' 1 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' SELECT str_to_date('2007-20-00', '%Y-%m-%d') >= '2007/10/20' AND str_to_date('2007-20-00', '%Y-%m-%d') <= ''; str_to_date('2007-20-00', '%Y-%m-%d') >= '2007/10/20' AND @@ -1580,7 +1580,7 @@ SELECT str_to_date('2007-10-00', '%Y-%m-%d') BETWEEN '' AND '2007/10/20'; str_to_date('2007-10-00', '%Y-%m-%d') BETWEEN '' AND '2007/10/20' 1 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' SELECT str_to_date('2007-20-00', '%Y-%m-%d') BETWEEN '2007/10/20' AND ''; str_to_date('2007-20-00', '%Y-%m-%d') BETWEEN '2007/10/20' AND '' NULL diff --git a/mysql-test/main/select.result b/mysql-test/main/select.result index 9b6a570717b..94a92315acc 100644 --- a/mysql-test/main/select.result +++ b/mysql-test/main/select.result @@ -2118,8 +2118,8 @@ INSERT INTO t2 VALUES (1,3,10,'2002-06-01 08:00:00',35),(1,3,1010,'2002-06-01 12 SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= 'wrong-date-value' AND b.sampletime < 'wrong-date-value' AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid; gvid the_success the_fail the_size the_time Warnings: -Warning 1292 Incorrect datetime value: 'wrong-date-value' -Warning 1292 Incorrect datetime value: 'wrong-date-value' +Warning 1292 Truncated incorrect datetime value: 'wrong-date-value' +Warning 1292 Truncated incorrect datetime value: 'wrong-date-value' SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= NULL AND b.sampletime < NULL AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid; gvid the_success the_fail the_size the_time DROP TABLE t1,t2; @@ -4111,7 +4111,7 @@ select str_to_date('2007-10-09','%Y-%m-%d') <= '2007/10/2000:00:00 GMT-6'; str_to_date('2007-10-09','%Y-%m-%d') <= '2007/10/2000:00:00 GMT-6' 0 Warnings: -Warning 1292 Incorrect datetime value: '2007/10/2000:00:00 GMT-6' +Warning 1292 Truncated incorrect datetime value: '2007/10/2000:00:00 GMT-6' select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-1 00:00:00 GMT-6'; str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-1 00:00:00 GMT-6' 1 @@ -4198,7 +4198,7 @@ select str_to_date('2007-10-00','%Y-%m-%d') between '' and '2007/10/20'; str_to_date('2007-10-00','%Y-%m-%d') between '' and '2007/10/20' 1 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' select str_to_date('','%Y-%m-%d') between '2007/10/01' and '2007/10/20'; str_to_date('','%Y-%m-%d') between '2007/10/01' and '2007/10/20' 0 @@ -4212,22 +4212,22 @@ select str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = ''; str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '' 0 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' select str_to_date('1','%Y-%m-%d') = '1'; str_to_date('1','%Y-%m-%d') = '1' 0 Warnings: -Warning 1292 Incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '1' select str_to_date('1','%Y-%m-%d') = '1'; str_to_date('1','%Y-%m-%d') = '1' 0 Warnings: -Warning 1292 Incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '1' select str_to_date('','%Y-%m-%d') = ''; str_to_date('','%Y-%m-%d') = '' 1 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' select str_to_date('2000-01-01','%Y-%m-%d') between '1000-01-01' and '2001-01-01'; str_to_date('2000-01-01','%Y-%m-%d') between '1000-01-01' and '2001-01-01' 1 @@ -5282,30 +5282,30 @@ SELECT * FROM t1 HAVING f1 = 'zz'; f1 0000-00-00 Warnings: -Warning 1292 Incorrect datetime value: 'zz' +Warning 1292 Truncated incorrect datetime value: 'zz' SELECT * FROM t1 HAVING f1 <= 'aa' ; f1 0000-00-00 Warnings: -Warning 1292 Incorrect datetime value: 'aa' +Warning 1292 Truncated incorrect datetime value: 'aa' SELECT * FROM t1 HAVING f1 = 'zz' AND f1 <= 'aa' ; f1 0000-00-00 Warnings: -Warning 1292 Incorrect datetime value: 'zz' -Warning 1292 Incorrect datetime value: 'aa' +Warning 1292 Truncated incorrect datetime value: 'zz' +Warning 1292 Truncated incorrect datetime value: 'aa' SELECT * FROM t1 WHERE f1 = 'zz' AND f1 <= 'aa' ; f1 0000-00-00 Warnings: -Warning 1292 Incorrect datetime value: 'zz' -Warning 1292 Incorrect datetime value: 'aa' +Warning 1292 Truncated incorrect datetime value: 'zz' +Warning 1292 Truncated incorrect datetime value: 'aa' SELECT * FROM v1 HAVING f1 = 'zz' AND f1 <= 'aa' ; f1 0000-00-00 Warnings: -Warning 1292 Incorrect datetime value: 'zz' -Warning 1292 Incorrect datetime value: 'aa' +Warning 1292 Truncated incorrect datetime value: 'zz' +Warning 1292 Truncated incorrect datetime value: 'aa' DROP TABLE t1; DROP VIEW v1; # diff --git a/mysql-test/main/select_jcl6.result b/mysql-test/main/select_jcl6.result index d78fad15da1..b45fb8c4c10 100644 --- a/mysql-test/main/select_jcl6.result +++ b/mysql-test/main/select_jcl6.result @@ -2129,8 +2129,8 @@ INSERT INTO t2 VALUES (1,3,10,'2002-06-01 08:00:00',35),(1,3,1010,'2002-06-01 12 SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= 'wrong-date-value' AND b.sampletime < 'wrong-date-value' AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid; gvid the_success the_fail the_size the_time Warnings: -Warning 1292 Incorrect datetime value: 'wrong-date-value' -Warning 1292 Incorrect datetime value: 'wrong-date-value' +Warning 1292 Truncated incorrect datetime value: 'wrong-date-value' +Warning 1292 Truncated incorrect datetime value: 'wrong-date-value' SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= NULL AND b.sampletime < NULL AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid; gvid the_success the_fail the_size the_time DROP TABLE t1,t2; @@ -4122,7 +4122,7 @@ select str_to_date('2007-10-09','%Y-%m-%d') <= '2007/10/2000:00:00 GMT-6'; str_to_date('2007-10-09','%Y-%m-%d') <= '2007/10/2000:00:00 GMT-6' 0 Warnings: -Warning 1292 Incorrect datetime value: '2007/10/2000:00:00 GMT-6' +Warning 1292 Truncated incorrect datetime value: '2007/10/2000:00:00 GMT-6' select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-1 00:00:00 GMT-6'; str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-1 00:00:00 GMT-6' 1 @@ -4209,7 +4209,7 @@ select str_to_date('2007-10-00','%Y-%m-%d') between '' and '2007/10/20'; str_to_date('2007-10-00','%Y-%m-%d') between '' and '2007/10/20' 1 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' select str_to_date('','%Y-%m-%d') between '2007/10/01' and '2007/10/20'; str_to_date('','%Y-%m-%d') between '2007/10/01' and '2007/10/20' 0 @@ -4223,22 +4223,22 @@ select str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = ''; str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '' 0 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' select str_to_date('1','%Y-%m-%d') = '1'; str_to_date('1','%Y-%m-%d') = '1' 0 Warnings: -Warning 1292 Incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '1' select str_to_date('1','%Y-%m-%d') = '1'; str_to_date('1','%Y-%m-%d') = '1' 0 Warnings: -Warning 1292 Incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '1' select str_to_date('','%Y-%m-%d') = ''; str_to_date('','%Y-%m-%d') = '' 1 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' select str_to_date('2000-01-01','%Y-%m-%d') between '1000-01-01' and '2001-01-01'; str_to_date('2000-01-01','%Y-%m-%d') between '1000-01-01' and '2001-01-01' 1 @@ -5293,30 +5293,30 @@ SELECT * FROM t1 HAVING f1 = 'zz'; f1 0000-00-00 Warnings: -Warning 1292 Incorrect datetime value: 'zz' +Warning 1292 Truncated incorrect datetime value: 'zz' SELECT * FROM t1 HAVING f1 <= 'aa' ; f1 0000-00-00 Warnings: -Warning 1292 Incorrect datetime value: 'aa' +Warning 1292 Truncated incorrect datetime value: 'aa' SELECT * FROM t1 HAVING f1 = 'zz' AND f1 <= 'aa' ; f1 0000-00-00 Warnings: -Warning 1292 Incorrect datetime value: 'zz' -Warning 1292 Incorrect datetime value: 'aa' +Warning 1292 Truncated incorrect datetime value: 'zz' +Warning 1292 Truncated incorrect datetime value: 'aa' SELECT * FROM t1 WHERE f1 = 'zz' AND f1 <= 'aa' ; f1 0000-00-00 Warnings: -Warning 1292 Incorrect datetime value: 'zz' -Warning 1292 Incorrect datetime value: 'aa' +Warning 1292 Truncated incorrect datetime value: 'zz' +Warning 1292 Truncated incorrect datetime value: 'aa' SELECT * FROM v1 HAVING f1 = 'zz' AND f1 <= 'aa' ; f1 0000-00-00 Warnings: -Warning 1292 Incorrect datetime value: 'zz' -Warning 1292 Incorrect datetime value: 'aa' +Warning 1292 Truncated incorrect datetime value: 'zz' +Warning 1292 Truncated incorrect datetime value: 'aa' DROP TABLE t1; DROP VIEW v1; # diff --git a/mysql-test/main/select_pkeycache.result b/mysql-test/main/select_pkeycache.result index 9b6a570717b..94a92315acc 100644 --- a/mysql-test/main/select_pkeycache.result +++ b/mysql-test/main/select_pkeycache.result @@ -2118,8 +2118,8 @@ INSERT INTO t2 VALUES (1,3,10,'2002-06-01 08:00:00',35),(1,3,1010,'2002-06-01 12 SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= 'wrong-date-value' AND b.sampletime < 'wrong-date-value' AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid; gvid the_success the_fail the_size the_time Warnings: -Warning 1292 Incorrect datetime value: 'wrong-date-value' -Warning 1292 Incorrect datetime value: 'wrong-date-value' +Warning 1292 Truncated incorrect datetime value: 'wrong-date-value' +Warning 1292 Truncated incorrect datetime value: 'wrong-date-value' SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= NULL AND b.sampletime < NULL AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid; gvid the_success the_fail the_size the_time DROP TABLE t1,t2; @@ -4111,7 +4111,7 @@ select str_to_date('2007-10-09','%Y-%m-%d') <= '2007/10/2000:00:00 GMT-6'; str_to_date('2007-10-09','%Y-%m-%d') <= '2007/10/2000:00:00 GMT-6' 0 Warnings: -Warning 1292 Incorrect datetime value: '2007/10/2000:00:00 GMT-6' +Warning 1292 Truncated incorrect datetime value: '2007/10/2000:00:00 GMT-6' select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-1 00:00:00 GMT-6'; str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-1 00:00:00 GMT-6' 1 @@ -4198,7 +4198,7 @@ select str_to_date('2007-10-00','%Y-%m-%d') between '' and '2007/10/20'; str_to_date('2007-10-00','%Y-%m-%d') between '' and '2007/10/20' 1 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' select str_to_date('','%Y-%m-%d') between '2007/10/01' and '2007/10/20'; str_to_date('','%Y-%m-%d') between '2007/10/01' and '2007/10/20' 0 @@ -4212,22 +4212,22 @@ select str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = ''; str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '' 0 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' select str_to_date('1','%Y-%m-%d') = '1'; str_to_date('1','%Y-%m-%d') = '1' 0 Warnings: -Warning 1292 Incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '1' select str_to_date('1','%Y-%m-%d') = '1'; str_to_date('1','%Y-%m-%d') = '1' 0 Warnings: -Warning 1292 Incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '1' select str_to_date('','%Y-%m-%d') = ''; str_to_date('','%Y-%m-%d') = '' 1 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' select str_to_date('2000-01-01','%Y-%m-%d') between '1000-01-01' and '2001-01-01'; str_to_date('2000-01-01','%Y-%m-%d') between '1000-01-01' and '2001-01-01' 1 @@ -5282,30 +5282,30 @@ SELECT * FROM t1 HAVING f1 = 'zz'; f1 0000-00-00 Warnings: -Warning 1292 Incorrect datetime value: 'zz' +Warning 1292 Truncated incorrect datetime value: 'zz' SELECT * FROM t1 HAVING f1 <= 'aa' ; f1 0000-00-00 Warnings: -Warning 1292 Incorrect datetime value: 'aa' +Warning 1292 Truncated incorrect datetime value: 'aa' SELECT * FROM t1 HAVING f1 = 'zz' AND f1 <= 'aa' ; f1 0000-00-00 Warnings: -Warning 1292 Incorrect datetime value: 'zz' -Warning 1292 Incorrect datetime value: 'aa' +Warning 1292 Truncated incorrect datetime value: 'zz' +Warning 1292 Truncated incorrect datetime value: 'aa' SELECT * FROM t1 WHERE f1 = 'zz' AND f1 <= 'aa' ; f1 0000-00-00 Warnings: -Warning 1292 Incorrect datetime value: 'zz' -Warning 1292 Incorrect datetime value: 'aa' +Warning 1292 Truncated incorrect datetime value: 'zz' +Warning 1292 Truncated incorrect datetime value: 'aa' SELECT * FROM v1 HAVING f1 = 'zz' AND f1 <= 'aa' ; f1 0000-00-00 Warnings: -Warning 1292 Incorrect datetime value: 'zz' -Warning 1292 Incorrect datetime value: 'aa' +Warning 1292 Truncated incorrect datetime value: 'zz' +Warning 1292 Truncated incorrect datetime value: 'aa' DROP TABLE t1; DROP VIEW v1; # diff --git a/mysql-test/main/str_to_datetime_457.result b/mysql-test/main/str_to_datetime_457.result index 41a8ee9bf90..a024b30944c 100644 --- a/mysql-test/main/str_to_datetime_457.result +++ b/mysql-test/main/str_to_datetime_457.result @@ -19,8 +19,8 @@ select extract(hour from '100000:02:03'), extract(hour from '100000:02:03 '); extract(hour from '100000:02:03') extract(hour from '100000:02:03 ') NULL NULL Warnings: -Warning 1292 Truncated incorrect time value: '100000:02:03' -Warning 1292 Truncated incorrect time value: '100000:02:03 ' +Warning 1292 Incorrect time value: '100000:02:03' +Warning 1292 Incorrect time value: '100000:02:03 ' # # backward compatibility craziness # diff --git a/mysql-test/main/type_date.result b/mysql-test/main/type_date.result index 950672161fd..2c268cfdd88 100644 --- a/mysql-test/main/type_date.result +++ b/mysql-test/main/type_date.result @@ -621,7 +621,7 @@ SELECT * FROM t1 WHERE LENGTH(a)=11+RAND() AND a=' garbage '; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Warning 1292 Incorrect datetime value: ' garbage ' +Warning 1292 Truncated incorrect datetime value: ' garbage ' Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = DATE'0000-00-00' and <cache>(octet_length(DATE'0000-00-00')) = 11 + rand() DROP TABLE t1; CREATE TABLE t1 (a DATE); @@ -970,7 +970,7 @@ SELECT CAST(20061108.01 AS DATE); CAST(20061108.01 AS DATE) 2006-11-08 Warnings: -Note 1292 Truncated incorrect datetime value: '20061108.01' +Note 1292 Truncated incorrect date value: '20061108.01' INSERT INTO t1 VALUES (20061108.01); Warnings: Note 1265 Data truncated for column 'a' at row 1 @@ -980,7 +980,7 @@ SELECT CAST(20061108.01 AS DATE); CAST(20061108.01 AS DATE) 2006-11-08 Warnings: -Note 1292 Truncated incorrect datetime value: '20061108.01' +Note 1292 Truncated incorrect date value: '20061108.01' CREATE TABLE t1 (a DATE); INSERT INTO t1 VALUES (20061108.01); Warnings: diff --git a/mysql-test/main/type_datetime.result b/mysql-test/main/type_datetime.result index f75b8d84f48..7a213842e03 100644 --- a/mysql-test/main/type_datetime.result +++ b/mysql-test/main/type_datetime.result @@ -399,7 +399,7 @@ if(@bug28261 = f1, '', @bug28261:= f1) 2001-01-01 2002-02-02 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' select if(@bug28261 = f1, '', @bug28261:= f1) from t1; if(@bug28261 = f1, '', @bug28261:= f1) 2001-01-01 @@ -423,11 +423,11 @@ f1 2001-01-01 00:00:00 2002-02-02 00:00:00 Warnings: -Warning 1292 Incorrect datetime value: '2002010' +Warning 1292 Truncated incorrect datetime value: '2002010' select * from t1 where f1 between 20020101 and 2007010100000; f1 Warnings: -Warning 1292 Incorrect datetime value: '2007010100000' +Warning 1292 Truncated incorrect datetime value: '2007010100000' drop table t1; # # Bug#27216: functions with parameters of different date types may @@ -498,7 +498,7 @@ f1 45:44:44 15:44:44 Warnings: -Warning 1292 Incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '1' drop table t1; create table t1 (a tinyint); insert into t1 values (), (), (); @@ -575,18 +575,18 @@ CAST('NULL' AS DATE) < CAST('NULL' AS DATE) n9; n1 n2 n3 n4 n5 n6 n7 n8 n9 0 0 1 1 1 0 1 0 0 Warnings: -Warning 1292 Incorrect datetime value: 'NULL' -Warning 1292 Incorrect datetime value: 'NULL' -Warning 1292 Incorrect datetime value: 'NULL' -Warning 1292 Incorrect datetime value: 'NULL' -Warning 1292 Incorrect datetime value: 'NULL' -Warning 1292 Incorrect datetime value: 'NULL' -Warning 1292 Incorrect datetime value: 'NULL' -Warning 1292 Incorrect datetime value: 'NULL' -Warning 1292 Incorrect datetime value: 'NULL' -Warning 1292 Incorrect datetime value: 'NULL' -Warning 1292 Incorrect datetime value: 'NULL' -Warning 1292 Incorrect datetime value: 'NULL' +Warning 1292 Truncated incorrect datetime value: 'NULL' +Warning 1292 Truncated incorrect datetime value: 'NULL' +Warning 1292 Truncated incorrect datetime value: 'NULL' +Warning 1292 Truncated incorrect datetime value: 'NULL' +Warning 1292 Truncated incorrect datetime value: 'NULL' +Warning 1292 Truncated incorrect datetime value: 'NULL' +Warning 1292 Truncated incorrect datetime value: 'NULL' +Warning 1292 Truncated incorrect datetime value: 'NULL' +Warning 1292 Truncated incorrect datetime value: 'NULL' +Warning 1292 Truncated incorrect datetime value: 'NULL' +Warning 1292 Truncated incorrect datetime value: 'NULL' +Warning 1292 Truncated incorrect datetime value: 'NULL' End of 5.0 tests set @org_mode=@@sql_mode; create table t1 (da date default '1962-03-03 23:33:34', dt datetime default '1962-03-03'); @@ -1012,7 +1012,7 @@ SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a=' garbage '; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Warning 1292 Incorrect datetime value: ' garbage ' +Warning 1292 Truncated incorrect datetime value: ' garbage ' Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = TIMESTAMP'0000-00-00 00:00:00' and <cache>(octet_length(TIMESTAMP'0000-00-00 00:00:00')) = 30 + rand() DROP TABLE t1; CREATE TABLE t1 (a DATETIME);; @@ -1131,11 +1131,11 @@ INSERT INTO t1 VALUES ('00:00:00'),('00:01:00'); SELECT 1 FROM t1 WHERE 2016 > SOME (SELECT CAST(a AS DATETIME) FROM t1); 1 Warnings: -Warning 1292 Incorrect datetime value: '2016' +Warning 1292 Truncated incorrect datetime value: '2016' SELECT * FROM t1 WHERE 2016 > CAST(a AS DATETIME); a Warnings: -Warning 1292 Incorrect datetime value: '2016' +Warning 1292 Truncated incorrect datetime value: '2016' SELECT 1 FROM t1 WHERE 20160101 > SOME (SELECT CAST(a AS DATETIME) FROM t1); 1 1 @@ -1411,5 +1411,28 @@ CREATE TABLE t1 (a DATETIME); INSERT INTO t1 SELECT CAST(20010101 AS UNSIGNED); DROP TABLE t1; # +# MDEV-17563 Different results using table or view when comparing values of time type +# +CREATE TABLE t1 (pk int, x1 datetime, x2 varchar(1)); +INSERT INTO t1 VALUES (17,'2001-01-01 09:16:37',''); +INSERT INTO t1 VALUES (18,'2001-01-01 09:16:37','k'); +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT pk FROM t1 WHERE x1 >x2; +pk +17 +18 +Warnings: +Warning 1292 Truncated incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: 'k' +SELECT pk FROM v1 WHERE x1 >x2; +pk +17 +18 +Warnings: +Warning 1292 Truncated incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: 'k' +DROP VIEW v1; +DROP TABLE t1; +# # End of 10.4 tests # diff --git a/mysql-test/main/type_datetime.test b/mysql-test/main/type_datetime.test index 79f2a95b147..7bd7883f469 100644 --- a/mysql-test/main/type_datetime.test +++ b/mysql-test/main/type_datetime.test @@ -914,5 +914,19 @@ DROP TABLE t1; --echo # +--echo # MDEV-17563 Different results using table or view when comparing values of time type +--echo # + +CREATE TABLE t1 (pk int, x1 datetime, x2 varchar(1)); +INSERT INTO t1 VALUES (17,'2001-01-01 09:16:37',''); +INSERT INTO t1 VALUES (18,'2001-01-01 09:16:37','k'); +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT pk FROM t1 WHERE x1 >x2; +SELECT pk FROM v1 WHERE x1 >x2; +DROP VIEW v1; +DROP TABLE t1; + + +--echo # --echo # End of 10.4 tests --echo # diff --git a/mysql-test/main/type_temporal_innodb.result b/mysql-test/main/type_temporal_innodb.result index b869822722d..f8d8bc018bd 100644 --- a/mysql-test/main/type_temporal_innodb.result +++ b/mysql-test/main/type_temporal_innodb.result @@ -56,7 +56,7 @@ SELECT DATE'0000-00-00'=''; DATE'0000-00-00'='' 1 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' CREATE TABLE t1 (a ENUM('a'), b DATE, c INT, KEY(b)) ENGINE=InnoDB; INSERT IGNORE INTO t1 VALUES ('','0000-00-00',0); Warnings: @@ -65,49 +65,49 @@ SELECT * FROM t1 WHERE b=''; a b c 0000-00-00 0 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' SELECT * FROM t1 IGNORE KEY (b) WHERE b=''; a b c 0000-00-00 0 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' SELECT * FROM t1 WHERE a=b; a b c 0000-00-00 0 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b; 1 1 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' ALTER TABLE t1 ENGINE=MyISAM; SELECT * FROM t1 WHERE b=''; a b c 0000-00-00 0 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' SELECT * FROM t1 IGNORE KEY (b) WHERE b=''; a b c 0000-00-00 0 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' SELECT * FROM t1 WHERE a=b; a b c 0000-00-00 0 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b; 1 1 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' DROP TABLE t1; SELECT TIMESTAMP'0000-00-00 00:00:00'=''; TIMESTAMP'0000-00-00 00:00:00'='' 1 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' 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); Warnings: @@ -116,43 +116,43 @@ SELECT * FROM t1 WHERE b=''; a b c 0000-00-00 00:00:00 0 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' SELECT * FROM t1 IGNORE KEY (b) WHERE b=''; a b c 0000-00-00 00:00:00 0 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' SELECT * FROM t1 WHERE a=b; a b c 0000-00-00 00:00:00 0 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b; 1 1 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' ALTER TABLE t1 ENGINE=MyISAM; SELECT * FROM t1 WHERE b=''; a b c 0000-00-00 00:00:00 0 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' SELECT * FROM t1 IGNORE KEY (b) WHERE b=''; a b c 0000-00-00 00:00:00 0 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' SELECT * FROM t1 WHERE a=b; a b c 0000-00-00 00:00:00 0 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b; 1 1 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' DROP TABLE t1; CREATE TABLE t1 (d DATE) ENGINE=InnoDB; INSERT INTO t1 VALUES ('2012-12-21'); diff --git a/mysql-test/main/type_time.result b/mysql-test/main/type_time.result index e530298db23..0a66a94db69 100644 --- a/mysql-test/main/type_time.result +++ b/mysql-test/main/type_time.result @@ -2103,8 +2103,8 @@ TIME(0)=TIME('z') AS t; ts d t 1 1 1 Warnings: -Warning 1292 Incorrect datetime value: 'z' -Warning 1292 Incorrect datetime value: 'z' +Warning 1292 Truncated incorrect datetime value: 'z' +Warning 1292 Truncated incorrect datetime value: 'z' Warning 1292 Truncated incorrect time value: 'z' SELECT TIMESTAMP(0)=TIMESTAMP('') AS ts, @@ -2113,9 +2113,60 @@ TIME(0)=TIME('') AS t; ts d t 1 1 1 Warnings: -Warning 1292 Incorrect datetime value: '' -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' Warning 1292 Truncated incorrect time value: '' # +# MDEV-17563 Different results using table or view when comparing values of time type +# +CREATE TABLE t1 (pk int, x1 time, x2 varchar(1)); +INSERT INTO t1 VALUES (17,'09:16:37','k'),(70,'19:44:22','k'); +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT pk FROM t1 WHERE x1 >x2; +pk +17 +70 +Warnings: +Warning 1292 Truncated incorrect time value: 'k' +Warning 1292 Truncated incorrect time value: 'k' +SELECT pk FROM v1 WHERE x1 >x2; +pk +17 +70 +Warnings: +Warning 1292 Truncated incorrect time value: 'k' +Warning 1292 Truncated incorrect time value: 'k' +DROP VIEW v1; +DROP TABLE t1; +CREATE TABLE t1 (pk int, x1 time, x2 varchar(1)); +INSERT INTO t1 VALUES (17,'09:16:37',''),(70,'19:44:22','k'); +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT pk FROM t1 WHERE x1 >x2; +pk +17 +70 +Warnings: +Warning 1292 Truncated incorrect time value: '' +Warning 1292 Truncated incorrect time value: 'k' +SELECT pk FROM v1 WHERE x1 >x2; +pk +17 +70 +Warnings: +Warning 1292 Truncated incorrect time value: '' +Warning 1292 Truncated incorrect time value: 'k' +DROP VIEW IF EXISTS v1; +DROP TABLE IF EXISTS t1; +# +# MDEV-17625 Different warnings when comparing a garbage to DATETIME vs TIME +# +SELECT TIMESTAMP(0)='z', DATE(0)='z', TIME(0)='z'; +TIMESTAMP(0)='z' DATE(0)='z' TIME(0)='z' +1 1 1 +Warnings: +Warning 1292 Truncated incorrect datetime value: 'z' +Warning 1292 Truncated incorrect datetime value: 'z' +Warning 1292 Truncated incorrect time value: 'z' +# # End of 10.4 tests # diff --git a/mysql-test/main/type_time.test b/mysql-test/main/type_time.test index 1fe3d8ab0ee..5e4090f48a4 100644 --- a/mysql-test/main/type_time.test +++ b/mysql-test/main/type_time.test @@ -1379,6 +1379,36 @@ SELECT DATE(0)=DATE('') AS d, TIME(0)=TIME('') AS t; + +--echo # +--echo # MDEV-17563 Different results using table or view when comparing values of time type +--echo # + +CREATE TABLE t1 (pk int, x1 time, x2 varchar(1)); +INSERT INTO t1 VALUES (17,'09:16:37','k'),(70,'19:44:22','k'); +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT pk FROM t1 WHERE x1 >x2; +SELECT pk FROM v1 WHERE x1 >x2; +DROP VIEW v1; +DROP TABLE t1; + + +CREATE TABLE t1 (pk int, x1 time, x2 varchar(1)); +INSERT INTO t1 VALUES (17,'09:16:37',''),(70,'19:44:22','k'); +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT pk FROM t1 WHERE x1 >x2; +SELECT pk FROM v1 WHERE x1 >x2; +DROP VIEW IF EXISTS v1; +DROP TABLE IF EXISTS t1; + + +--echo # +--echo # MDEV-17625 Different warnings when comparing a garbage to DATETIME vs TIME +--echo # + +SELECT TIMESTAMP(0)='z', DATE(0)='z', TIME(0)='z'; + + --echo # --echo # End of 10.4 tests --echo # diff --git a/mysql-test/main/type_timestamp.result b/mysql-test/main/type_timestamp.result index 071b2181e73..a708ef5ec34 100644 --- a/mysql-test/main/type_timestamp.result +++ b/mysql-test/main/type_timestamp.result @@ -872,7 +872,7 @@ SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a=' garbage '; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Warning 1292 Incorrect datetime value: ' garbage ' +Warning 1292 Truncated incorrect datetime value: ' garbage ' Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = TIMESTAMP'0000-00-00 00:00:00' and <cache>(octet_length(TIMESTAMP'0000-00-00 00:00:00')) = 30 + rand() DROP TABLE t1; CREATE TABLE t1 (a TIMESTAMP);; diff --git a/mysql-test/suite/binlog_encryption/rpl_switch_stm_row_mixed.result b/mysql-test/suite/binlog_encryption/rpl_switch_stm_row_mixed.result index 2f7f1b07cb4..936f604be2e 100644 --- a/mysql-test/suite/binlog_encryption/rpl_switch_stm_row_mixed.result +++ b/mysql-test/suite/binlog_encryption/rpl_switch_stm_row_mixed.result @@ -140,7 +140,7 @@ create table t4 select * from t1 where 3 in (select 1 union select 2 union selec SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR create table t5 select * from t1 where 3 in (select 1 union select 2 union select curdate() union select 3); Warnings: -Warning 1292 Incorrect datetime value: '3' +Warning 1292 Truncated incorrect datetime value: '3' insert ignore into t5 select UUID() from t1 where 3 in (select 1 union select 2 union select 3 union select * from t4); create procedure foo() begin diff --git a/mysql-test/suite/funcs_1/r/innodb_func_view.result b/mysql-test/suite/funcs_1/r/innodb_func_view.result index c956ab1955e..45c04e32de8 100644 --- a/mysql-test/suite/funcs_1/r/innodb_func_view.result +++ b/mysql-test/suite/funcs_1/r/innodb_func_view.result @@ -3783,9 +3783,9 @@ NULL ---äÖüß@µ*$-- 4 -00:00:01 -1 5 41:58:00 1 17:58 23 Warnings: -Warning 1292 Truncated incorrect time value: '' -Warning 1292 Truncated incorrect time value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' -Warning 1292 Truncated incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' +Warning 1292 Incorrect time value: '' +Warning 1292 Incorrect time value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' +Warning 1292 Incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' SHOW CREATE VIEW v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(`t1_values`.`my_varbinary_1000` as time) AS `CAST(my_varbinary_1000 AS TIME)`,`t1_values`.`my_varbinary_1000` AS `my_varbinary_1000`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -3800,9 +3800,9 @@ NULL ---äÖüß@µ*$-- 4 -00:00:01 -1 5 41:58:00 1 17:58 23 Warnings: -Warning 1292 Truncated incorrect time value: '' -Warning 1292 Truncated incorrect time value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' -Warning 1292 Truncated incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' +Warning 1292 Incorrect time value: '' +Warning 1292 Incorrect time value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' +Warning 1292 Incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' DROP VIEW v1; @@ -3819,9 +3819,9 @@ NULL ---äÖüß@µ*$-- 4 -00:00:01 -1 5 41:58:00 1 17:58 22 Warnings: -Warning 1292 Truncated incorrect time value: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' -Warning 1292 Truncated incorrect time value: '<--------30 characters------->' -Warning 1292 Truncated incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +Warning 1292 Incorrect time value: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +Warning 1292 Incorrect time value: '<--------30 characters------->' +Warning 1292 Incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' Warning 1292 Truncated incorrect time value: '-1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' Warning 1292 Truncated incorrect time value: '1 17:58\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' SHOW CREATE VIEW v1; @@ -3838,9 +3838,9 @@ NULL ---äÖüß@µ*$-- -00:00:01 -1 41:58:00 1 17:58 Warnings: -Warning 1292 Truncated incorrect time value: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' -Warning 1292 Truncated incorrect time value: '<--------30 characters------->' -Warning 1292 Truncated incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +Warning 1292 Incorrect time value: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +Warning 1292 Incorrect time value: '<--------30 characters------->' +Warning 1292 Incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' Warning 1292 Truncated incorrect time value: '-1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' Warning 1292 Truncated incorrect time value: '1 17:58\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' DROP VIEW v1; @@ -3859,9 +3859,9 @@ NULL ---äÖüß@µ*$-- 4 -00:00:01 -1 5 41:58:00 1 17:58 21 Warnings: -Warning 1292 Truncated incorrect time value: '' -Warning 1292 Truncated incorrect time value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' -Warning 1292 Truncated incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' +Warning 1292 Incorrect time value: '' +Warning 1292 Incorrect time value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' +Warning 1292 Incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' SHOW CREATE VIEW v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(`t1_values`.`my_varchar_1000` as time) AS `CAST(my_varchar_1000 AS TIME)`,`t1_values`.`my_varchar_1000` AS `my_varchar_1000`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -3876,9 +3876,9 @@ NULL ---äÖüß@µ*$-- 4 -00:00:01 -1 5 41:58:00 1 17:58 21 Warnings: -Warning 1292 Truncated incorrect time value: '' -Warning 1292 Truncated incorrect time value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' -Warning 1292 Truncated incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' +Warning 1292 Incorrect time value: '' +Warning 1292 Incorrect time value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' +Warning 1292 Incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' DROP VIEW v1; @@ -3895,9 +3895,9 @@ NULL ---äÖüß@µ*$-- 4 -00:00:01 -1 5 41:58:00 1 17:58 20 Warnings: -Warning 1292 Truncated incorrect time value: '' -Warning 1292 Truncated incorrect time value: '<--------30 characters------->' -Warning 1292 Truncated incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$--' +Warning 1292 Incorrect time value: '' +Warning 1292 Incorrect time value: '<--------30 characters------->' +Warning 1292 Incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$--' SHOW CREATE VIEW v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(`t1_values`.`my_char_30` as time) AS `CAST(my_char_30 AS TIME)`,`t1_values`.`my_char_30` AS `my_char_30`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -3912,9 +3912,9 @@ NULL ---äÖüß@µ*$-- 4 -00:00:01 -1 5 41:58:00 1 17:58 20 Warnings: -Warning 1292 Truncated incorrect time value: '' -Warning 1292 Truncated incorrect time value: '<--------30 characters------->' -Warning 1292 Truncated incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$--' +Warning 1292 Incorrect time value: '' +Warning 1292 Incorrect time value: '<--------30 characters------->' +Warning 1292 Incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$--' DROP VIEW v1; diff --git a/mysql-test/suite/funcs_1/r/memory_func_view.result b/mysql-test/suite/funcs_1/r/memory_func_view.result index cd306b6b379..62c9a245010 100644 --- a/mysql-test/suite/funcs_1/r/memory_func_view.result +++ b/mysql-test/suite/funcs_1/r/memory_func_view.result @@ -3784,9 +3784,9 @@ NULL ---äÖüß@µ*$-- 4 -00:00:01 -1 5 41:58:00 1 17:58 23 Warnings: -Warning 1292 Truncated incorrect time value: '' -Warning 1292 Truncated incorrect time value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' -Warning 1292 Truncated incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' +Warning 1292 Incorrect time value: '' +Warning 1292 Incorrect time value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' +Warning 1292 Incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' SHOW CREATE VIEW v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(`t1_values`.`my_varbinary_1000` as time) AS `CAST(my_varbinary_1000 AS TIME)`,`t1_values`.`my_varbinary_1000` AS `my_varbinary_1000`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -3801,9 +3801,9 @@ NULL ---äÖüß@µ*$-- 4 -00:00:01 -1 5 41:58:00 1 17:58 23 Warnings: -Warning 1292 Truncated incorrect time value: '' -Warning 1292 Truncated incorrect time value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' -Warning 1292 Truncated incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' +Warning 1292 Incorrect time value: '' +Warning 1292 Incorrect time value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' +Warning 1292 Incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' DROP VIEW v1; @@ -3820,9 +3820,9 @@ NULL ---äÖüß@µ*$-- 4 -00:00:01 -1 5 41:58:00 1 17:58 22 Warnings: -Warning 1292 Truncated incorrect time value: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' -Warning 1292 Truncated incorrect time value: '<--------30 characters------->' -Warning 1292 Truncated incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +Warning 1292 Incorrect time value: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +Warning 1292 Incorrect time value: '<--------30 characters------->' +Warning 1292 Incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' Warning 1292 Truncated incorrect time value: '-1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' Warning 1292 Truncated incorrect time value: '1 17:58\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' SHOW CREATE VIEW v1; @@ -3839,9 +3839,9 @@ NULL ---äÖüß@µ*$-- -00:00:01 -1 41:58:00 1 17:58 Warnings: -Warning 1292 Truncated incorrect time value: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' -Warning 1292 Truncated incorrect time value: '<--------30 characters------->' -Warning 1292 Truncated incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +Warning 1292 Incorrect time value: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +Warning 1292 Incorrect time value: '<--------30 characters------->' +Warning 1292 Incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' Warning 1292 Truncated incorrect time value: '-1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' Warning 1292 Truncated incorrect time value: '1 17:58\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' DROP VIEW v1; @@ -3860,9 +3860,9 @@ NULL ---äÖüß@µ*$-- 4 -00:00:01 -1 5 41:58:00 1 17:58 21 Warnings: -Warning 1292 Truncated incorrect time value: '' -Warning 1292 Truncated incorrect time value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' -Warning 1292 Truncated incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' +Warning 1292 Incorrect time value: '' +Warning 1292 Incorrect time value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' +Warning 1292 Incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' SHOW CREATE VIEW v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(`t1_values`.`my_varchar_1000` as time) AS `CAST(my_varchar_1000 AS TIME)`,`t1_values`.`my_varchar_1000` AS `my_varchar_1000`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -3877,9 +3877,9 @@ NULL ---äÖüß@µ*$-- 4 -00:00:01 -1 5 41:58:00 1 17:58 21 Warnings: -Warning 1292 Truncated incorrect time value: '' -Warning 1292 Truncated incorrect time value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' -Warning 1292 Truncated incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' +Warning 1292 Incorrect time value: '' +Warning 1292 Incorrect time value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' +Warning 1292 Incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' DROP VIEW v1; @@ -3896,9 +3896,9 @@ NULL ---äÖüß@µ*$-- 4 -00:00:01 -1 5 41:58:00 1 17:58 20 Warnings: -Warning 1292 Truncated incorrect time value: '' -Warning 1292 Truncated incorrect time value: '<--------30 characters------->' -Warning 1292 Truncated incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$--' +Warning 1292 Incorrect time value: '' +Warning 1292 Incorrect time value: '<--------30 characters------->' +Warning 1292 Incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$--' SHOW CREATE VIEW v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(`t1_values`.`my_char_30` as time) AS `CAST(my_char_30 AS TIME)`,`t1_values`.`my_char_30` AS `my_char_30`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -3913,9 +3913,9 @@ NULL ---äÖüß@µ*$-- 4 -00:00:01 -1 5 41:58:00 1 17:58 20 Warnings: -Warning 1292 Truncated incorrect time value: '' -Warning 1292 Truncated incorrect time value: '<--------30 characters------->' -Warning 1292 Truncated incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$--' +Warning 1292 Incorrect time value: '' +Warning 1292 Incorrect time value: '<--------30 characters------->' +Warning 1292 Incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$--' DROP VIEW v1; diff --git a/mysql-test/suite/funcs_1/r/myisam_func_view.result b/mysql-test/suite/funcs_1/r/myisam_func_view.result index cd306b6b379..62c9a245010 100644 --- a/mysql-test/suite/funcs_1/r/myisam_func_view.result +++ b/mysql-test/suite/funcs_1/r/myisam_func_view.result @@ -3784,9 +3784,9 @@ NULL ---äÖüß@µ*$-- 4 -00:00:01 -1 5 41:58:00 1 17:58 23 Warnings: -Warning 1292 Truncated incorrect time value: '' -Warning 1292 Truncated incorrect time value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' -Warning 1292 Truncated incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' +Warning 1292 Incorrect time value: '' +Warning 1292 Incorrect time value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' +Warning 1292 Incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' SHOW CREATE VIEW v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(`t1_values`.`my_varbinary_1000` as time) AS `CAST(my_varbinary_1000 AS TIME)`,`t1_values`.`my_varbinary_1000` AS `my_varbinary_1000`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -3801,9 +3801,9 @@ NULL ---äÖüß@µ*$-- 4 -00:00:01 -1 5 41:58:00 1 17:58 23 Warnings: -Warning 1292 Truncated incorrect time value: '' -Warning 1292 Truncated incorrect time value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' -Warning 1292 Truncated incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' +Warning 1292 Incorrect time value: '' +Warning 1292 Incorrect time value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' +Warning 1292 Incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' DROP VIEW v1; @@ -3820,9 +3820,9 @@ NULL ---äÖüß@µ*$-- 4 -00:00:01 -1 5 41:58:00 1 17:58 22 Warnings: -Warning 1292 Truncated incorrect time value: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' -Warning 1292 Truncated incorrect time value: '<--------30 characters------->' -Warning 1292 Truncated incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +Warning 1292 Incorrect time value: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +Warning 1292 Incorrect time value: '<--------30 characters------->' +Warning 1292 Incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' Warning 1292 Truncated incorrect time value: '-1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' Warning 1292 Truncated incorrect time value: '1 17:58\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' SHOW CREATE VIEW v1; @@ -3839,9 +3839,9 @@ NULL ---äÖüß@µ*$-- -00:00:01 -1 41:58:00 1 17:58 Warnings: -Warning 1292 Truncated incorrect time value: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' -Warning 1292 Truncated incorrect time value: '<--------30 characters------->' -Warning 1292 Truncated incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +Warning 1292 Incorrect time value: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +Warning 1292 Incorrect time value: '<--------30 characters------->' +Warning 1292 Incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' Warning 1292 Truncated incorrect time value: '-1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' Warning 1292 Truncated incorrect time value: '1 17:58\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' DROP VIEW v1; @@ -3860,9 +3860,9 @@ NULL ---äÖüß@µ*$-- 4 -00:00:01 -1 5 41:58:00 1 17:58 21 Warnings: -Warning 1292 Truncated incorrect time value: '' -Warning 1292 Truncated incorrect time value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' -Warning 1292 Truncated incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' +Warning 1292 Incorrect time value: '' +Warning 1292 Incorrect time value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' +Warning 1292 Incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' SHOW CREATE VIEW v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(`t1_values`.`my_varchar_1000` as time) AS `CAST(my_varchar_1000 AS TIME)`,`t1_values`.`my_varchar_1000` AS `my_varchar_1000`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -3877,9 +3877,9 @@ NULL ---äÖüß@µ*$-- 4 -00:00:01 -1 5 41:58:00 1 17:58 21 Warnings: -Warning 1292 Truncated incorrect time value: '' -Warning 1292 Truncated incorrect time value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' -Warning 1292 Truncated incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' +Warning 1292 Incorrect time value: '' +Warning 1292 Incorrect time value: '<---------1000 characters-------------------------------------------------------------------------------------------------------' +Warning 1292 Incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$-- ' DROP VIEW v1; @@ -3896,9 +3896,9 @@ NULL ---äÖüß@µ*$-- 4 -00:00:01 -1 5 41:58:00 1 17:58 20 Warnings: -Warning 1292 Truncated incorrect time value: '' -Warning 1292 Truncated incorrect time value: '<--------30 characters------->' -Warning 1292 Truncated incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$--' +Warning 1292 Incorrect time value: '' +Warning 1292 Incorrect time value: '<--------30 characters------->' +Warning 1292 Incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$--' SHOW CREATE VIEW v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(`t1_values`.`my_char_30` as time) AS `CAST(my_char_30 AS TIME)`,`t1_values`.`my_char_30` AS `my_char_30`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -3913,9 +3913,9 @@ NULL ---äÖüß@µ*$-- 4 -00:00:01 -1 5 41:58:00 1 17:58 20 Warnings: -Warning 1292 Truncated incorrect time value: '' -Warning 1292 Truncated incorrect time value: '<--------30 characters------->' -Warning 1292 Truncated incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$--' +Warning 1292 Incorrect time value: '' +Warning 1292 Incorrect time value: '<--------30 characters------->' +Warning 1292 Incorrect time value: ' ---\xC3\xA4\xC3\x96\xC3\xBC\xC3\x9F@\xC2\xB5*$--' DROP VIEW v1; diff --git a/mysql-test/suite/gcol/r/gcol_bug20746926.result b/mysql-test/suite/gcol/r/gcol_bug20746926.result index 74fe76b3f1a..590caf02503 100644 --- a/mysql-test/suite/gcol/r/gcol_bug20746926.result +++ b/mysql-test/suite/gcol/r/gcol_bug20746926.result @@ -11,22 +11,22 @@ c timestamp generated always as ((a not in (b,b))) stored insert t1(a) values(7777777777); Warnings: Warning 1265 Data truncated for column 'a' at row 1 -Warning 1292 Incorrect datetime value: '0' +Warning 1292 Truncated incorrect datetime value: '0' show warnings; Level Code Message Warning 1265 Data truncated for column 'a' at row 1 -Warning 1292 Incorrect datetime value: '0' +Warning 1292 Truncated incorrect datetime value: '0' disconnect con1; connect con2,localhost,root,,; set sql_mode=''; insert t1(a) values(6666666666); Warnings: Warning 1265 Data truncated for column 'a' at row 1 -Warning 1292 Incorrect datetime value: '0' +Warning 1292 Truncated incorrect datetime value: '0' show warnings; Level Code Message Warning 1265 Data truncated for column 'a' at row 1 -Warning 1292 Incorrect datetime value: '0' +Warning 1292 Truncated incorrect datetime value: '0' drop table t1; disconnect con2; connection default; diff --git a/mysql-test/suite/rpl/r/rpl_switch_stm_row_mixed.result b/mysql-test/suite/rpl/r/rpl_switch_stm_row_mixed.result index 2f7f1b07cb4..936f604be2e 100644 --- a/mysql-test/suite/rpl/r/rpl_switch_stm_row_mixed.result +++ b/mysql-test/suite/rpl/r/rpl_switch_stm_row_mixed.result @@ -140,7 +140,7 @@ create table t4 select * from t1 where 3 in (select 1 union select 2 union selec SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR create table t5 select * from t1 where 3 in (select 1 union select 2 union select curdate() union select 3); Warnings: -Warning 1292 Incorrect datetime value: '3' +Warning 1292 Truncated incorrect datetime value: '3' insert ignore into t5 select UUID() from t1 where 3 in (select 1 union select 2 union select 3 union select * from t4); create procedure foo() begin diff --git a/mysql-test/suite/vcol/r/wrong_arena.result b/mysql-test/suite/vcol/r/wrong_arena.result index c105a069b7f..cd36801f601 100644 --- a/mysql-test/suite/vcol/r/wrong_arena.result +++ b/mysql-test/suite/vcol/r/wrong_arena.result @@ -7,9 +7,9 @@ d int as ((a,a) in ((1,1),(2,1),(NULL,1))), # cmp_item_datetime e int as ((a,1) in ((1,1),(2,1),(NULL,1))) # cmp_item_row::alloc_comparators() ); Warnings: -Warning 1292 Incorrect datetime value: '1' -Warning 1292 Incorrect datetime value: '2' -Warning 1292 Incorrect datetime value: '3' +Warning 1292 Truncated incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '2' +Warning 1292 Truncated incorrect datetime value: '3' show create table t1; Table Create Table t1 CREATE TABLE `t1` ( @@ -20,21 +20,21 @@ t1 CREATE TABLE `t1` ( `e` int(11) GENERATED ALWAYS AS ((`a`,1) in ((1,1),(2,1),(NULL,1))) VIRTUAL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 Warnings: -Warning 1292 Incorrect datetime value: '1' -Warning 1292 Incorrect datetime value: '2' -Warning 1292 Incorrect datetime value: '3' +Warning 1292 Truncated incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '2' +Warning 1292 Truncated incorrect datetime value: '3' connect con1, localhost, root; insert t1 (a) values ('2010-10-10 10:10:10'); select * from t1; a b c d e 2010-10-10 10:10:10 1 0 0 NULL Warnings: -Warning 1292 Incorrect datetime value: '1' -Warning 1292 Incorrect datetime value: '1' -Warning 1292 Incorrect datetime value: '2' -Warning 1292 Incorrect datetime value: '1' -Warning 1292 Incorrect datetime value: '1' -Warning 1292 Incorrect datetime value: '2' +Warning 1292 Truncated incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '2' +Warning 1292 Truncated incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '2' disconnect con1; connection default; select * from t1; @@ -50,14 +50,14 @@ select * from t1; a b 2010-10-10 10:10:10 0000-00-00 00:00:00 Warnings: -Warning 1292 Incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '1' disconnect con1; connection default; select * from t1; a b 2010-10-10 10:10:10 0000-00-00 00:00:00 Warnings: -Warning 1292 Incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '1' drop table t1; create table t1 ( id int not null , diff --git a/mysql-test/suite/versioning/r/partition.result b/mysql-test/suite/versioning/r/partition.result index 75efe62b5c6..f5106e03a14 100644 --- a/mysql-test/suite/versioning/r/partition.result +++ b/mysql-test/suite/versioning/r/partition.result @@ -435,7 +435,7 @@ partition_name partition_ordinal_position partition_method timediff(partition_de p0 1 SYSTEM_TIME 00:00:00.000000 pn 2 SYSTEM_TIME NULL Warnings: -Warning 1292 Truncated incorrect time value: 'CURRENT' +Warning 1292 Incorrect time value: 'CURRENT' alter table t1 add partition (partition p1 history, partition p2 history); select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1'; partition_name partition_ordinal_position partition_method timediff(partition_description, @ts) @@ -444,7 +444,7 @@ p1 2 SYSTEM_TIME 01:00:00.000000 p2 3 SYSTEM_TIME 02:00:00.000000 pn 4 SYSTEM_TIME NULL Warnings: -Warning 1292 Truncated incorrect time value: 'CURRENT' +Warning 1292 Incorrect time value: 'CURRENT' alter table t1 drop partition p0; select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1'; partition_name partition_ordinal_position partition_method timediff(partition_description, @ts) @@ -452,7 +452,7 @@ p1 1 SYSTEM_TIME 01:00:00.000000 p2 2 SYSTEM_TIME 02:00:00.000000 pn 3 SYSTEM_TIME NULL Warnings: -Warning 1292 Truncated incorrect time value: 'CURRENT' +Warning 1292 Incorrect time value: 'CURRENT' alter table t1 drop partition p2; ERROR HY000: Can only drop oldest partitions when rotating by INTERVAL select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1'; @@ -461,7 +461,7 @@ p1 1 SYSTEM_TIME 01:00:00.000000 p2 2 SYSTEM_TIME 02:00:00.000000 pn 3 SYSTEM_TIME NULL Warnings: -Warning 1292 Truncated incorrect time value: 'CURRENT' +Warning 1292 Incorrect time value: 'CURRENT' # # MDEV-15103 Assertion in ha_partition::part_records() for updating VIEW # diff --git a/sql-common/my_time.c b/sql-common/my_time.c index 4f03482f6e0..249ed48713a 100644 --- a/sql-common/my_time.c +++ b/sql-common/my_time.c @@ -118,6 +118,7 @@ my_bool check_date(const MYSQL_TIME *ltime, my_bool not_zero_date, We don't set *was_cut here to signal that the problem was a zero date and not an invalid date */ + *was_cut|= MYSQL_TIME_WARN_ZERO_DATE; return TRUE; } return FALSE; @@ -343,7 +344,7 @@ static my_bool find_body(my_bool *neg, const char *str, size_t length, *new_length= length; if (!length || !my_isdigit(&my_charset_latin1, *str)) { - *warn|= MYSQL_TIME_WARN_TRUNCATED; + *warn|= MYSQL_TIME_WARN_EDOM; set_zero_time(to, MYSQL_TIMESTAMP_ERROR); return TRUE; } @@ -702,7 +703,10 @@ str_to_datetime(const char *str, size_t length, MYSQL_TIME *l_time, if (rc) return rc; if ((l_time->neg= neg) && l_time->time_type != MYSQL_TIMESTAMP_TIME) + { + status->warnings|= MYSQL_TIME_WARN_OUT_OF_RANGE; return TRUE; + } return FALSE; } @@ -725,7 +729,10 @@ str_to_DDhhmmssff_internal(my_bool neg, const char *str, size_t length, { value=value*10L + (long) (*str - '0'); if (value >= 42949672955959ULL) /* i.e. UINT_MAX32 : 59 : 59 */ + { + status->warnings|= MYSQL_TIME_WARN_OUT_OF_RANGE; goto err; + } } /* Skip all space after 'days' */ @@ -746,7 +753,10 @@ str_to_DDhhmmssff_internal(my_bool neg, const char *str, size_t length, { date[0]= 0; /* Assume we found hours */ if (value >= UINT_MAX32) + { + status->warnings|= MYSQL_TIME_WARN_OUT_OF_RANGE; goto err; + } date[1]= (ulong) value; state=2; found_hours=1; @@ -1514,7 +1524,7 @@ longlong number_to_datetime(longlong nr, ulong sec_part, MYSQL_TIME *time_res, /* Don't want to have was_cut get set if NO_ZERO_DATE was violated. */ if (nr || !(flags & C_TIME_NO_ZERO_DATE)) - *was_cut= 1; + *was_cut= MYSQL_TIME_WARN_TRUNCATED; return -1; err: @@ -1523,7 +1533,7 @@ longlong number_to_datetime(longlong nr, ulong sec_part, MYSQL_TIME *time_res, enum enum_mysql_timestamp_type save= time_res->time_type; bzero((char*) time_res, sizeof(*time_res)); time_res->time_type= save; /* Restore range */ - *was_cut= 1; /* Found invalid date */ + *was_cut= MYSQL_TIME_WARN_TRUNCATED; /* Found invalid date */ } return -1; } diff --git a/sql/field.cc b/sql/field.cc index d7214687e2d..7e27ed1bfc3 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -2253,16 +2253,13 @@ uint Field::fill_cache_field(CACHE_FIELD *copy) } -bool Field::get_date(MYSQL_TIME *ltime,date_mode_t fuzzydate) -{ - char buff[40]; - String tmp(buff,sizeof(buff),&my_charset_bin),*res; - if (!(res=val_str(&tmp)) || - str_to_datetime_with_warn(get_thd(), - res->charset(), res->ptr(), res->length(), - ltime, fuzzydate)) - return 1; - return 0; +bool Field::get_date(MYSQL_TIME *to, date_mode_t mode) +{ + StringBuffer<40> tmp; + Temporal::Warn_push warn(get_thd(), NullS, to, mode); + Temporal_hybrid *t= new(to) Temporal_hybrid(get_thd(), &warn, + val_str(&tmp), mode); + return !t->is_valid_temporal(); } /** diff --git a/sql/field.h b/sql/field.h index d5b2a621d48..eb39b6bcec9 100644 --- a/sql/field.h +++ b/sql/field.h @@ -2077,8 +2077,9 @@ public: } bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return my_decimal(ptr, precision, dec). - to_datetime_with_warn(get_thd(), ltime, fuzzydate, field_name.str); + my_decimal nr(ptr, precision, dec); + return decimal_to_datetime_with_warn(get_thd(), &nr, ltime, + fuzzydate, field_name.str); } bool val_bool() { @@ -2612,9 +2613,10 @@ protected: int store_invalid_with_warning(const ErrConv *str, int was_cut, timestamp_type ts_type) { + DBUG_ASSERT(was_cut); reset(); Sql_condition::enum_warning_level level= Sql_condition::WARN_LEVEL_WARN; - if (was_cut == 0) // special case: zero date + if (was_cut & MYSQL_TIME_WARN_ZERO_DATE) { DBUG_ASSERT(ts_type != MYSQL_TIMESTAMP_TIME); set_warnings(level, str, MYSQL_TIME_WARN_OUT_OF_RANGE, ts_type); diff --git a/sql/item.cc b/sql/item.cc index 88bb929fc05..d4cfa790986 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1277,60 +1277,27 @@ Item *Item_param::safe_charset_converter(THD *thd, CHARSET_INFO *tocs) bool Item::get_date_from_int(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { Longlong_hybrid value(val_int(), unsigned_flag); - if (null_value || int_to_datetime_with_warn(thd, value, - ltime, fuzzydate, - field_name_or_null())) - return null_value|= make_zero_date(ltime, fuzzydate); - return null_value= false; + return null_value || int_to_datetime_with_warn(thd, value, + ltime, fuzzydate, + field_name_or_null()); } bool Item::get_date_from_real(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { double value= val_real(); - if (null_value || double_to_datetime_with_warn(thd, value, ltime, fuzzydate, - field_name_or_null())) - return null_value|= make_zero_date(ltime, fuzzydate); - return null_value= false; + return null_value || double_to_datetime_with_warn(thd, value, + ltime, fuzzydate, + field_name_or_null()); } -bool Item::get_date_from_string(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) +bool Item::get_date_from_string(THD *thd, MYSQL_TIME *to, date_mode_t mode) { - char buff[40]; - String tmp(buff,sizeof(buff), &my_charset_bin),*res; - if (!(res=val_str(&tmp)) || - str_to_datetime_with_warn(thd, res->charset(), res->ptr(), res->length(), - ltime, fuzzydate)) - return null_value|= make_zero_date(ltime, fuzzydate); - return null_value= false; -} - - -bool Item::make_zero_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) -{ - /* - if the item was not null and convertion failed, we return a zero date - if allowed, otherwise - null. - */ - bzero((char*) ltime,sizeof(*ltime)); - if (fuzzydate & TIME_TIME_ONLY) - { - /* - In the following scenario: - - The caller expected to get a TIME value - - Item returned a not NULL string or numeric value - - But then conversion from string or number to TIME failed - we need to change the default time_type from MYSQL_TIMESTAMP_DATE - (which was set in bzero) to MYSQL_TIMESTAMP_TIME and therefore - return TIME'00:00:00' rather than DATE'0000-00-00'. - If we don't do this, methods like Item::get_time_with_conversion() - will erroneously subtract CURRENT_DATE from '0000-00-00 00:00:00' - and return TIME'-838:59:59' instead of TIME'00:00:00' as a result. - */ - ltime->time_type= MYSQL_TIMESTAMP_TIME; - } - return !(fuzzydate & TIME_FUZZY_DATES); + StringBuffer<40> tmp; + Temporal::Warn_push warn(thd, field_name_or_null(), to, mode); + Temporal_hybrid *t= new(to) Temporal_hybrid(thd, &warn, val_str(&tmp), mode); + return !t->is_valid_temporal(); } @@ -3735,7 +3702,7 @@ my_decimal *Item_null::val_decimal(my_decimal *decimal_value) bool Item_null::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - make_zero_date(ltime, fuzzydate); + set_zero_time(ltime, MYSQL_TIMESTAMP_NONE); return (null_value= true); } @@ -4261,7 +4228,7 @@ bool Item_param::get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate) *res= value.time; return 0; } - return type_handler()->Item_get_date(thd, this, res, fuzzydate); + return type_handler()->Item_get_date_with_warn(thd, this, res, fuzzydate); } diff --git a/sql/item.h b/sql/item.h index d15dbade60f..c2666c35c67 100644 --- a/sql/item.h +++ b/sql/item.h @@ -870,12 +870,6 @@ protected: return rc; } public: - /* - This method is used if the item was not null but convertion to - TIME/DATE/DATETIME failed. We return a zero date if allowed, - otherwise - null. - */ - bool make_zero_date(MYSQL_TIME *ltime, date_mode_t fuzzydate); /* Cache val_str() into the own buffer, e.g. to evaluate constant @@ -1172,6 +1166,12 @@ public: If value is not null null_value flag will be reset to FALSE. */ virtual double val_real()=0; + Double_null to_double_null() + { + // val_real() must be caleed on a separate line. See to_longlong_null() + double nr= val_real(); + return Double_null(nr, null_value); + } /* Return integer representation of item. @@ -1193,6 +1193,10 @@ public: */ return Longlong_null(nr, null_value); } + Longlong_hybrid_null to_longlong_hybrid_null() + { + return Longlong_hybrid_null(to_longlong_null(), unsigned_flag); + } /** Get a value for CAST(x AS SIGNED). Too large positive unsigned integer values are converted @@ -3031,7 +3035,7 @@ public: Item *safe_charset_converter(THD *thd, CHARSET_INFO *tocs); bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return type_handler()->Item_get_date(thd, this, ltime, fuzzydate); + return type_handler()->Item_get_date_with_warn(thd, this, ltime, fuzzydate); } }; @@ -4516,7 +4520,7 @@ public: String *val_str(String*) { return &str_value; } bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return type_handler()->Item_get_date(thd, this, ltime, fuzzydate); + return type_handler()->Item_get_date_with_warn(thd, this, ltime, fuzzydate); } }; @@ -6389,10 +6393,9 @@ class Item_cache_year: public Item_cache_int public: Item_cache_year(THD *thd, const Type_handler *handler) :Item_cache_int(thd, handler) { } - bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *to, date_mode_t mode) { - return null_value= - VYear(this).to_mysql_time_with_warn(thd, ltime, fuzzydate, NULL); + return type_handler_year.Item_get_date_with_warn(thd, this, to, mode); } }; @@ -6549,8 +6552,10 @@ public: longlong val_int(); String* val_str(String *str); my_decimal *val_decimal(my_decimal *); - bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) - { return VDec(this).to_datetime_with_warn(thd, ltime, fuzzydate, this); } + bool get_date(THD *thd, MYSQL_TIME *to, date_mode_t mode) + { + return decimal_to_datetime_with_warn(thd, VDec(this).ptr(), to, mode, NULL); + } bool cache_value(); Item *convert_to_basic_const_item(THD *thd); Item *get_copy(THD *thd) diff --git a/sql/item_func.cc b/sql/item_func.cc index 20c0a2564bb..c176a7e43a7 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -831,17 +831,6 @@ Item_func_hybrid_field_type::val_decimal_from_int_op(my_decimal *dec) return dec; } -bool Item_func_hybrid_field_type::get_date_from_int_op(THD *thd, - MYSQL_TIME *ltime, - date_mode_t fuzzydate) -{ - Longlong_hybrid value(int_op(), unsigned_flag); - if (null_value || int_to_datetime_with_warn(thd, value, - ltime, fuzzydate, NULL)) - return make_zero_mysql_time(ltime, fuzzydate); - return (null_value= 0); -} - String *Item_func_hybrid_field_type::val_str_from_real_op(String *str) { @@ -867,17 +856,6 @@ Item_func_hybrid_field_type::val_decimal_from_real_op(my_decimal *dec) return dec; } -bool Item_func_hybrid_field_type::get_date_from_real_op(THD *thd, - MYSQL_TIME *ltime, - date_mode_t fuzzydate) -{ - double value= real_op(); - if (null_value || - double_to_datetime_with_warn(thd, value, ltime, fuzzydate, NULL)) - return make_zero_mysql_time(ltime, fuzzydate); - return (null_value= 0); -} - String *Item_func_hybrid_field_type::val_str_from_date_op(String *str) { @@ -975,19 +953,6 @@ Item_func_hybrid_field_type::val_decimal_from_str_op(my_decimal *decimal_value) return res ? decimal_from_string_with_check(decimal_value, res) : 0; } -bool Item_func_hybrid_field_type::get_date_from_str_op(THD *thd, - MYSQL_TIME *ltime, - date_mode_t fuzzydate) -{ - StringBuffer<40> tmp; - String *res; - if (!(res= str_op_with_null_check(&tmp)) || - str_to_datetime_with_warn(thd, res->charset(), res->ptr(), res->length(), - ltime, fuzzydate)) - return make_zero_mysql_time(ltime, fuzzydate); - return (null_value= 0); -} - void Item_func_signed::print(String *str, enum_query_type query_type) { diff --git a/sql/item_func.h b/sql/item_func.h index 602b13fad7a..660d39f48ea 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -680,11 +680,6 @@ class Item_func_hybrid_field_type: public Item_hybrid_func DBUG_ASSERT((res != NULL) ^ null_value); return res; } - bool make_zero_mysql_time(MYSQL_TIME *ltime, date_mode_t fuzzydate) - { - bzero(ltime, sizeof(*ltime)); - return null_value|= !(fuzzydate & TIME_FUZZY_DATES); - } public: // Value methods that involve no conversion @@ -723,10 +718,6 @@ public: double val_real_from_time_op(); double val_real_from_int_op(); - bool get_date_from_str_op(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); - bool get_date_from_real_op(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); - bool get_date_from_int_op(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); - public: Item_func_hybrid_field_type(THD *thd): Item_hybrid_func(thd) @@ -770,11 +761,11 @@ public: DBUG_ASSERT(null_value == (res == NULL)); return res; } - bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *to, date_mode_t mode) { DBUG_ASSERT(fixed); return Item_func_hybrid_field_type::type_handler()-> - Item_func_hybrid_field_type_get_date(thd, this, res, fuzzydate); + Item_func_hybrid_field_type_get_date_with_warn(thd, this, to, mode); } /** @@ -794,6 +785,10 @@ public: */ return Longlong_null(nr, null_value); } + Longlong_hybrid_null to_longlong_hybrid_null_op() + { + return Longlong_hybrid_null(to_longlong_null_op(), unsigned_flag); + } /** @brief Performs the operation that this functions implements when the @@ -802,6 +797,12 @@ public: @return The result of the operation. */ virtual double real_op()= 0; + Double_null to_double_null_op() + { + // val_real() must be caleed on a separate line. See to_longlong_null() + double nr= real_op(); + return Double_null(nr, null_value); + } /** @brief Performs the operation that this functions implements when the @@ -1180,8 +1181,10 @@ public: double val_real() { return VDec(this).to_double(); } longlong val_int() { return VDec(this).to_longlong(unsigned_flag); } my_decimal *val_decimal(my_decimal*); - bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) - { return VDec(this).to_datetime_with_warn(thd, ltime, fuzzydate, this); } + bool get_date(THD *thd, MYSQL_TIME *to, date_mode_t mode) + { + return decimal_to_datetime_with_warn(thd, VDec(this).ptr(), to, mode, NULL); + } const Type_handler *type_handler() const { return &type_handler_newdecimal; } void fix_length_and_dec_generic() {} bool fix_length_and_dec() @@ -2292,7 +2295,7 @@ public: } bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return type_handler()->Item_get_date(thd, this, ltime, fuzzydate); + return type_handler()->Item_get_date_with_warn(thd, this, ltime, fuzzydate); } }; @@ -2602,7 +2605,9 @@ public: { return create_table_field_from_handler(table); } bool check_vcol_func_processor(void *arg); bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) - { return type_handler()->Item_get_date(thd, this, ltime, fuzzydate); } + { + return type_handler()->Item_get_date_with_warn(thd, this, ltime, fuzzydate); + } }; @@ -2832,7 +2837,7 @@ public: { return val_decimal_from_real(dec_buf); } bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return type_handler()->Item_get_date(thd, this, ltime, fuzzydate); + return type_handler()->Item_get_date_with_warn(thd, this, ltime, fuzzydate); } /* TODO: fix to support views */ const char *func_name() const { return "get_system_var"; } diff --git a/sql/item_sum.h b/sql/item_sum.h index c88a850c241..1a21c257221 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -744,7 +744,7 @@ public: my_decimal *val_decimal(my_decimal *); bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return type_handler()->Item_get_date(thd, this, ltime, fuzzydate); + return type_handler()->Item_get_date_with_warn(thd, this, ltime, fuzzydate); } void reset_field(); }; @@ -1405,7 +1405,7 @@ public: } bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return type_handler()->Item_get_date(thd, this, ltime, fuzzydate); + return type_handler()->Item_get_date_with_warn(thd, this, ltime, fuzzydate); } }; @@ -1567,7 +1567,7 @@ public: virtual void print(String *str, enum_query_type query_type); bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return type_handler()->Item_get_date(thd, this, ltime, fuzzydate); + return type_handler()->Item_get_date_with_warn(thd, this, ltime, fuzzydate); } }; diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index de5ba8df2fe..d2a4e87a3d1 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -457,7 +457,7 @@ public: } bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return type_handler()->Item_get_date(thd, this, ltime, fuzzydate); + return type_handler()->Item_get_date_with_warn(thd, this, ltime, fuzzydate); } const Type_handler *type_handler() const { return &type_handler_long; } bool fix_length_and_dec() diff --git a/sql/my_decimal.h b/sql/my_decimal.h index f0bb69c60c8..b22c686cc90 100644 --- a/sql/my_decimal.h +++ b/sql/my_decimal.h @@ -217,8 +217,6 @@ public: { return check_result(mask, decimal_round(this, to, (int) scale, mode)); } - bool to_datetime_with_warn(THD *thd, MYSQL_TIME *to, date_mode_t fuzzydate, - const char *field_name); int to_binary(uchar *bin, int prec, int scale, uint mask= E_DEC_FATAL_ERROR) const; #endif diff --git a/sql/procedure.h b/sql/procedure.h index 2169091c0a6..050cc3817c0 100644 --- a/sql/procedure.h +++ b/sql/procedure.h @@ -71,7 +71,7 @@ public: } bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return type_handler()->Item_get_date(thd, this, ltime, fuzzydate); + return type_handler()->Item_get_date_with_warn(thd, this, ltime, fuzzydate); } Item* get_copy(THD *thd) { return 0; } }; diff --git a/sql/sql_error.h b/sql/sql_error.h index b783d527cb3..6586c49a125 100644 --- a/sql/sql_error.h +++ b/sql/sql_error.h @@ -814,11 +814,48 @@ private: extern char *err_conv(char *buff, uint to_length, const char *from, uint from_length, CHARSET_INFO *from_cs); -class ErrConv +class ErrBuff { protected: mutable char err_buffer[MYSQL_ERRMSG_SIZE]; public: + ErrBuff() + { + err_buffer[0]= '\0'; + } + const char *ptr() const { return err_buffer; } + const char *set_longlong(const Longlong_hybrid &nr) const + { + return nr.is_unsigned() ? ullstr(nr.value(), err_buffer) : + llstr(nr.value(), err_buffer); + } + const char *set_double(double nr) const + { + my_gcvt(nr, MY_GCVT_ARG_DOUBLE, sizeof(err_buffer), err_buffer, 0); + return err_buffer; + } + const char *set_decimal(const decimal_t *d) const + { + int len= sizeof(err_buffer); + decimal2string(d, err_buffer, &len, 0, 0, ' '); + return err_buffer; + } + const char *set_str(const char *str, size_t len, CHARSET_INFO *cs) const + { + DBUG_ASSERT(len < UINT_MAX32); + return err_conv(err_buffer, (uint) sizeof(err_buffer), str, (uint) len, cs); + } + const char *set_mysql_time(const MYSQL_TIME *ltime) const + { + my_TIME_to_str(ltime, err_buffer, AUTO_SEC_PART_DIGITS); + return err_buffer; + } +}; + + +class ErrConv: public ErrBuff +{ +public: ErrConv() {} virtual ~ErrConv() {} virtual const char *ptr() const = 0; @@ -838,8 +875,7 @@ public: : ErrConv(), str(s->ptr()), len(s->length()), cs(s->charset()) {} const char *ptr() const { - DBUG_ASSERT(len < UINT_MAX32); - return err_conv(err_buffer, (uint) sizeof(err_buffer), str, (uint) len, cs); + return set_str(str, len, cs); } }; @@ -850,8 +886,7 @@ public: : ErrConv(), Longlong_hybrid(nr) { } const char *ptr() const { - return m_unsigned ? ullstr(m_value, err_buffer) : - llstr(m_value, err_buffer); + return set_longlong(static_cast<Longlong_hybrid>(*this)); } }; @@ -862,8 +897,7 @@ public: ErrConvDouble(double num_arg) : ErrConv(), num(num_arg) {} const char *ptr() const { - my_gcvt(num, MY_GCVT_ARG_DOUBLE, sizeof(err_buffer), err_buffer, 0); - return err_buffer; + return set_double(num); } }; @@ -874,8 +908,7 @@ public: ErrConvTime(const MYSQL_TIME *ltime_arg) : ErrConv(), ltime(ltime_arg) {} const char *ptr() const { - my_TIME_to_str(ltime, err_buffer, AUTO_SEC_PART_DIGITS); - return err_buffer; + return set_mysql_time(ltime); } }; @@ -886,9 +919,7 @@ public: ErrConvDecimal(const decimal_t *d_arg) : ErrConv(), d(d_arg) {} const char *ptr() const { - int len= sizeof(err_buffer); - decimal2string(d, err_buffer, &len, 0, 0, ' '); - return err_buffer; + return set_decimal(d); } }; diff --git a/sql/sql_time.cc b/sql/sql_time.cc index 630d150be77..9562394f11e 100644 --- a/sql/sql_time.cc +++ b/sql/sql_time.cc @@ -377,9 +377,11 @@ bool Temporal::str_to_time(MYSQL_TIME_STATUS *status, date_mode_t fuzzydate) { TemporalAsciiBuffer tmp(str, length, cs); - return ::str_to_time(tmp.str, tmp.length, this, + bool rc= ::str_to_time(tmp.str, tmp.length, this, ulonglong(fuzzydate & TIME_MODE_FOR_XXX_TO_DATE), status); + DBUG_ASSERT(status->warnings || !rc); + return rc; } @@ -389,9 +391,11 @@ bool Temporal::str_to_datetime(MYSQL_TIME_STATUS *status, date_mode_t flags) { TemporalAsciiBuffer tmp(str, length, cs); - return ::str_to_datetime(tmp.str, tmp.length, this, + bool rc= ::str_to_datetime(tmp.str, tmp.length, this, ulonglong(flags & TIME_MODE_FOR_XXX_TO_DATE), status); + DBUG_ASSERT(status->warnings || !rc); + return rc; } @@ -401,7 +405,9 @@ bool Interval_DDhhmmssff::str_to_DDhhmmssff(MYSQL_TIME_STATUS *status, CHARSET_INFO *cs, ulong max_hour) { TemporalAsciiBuffer tmp(str, length, cs); - return ::str_to_DDhhmmssff(tmp.str, tmp.length, this, UINT_MAX32, status); + bool rc= ::str_to_DDhhmmssff(tmp.str, tmp.length, this, UINT_MAX32, status); + DBUG_ASSERT(status->warnings || !rc); + return rc; } @@ -413,45 +419,22 @@ bool Interval_DDhhmmssff::str_to_DDhhmmssff(MYSQL_TIME_STATUS *status, See description of str_to_datetime() for more information. */ -static bool -str_to_datetime_with_warn(THD *thd, CHARSET_INFO *cs, - const char *str, size_t length, MYSQL_TIME *l_time, - date_mode_t flags, MYSQL_TIME_STATUS *status) -{ - Temporal_hybrid *t= new(l_time) Temporal_hybrid(status, str, length, cs, flags); - if (!t->is_valid_temporal() || status->warnings) - { - const ErrConvString err(str, length, &my_charset_bin); - make_truncated_value_warning(thd, - !t->is_valid_temporal() ? - Sql_condition::WARN_LEVEL_WARN : - Sql_condition::time_warn_level(status->warnings), - &err, flags & TIME_TIME_ONLY ? - MYSQL_TIMESTAMP_TIME : l_time->time_type, NullS); - } - DBUG_EXECUTE_IF("str_to_datetime_warn", - push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_YES, str);); - return !t->is_valid_temporal(); -} - - bool str_to_datetime_with_warn(THD *thd, CHARSET_INFO *cs, - const char *str, size_t length, MYSQL_TIME *l_time, - date_mode_t flags) + const char *str, size_t length, MYSQL_TIME *to, + date_mode_t mode) { - MYSQL_TIME_STATUS status; - return str_to_datetime_with_warn(thd, cs, str, length, l_time, flags, &status); + Temporal::Warn_push warn(thd, NullS, to, mode); + Temporal_hybrid *t= new(to) Temporal_hybrid(thd, &warn, str, length, cs, mode); + return !t->is_valid_temporal(); } bool double_to_datetime_with_warn(THD *thd, double value, MYSQL_TIME *ltime, date_mode_t fuzzydate, const char *field_name) { - const ErrConvDouble str(value); - Temporal_hybrid *t= new (ltime) Temporal_hybrid(thd, Sec6(value), fuzzydate, - &str, field_name); + Temporal::Warn_push warn(thd, field_name, ltime, fuzzydate); + Temporal_hybrid *t= new (ltime) Temporal_hybrid(thd, &warn, value, fuzzydate); return !t->is_valid_temporal(); } @@ -460,9 +443,8 @@ bool decimal_to_datetime_with_warn(THD *thd, const my_decimal *value, MYSQL_TIME *ltime, date_mode_t fuzzydate, const char *field_name) { - const ErrConvDecimal str(value); - Temporal_hybrid *t= new (ltime) Temporal_hybrid(thd, Sec6(value), fuzzydate, - &str, field_name); + Temporal::Warn_push warn(thd, field_name, ltime, fuzzydate); + Temporal_hybrid *t= new (ltime) Temporal_hybrid(thd, &warn, value, fuzzydate); return !t->is_valid_temporal(); } @@ -471,14 +453,12 @@ bool int_to_datetime_with_warn(THD *thd, const Longlong_hybrid &nr, MYSQL_TIME *ltime, date_mode_t fuzzydate, const char *field_name) { - const ErrConvInteger str(nr); /* Note: conversion from an integer to TIME can overflow to '838:59:59.999999', so the conversion result can have fractional digits. */ - Temporal_hybrid *t= new (ltime) - Temporal_hybrid(thd, Sec6(nr), - fuzzydate, &str, field_name); + Temporal::Warn_push warn(thd, field_name, ltime, fuzzydate); + Temporal_hybrid *t= new (ltime) Temporal_hybrid(thd, &warn, nr, fuzzydate); return !t->is_valid_temporal(); } @@ -909,20 +889,7 @@ void make_truncated_value_warning(THD *thd, timestamp_type time_type, const char *field_name) { - const char *type_str; - - switch (time_type) { - case MYSQL_TIMESTAMP_DATE: - type_str= "date"; - break; - case MYSQL_TIMESTAMP_TIME: - type_str= "time"; - break; - case MYSQL_TIMESTAMP_DATETIME: // FALLTHROUGH - default: - type_str= "datetime"; - break; - } + const char *type_str= Temporal::type_name_by_timestamp_type(time_type); return thd->push_warning_wrong_or_truncated_value(level, time_type <= MYSQL_TIMESTAMP_ERROR, type_str, sval->ptr(), field_name); @@ -1400,11 +1367,3 @@ void unpack_time(longlong packed, MYSQL_TIME *my_time, break; } } - - -bool my_decimal::to_datetime_with_warn(THD *thd, MYSQL_TIME *to, - date_mode_t fuzzydate, - const char *field_name) -{ - return decimal_to_datetime_with_warn(thd, this, to, fuzzydate, field_name); -} diff --git a/sql/sql_type.cc b/sql/sql_type.cc index 23fa678e7cf..a432f37b580 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -160,15 +160,6 @@ date_mode_t Temporal::sql_mode_for_dates(THD *thd) } -bool Dec_ptr::to_datetime_with_warn(THD *thd, MYSQL_TIME *to, - date_mode_t fuzzydate, Item *item) -{ - if (to_datetime_with_warn(thd, to, fuzzydate, item->field_name_or_null())) - return item->null_value|= item->make_zero_date(to, fuzzydate); - return item->null_value= false; -} - - my_decimal *Temporal::to_decimal(my_decimal *to) const { return date2my_decimal(this, to); @@ -182,6 +173,20 @@ my_decimal *Temporal::bad_to_decimal(my_decimal *to) const } +void Temporal::make_from_str(THD *thd, Warn *warn, + const char *str, size_t length, + CHARSET_INFO *cs, date_mode_t fuzzydate) +{ + DBUG_EXECUTE_IF("str_to_datetime_warn", + push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, + ER_YES, ErrConvString(str, length,cs).ptr());); + if (str_to_datetime(warn, str, length, cs, fuzzydate)) + make_fuzzy_date(&warn->warnings, fuzzydate); + if (warn->warnings) + warn->set_str(str, length, &my_charset_bin); +} + + Temporal_hybrid::Temporal_hybrid(THD *thd, Item *item, date_mode_t fuzzydate) { if (item->get_date(thd, this, fuzzydate)) @@ -221,31 +226,30 @@ void Sec6::make_truncated_warning(THD *thd, const char *type_str) const } -bool Sec6::convert_to_mysql_time(THD *thd, MYSQL_TIME *ltime, - date_mode_t fuzzydate, const ErrConv *str, - const char *field_name) const +bool Sec6::convert_to_mysql_time(THD *thd, int *warn, MYSQL_TIME *ltime, + date_mode_t fuzzydate) const { - int warn; bool is_time= bool(fuzzydate & TIME_TIME_ONLY); - const char *typestr= is_time ? "time" : "datetime"; - bool rc= is_time ? to_time(ltime, &warn) : - to_datetime(ltime, fuzzydate, &warn); + bool rc= is_time ? to_time(ltime, warn) : to_datetime(ltime, fuzzydate, warn); + DBUG_ASSERT(*warn || !rc); if (truncated()) - { - // The value was already truncated at the constructor call time - thd->push_warning_wrong_or_truncated_value(Sql_condition::WARN_LEVEL_WARN, - !is_time, typestr, - str->ptr(), field_name); - } - else if (rc || MYSQL_TIME_WARN_HAVE_WARNINGS(warn)) + *warn|= MYSQL_TIME_WARN_TRUNCATED; + return rc; +} + + +void Temporal::push_conversion_warnings(THD *thd, bool totally_useless_value, int warn, + const char *typestr, + const char *field_name, + const char *value) +{ + if (MYSQL_TIME_WARN_HAVE_WARNINGS(warn)) thd->push_warning_wrong_or_truncated_value(Sql_condition::WARN_LEVEL_WARN, - rc, typestr, str->ptr(), - field_name); + totally_useless_value, + typestr, value, field_name); else if (MYSQL_TIME_WARN_HAVE_NOTES(warn)) thd->push_warning_wrong_or_truncated_value(Sql_condition::WARN_LEVEL_NOTE, - rc, typestr, str->ptr(), - field_name); - return rc; + false, typestr, value, field_name); } @@ -340,11 +344,10 @@ const LEX_CSTRING Interval_DDhhmmssff::m_type_name= {STRING_WITH_LEN("INTERVAL DAY TO SECOND")}; -Interval_DDhhmmssff::Interval_DDhhmmssff(THD *thd, MYSQL_TIME_STATUS *st, +Interval_DDhhmmssff::Interval_DDhhmmssff(THD *thd, Status *st, bool push_warnings, Item *item, ulong max_hour) { - my_time_status_init(st); switch (item->cmp_type()) { case ROW_RESULT: DBUG_ASSERT(0); @@ -425,7 +428,6 @@ Interval_DDhhmmssff::push_warning_wrong_or_truncated_value(THD *thd, uint Interval_DDhhmmssff::fsp(THD *thd, Item *item) { - MYSQL_TIME_STATUS st; switch (item->cmp_type()) { case INT_RESULT: case TIME_RESULT: @@ -441,6 +443,7 @@ uint Interval_DDhhmmssff::fsp(THD *thd, Item *item) } if (!item->const_item() || item->is_expensive()) return TIME_SECOND_PART_DIGITS; + Status st; Interval_DDhhmmssff it(thd, &st, false/*no warnings*/, item, UINT_MAX32); return it.is_valid_interval_DDhhmmssff() ? st.precision : TIME_SECOND_PART_DIGITS; @@ -3995,47 +3998,87 @@ bool Type_handler_string_result::Item_val_bool(Item *item) const /*************************************************************************/ -bool Type_handler_int_result::Item_get_date(THD *thd, Item *item, - MYSQL_TIME *ltime, - date_mode_t fuzzydate) const + +bool Type_handler::Item_get_date_with_warn(THD *thd, Item *item, + MYSQL_TIME *ltime, + date_mode_t fuzzydate) const { - return item->get_date_from_int(thd, ltime, fuzzydate); + Temporal::Warn_push warn(thd, item->field_name_or_null(), ltime, fuzzydate); + Item_get_date(thd, item, &warn, ltime, fuzzydate); + return ltime->time_type < 0; } -bool Type_handler_year::Item_get_date(THD *thd, Item *item, MYSQL_TIME *ltime, +bool Type_handler::Item_func_hybrid_field_type_get_date_with_warn(THD *thd, + Item_func_hybrid_field_type *item, + MYSQL_TIME *ltime, + date_mode_t mode) const +{ + Temporal::Warn_push warn(thd, item->field_name_or_null(), ltime, mode); + Item_func_hybrid_field_type_get_date(thd, item, &warn, ltime, mode); + return ltime->time_type < 0; +} + + +/************************************************************************/ +void Type_handler_decimal_result::Item_get_date(THD *thd, Item *item, + Temporal::Warn *warn, + MYSQL_TIME *ltime, + date_mode_t fuzzydate) const +{ + new(ltime) Temporal_hybrid(thd, warn, VDec(item).ptr(), fuzzydate); +} + + +void Type_handler_int_result::Item_get_date(THD *thd, Item *item, + Temporal::Warn *warn, + MYSQL_TIME *to, + date_mode_t mode) const +{ + new(to) Temporal_hybrid(thd, warn, item->to_longlong_hybrid_null(), mode); +} + + +void Type_handler_year::Item_get_date(THD *thd, Item *item, + Temporal::Warn *warn, + MYSQL_TIME *ltime, date_mode_t fuzzydate) const { - return item->null_value= - VYear(item).to_mysql_time_with_warn(thd, ltime, fuzzydate, - item->field_name_or_null()); + VYear year(item); + DBUG_ASSERT(!year.truncated()); + Longlong_hybrid_null nr(Longlong_null(year.to_YYYYMMDD(), year.is_null()), + item->unsigned_flag); + new(ltime) Temporal_hybrid(thd, warn, nr, fuzzydate); } -bool Type_handler_real_result::Item_get_date(THD *thd, Item *item, +void Type_handler_real_result::Item_get_date(THD *thd, Item *item, + Temporal::Warn *warn, MYSQL_TIME *ltime, date_mode_t fuzzydate) const { - return item->get_date_from_real(thd, ltime, fuzzydate); + new(ltime) Temporal_hybrid(thd, warn, item->to_double_null(), fuzzydate); } -bool Type_handler_string_result::Item_get_date(THD *thd, Item *item, +void Type_handler_string_result::Item_get_date(THD *thd, Item *item, + Temporal::Warn *warn, MYSQL_TIME *ltime, - date_mode_t fuzzydate) const + date_mode_t mode) const { - return item->get_date_from_string(thd, ltime, fuzzydate); + StringBuffer<40> tmp; + new(ltime) Temporal_hybrid(thd, warn, item->val_str(&tmp), mode); } -bool Type_handler_temporal_result::Item_get_date(THD *thd, Item *item, +void Type_handler_temporal_result::Item_get_date(THD *thd, Item *item, + Temporal::Warn *warn, MYSQL_TIME *ltime, date_mode_t fuzzydate) const { DBUG_ASSERT(0); // Temporal type items must implement native get_date() item->null_value= true; - set_zero_time(ltime, mysql_timestamp_type()); - return true; + set_zero_time(ltime, MYSQL_TIMESTAMP_NONE); } @@ -4176,26 +4219,31 @@ Type_handler_decimal_result::Item_func_hybrid_field_type_val_decimal( } -bool +void Type_handler_decimal_result::Item_func_hybrid_field_type_get_date( THD *thd, Item_func_hybrid_field_type *item, + Temporal::Warn *warn, MYSQL_TIME *ltime, date_mode_t fuzzydate) const { - return VDec_op(item).to_datetime_with_warn(thd, ltime, fuzzydate, item); + new (ltime) Temporal_hybrid(thd, warn, VDec_op(item).ptr(), fuzzydate); } -bool +void Type_handler_year::Item_func_hybrid_field_type_get_date( THD *thd, Item_func_hybrid_field_type *item, + Temporal::Warn *warn, MYSQL_TIME *ltime, date_mode_t fuzzydate) const { - return item->null_value= - VYear_op(item).to_mysql_time_with_warn(thd, ltime, fuzzydate, NULL); + VYear_op year(item); + DBUG_ASSERT(!year.truncated()); + Longlong_hybrid_null nr(Longlong_null(year.to_YYYYMMDD(), year.is_null()), + item->unsigned_flag); + new(ltime) Temporal_hybrid(thd, warn, nr, fuzzydate); } @@ -4238,18 +4286,18 @@ Type_handler_int_result::Item_func_hybrid_field_type_val_decimal( } -bool +void Type_handler_int_result::Item_func_hybrid_field_type_get_date( THD *thd, Item_func_hybrid_field_type *item, - MYSQL_TIME *ltime, - date_mode_t fuzzydate) const + Temporal::Warn *warn, + MYSQL_TIME *to, + date_mode_t mode) const { - return item->get_date_from_int_op(thd, ltime, fuzzydate); + new(to) Temporal_hybrid(thd, warn, item->to_longlong_hybrid_null_op(), mode); } - /***************************************************************************/ String * @@ -4288,14 +4336,15 @@ Type_handler_real_result::Item_func_hybrid_field_type_val_decimal( } -bool +void Type_handler_real_result::Item_func_hybrid_field_type_get_date( THD *thd, Item_func_hybrid_field_type *item, - MYSQL_TIME *ltime, - date_mode_t fuzzydate) const + Temporal::Warn *warn, + MYSQL_TIME *to, + date_mode_t mode) const { - return item->get_date_from_real_op(thd, ltime, fuzzydate); + new(to) Temporal_hybrid(thd, warn, item->to_double_null_op(), mode); } @@ -4337,14 +4386,16 @@ Type_handler_temporal_result::Item_func_hybrid_field_type_val_decimal( } -bool +void Type_handler_temporal_result::Item_func_hybrid_field_type_get_date( THD *thd, Item_func_hybrid_field_type *item, + Temporal::Warn *warn, MYSQL_TIME *ltime, date_mode_t fuzzydate) const { - return item->date_op(thd, ltime, fuzzydate); + if (item->date_op(thd, ltime, fuzzydate)) + set_zero_time(ltime, MYSQL_TIMESTAMP_NONE); } @@ -4386,14 +4437,16 @@ Type_handler_time_common::Item_func_hybrid_field_type_val_decimal( } -bool +void Type_handler_time_common::Item_func_hybrid_field_type_get_date( THD *thd, Item_func_hybrid_field_type *item, + Temporal::Warn *warn, MYSQL_TIME *ltime, date_mode_t fuzzydate) const { - return item->time_op(thd, ltime); + if (item->time_op(thd, ltime)) + set_zero_time(ltime, MYSQL_TIMESTAMP_NONE); } @@ -4435,14 +4488,18 @@ Type_handler_string_result::Item_func_hybrid_field_type_val_decimal( } -bool +void Type_handler_string_result::Item_func_hybrid_field_type_get_date( THD *thd, Item_func_hybrid_field_type *item, + Temporal::Warn *warn, MYSQL_TIME *ltime, - date_mode_t fuzzydate) const + date_mode_t mode) const { - return item->get_date_from_str_op(thd, ltime, fuzzydate); + StringBuffer<40> tmp; + String *res= item->str_op(&tmp); + DBUG_ASSERT((res == NULL) == item->null_value); + new(ltime) Temporal_hybrid(thd, warn, res, mode); } /***************************************************************************/ @@ -4907,7 +4964,7 @@ bool Type_handler_numeric:: Item_func_min_max_get_date(THD *thd, Item_func_min_max *func, MYSQL_TIME *ltime, date_mode_t fuzzydate) const { - return Item_get_date(thd, func, ltime, fuzzydate); + return Item_get_date_with_warn(thd, func, ltime, fuzzydate); } @@ -7508,9 +7565,9 @@ Type_handler_date_common::create_literal_item(THD *thd, CHARSET_INFO *cs, bool send_error) const { - MYSQL_TIME_STATUS st; + Temporal::Warn st; Item_literal *item= NULL; - Temporal_hybrid tmp(&st, str, length, cs, sql_mode_for_dates(thd)); + Temporal_hybrid tmp(thd, &st, str, length, cs, sql_mode_for_dates(thd)); if (tmp.is_valid_temporal() && tmp.get_mysql_time()->time_type == MYSQL_TIMESTAMP_DATE && !have_important_literal_warnings(&st)) @@ -7528,9 +7585,9 @@ Type_handler_temporal_with_date::create_literal_item(THD *thd, CHARSET_INFO *cs, bool send_error) const { - MYSQL_TIME_STATUS st; + Temporal::Warn st; Item_literal *item= NULL; - Temporal_hybrid tmp(&st, str, length, cs, sql_mode_for_dates(thd)); + Temporal_hybrid tmp(thd, &st, str, length, cs, sql_mode_for_dates(thd)); if (tmp.is_valid_temporal() && tmp.get_mysql_time()->time_type == MYSQL_TIMESTAMP_DATETIME && !have_important_literal_warnings(&st)) diff --git a/sql/sql_type.h b/sql/sql_type.h index 45c98f7b7d3..5de4c8e431a 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -96,6 +96,7 @@ protected: my_decimal *m_ptr; Dec_ptr() { } public: + Dec_ptr(my_decimal *ptr) :m_ptr(ptr) { } bool is_null() const { return m_ptr == NULL; } const my_decimal *ptr() const { return m_ptr; } const my_decimal *ptr_or(const my_decimal *def) const @@ -113,14 +114,6 @@ public: longlong to_longlong(bool unsigned_flag) { return m_ptr ? m_ptr->to_longlong(unsigned_flag) : 0; } bool to_bool() const { return m_ptr ? m_ptr->to_bool() : false; } - bool to_datetime_with_warn(THD *thd, MYSQL_TIME *to, date_mode_t fuzzydate, - const char *field_name) - { - return m_ptr ? m_ptr->to_datetime_with_warn(thd, to, fuzzydate, field_name) : - true; - } - bool to_datetime_with_warn(THD *thd, MYSQL_TIME *to, date_mode_t fuzzydate, - Item *item); String *to_string(String *to) const { return m_ptr ? m_ptr->to_string(to) : NULL; @@ -260,20 +253,23 @@ public: long usec() const { return m_usec; } /** Converts Sec6 to MYSQL_TIME - - @param ltime converted value will be written here + @param thd current thd + @param [out] warn conversion warnings will be written here + @param [out] ltime converted value will be written here @param fuzzydate conversion flags (TIME_INVALID_DATE, etc) - @param str original number, as an ErrConv. For the warning - @param field_name field name or NULL if not a field. For the warning @returns false for success, true for a failure */ - bool convert_to_mysql_time(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate, - const ErrConv *str, const char *field_name) const; + bool convert_to_mysql_time(THD *thd, + int *warn, + MYSQL_TIME *ltime, + date_mode_t fuzzydate) const; // Convert a number in format hhhmmss.ff to TIME'hhh:mm:ss.ff' bool to_time(MYSQL_TIME *to, int *warn) const { - return number_to_time(m_neg, m_sec, m_usec, to, warn); + bool rc= number_to_time(m_neg, m_sec, m_usec, to, warn); + DBUG_ASSERT(*warn || !rc); + return rc; } /* Convert a number in format YYYYMMDDhhmmss.ff to @@ -286,9 +282,11 @@ public: *warn= MYSQL_TIME_WARN_OUT_OF_RANGE; return true; } - return number_to_datetime(m_sec, m_usec, to, - ulonglong(flags & TIME_MODE_FOR_XXX_TO_DATE), - warn) == -1; + bool rc= number_to_datetime(m_sec, m_usec, to, + ulonglong(flags & TIME_MODE_FOR_XXX_TO_DATE), + warn) == -1; + DBUG_ASSERT(*warn || !rc); + return rc; } // Convert elapsed seconds to TIME bool sec_to_time(MYSQL_TIME *ltime, uint dec) const @@ -394,20 +392,12 @@ class Year protected: uint m_year; bool m_truncated; - bool to_mysql_time_with_warn(THD *thd, MYSQL_TIME *to, date_mode_t fuzzydate, - const char *field_name) const - { - // Make it YYYYMMDD - Longlong_hybrid value(static_cast<ulonglong>(m_year) * 10000, true); - const ErrConvInteger str(value); - Sec6 sec(value); - return sec.convert_to_mysql_time(thd, to, fuzzydate, &str, field_name); - } uint year_precision(const Item *item) const; public: Year(): m_year(0), m_truncated(false) { } Year(longlong value, bool unsigned_flag, uint length); uint year() const { return m_year; } + uint to_YYYYMMDD() const { return m_year * 10000; } bool truncated() const { return m_truncated; } }; @@ -419,12 +409,6 @@ public: :Year(nr.is_null() ? 0 : nr.value(), unsigned_flag, length), Null_flag(nr.is_null()) { } - bool to_mysql_time_with_warn(THD *thd, MYSQL_TIME *to, date_mode_t fuzzydate, - const char *field_name) const - { - return m_is_null ? true : - Year::to_mysql_time_with_warn(thd, to, fuzzydate, field_name); - } }; @@ -442,15 +426,109 @@ public: }; +class Double_null: public Null_flag +{ +protected: + double m_value; +public: + Double_null(double value, bool is_null) + :Null_flag(is_null), m_value(value) + { } + double value() const { return m_value; } +}; + + class Temporal: protected MYSQL_TIME { public: + class Status: public MYSQL_TIME_STATUS + { + public: + Status() { my_time_status_init(this); } + }; + + class Warn: public ErrBuff, + public Status + { + public: + void push_conversion_warnings(THD *thd, bool totally_useless_value, date_mode_t mode, + timestamp_type tstype, const char *name) + { + const char *typestr= tstype >= 0 ? type_name_by_timestamp_type(tstype) : + mode & TIME_TIME_ONLY ? "time" : "datetime"; + Temporal::push_conversion_warnings(thd, totally_useless_value, warnings, typestr, + name, ptr()); + } + }; + + class Warn_push: public Warn + { + THD *m_thd; + const char *m_name; + const MYSQL_TIME *m_ltime; + date_mode_t m_mode; + public: + Warn_push(THD *thd, const char *name, + const MYSQL_TIME *ltime, date_mode_t mode) + :m_thd(thd), m_name(name), m_ltime(ltime), m_mode(mode) + { } + ~Warn_push() + { + if (warnings) + push_conversion_warnings(m_thd, m_ltime->time_type < 0, + m_mode, m_ltime->time_type, m_name); + } + }; + +public: static date_mode_t sql_mode_for_dates(THD *thd); bool is_valid_temporal() const { DBUG_ASSERT(time_type != MYSQL_TIMESTAMP_ERROR); return time_type != MYSQL_TIMESTAMP_NONE; } + static const char *type_name_by_timestamp_type(timestamp_type time_type) + { + switch (time_type) { + case MYSQL_TIMESTAMP_DATE: return "date"; + case MYSQL_TIMESTAMP_TIME: return "time"; + case MYSQL_TIMESTAMP_DATETIME: // FALLTHROUGH + default: + break; + } + return "datetime"; + } + static void push_conversion_warnings(THD *thd, bool totally_useless_value, int warn, + const char *type_name, + const char *field_name, + const char *value); + /* + This method is used if the item was not null but convertion to + TIME/DATE/DATETIME failed. We return a zero date if allowed, + otherwise - null. + */ + void make_fuzzy_date(int *warn, date_mode_t fuzzydate) + { + /* + In the following scenario: + - The caller expected to get a TIME value + - Item returned a not NULL string or numeric value + - But then conversion from string or number to TIME failed + we need to change the default time_type from MYSQL_TIMESTAMP_DATE + (which was set in bzero) to MYSQL_TIMESTAMP_TIME and therefore + return TIME'00:00:00' rather than DATE'0000-00-00'. + If we don't do this, methods like Item::get_time_with_conversion() + will erroneously subtract CURRENT_DATE from '0000-00-00 00:00:00' + and return TIME'-838:59:59' instead of TIME'00:00:00' as a result. + */ + timestamp_type tstype= !(fuzzydate & TIME_FUZZY_DATES) ? + MYSQL_TIMESTAMP_NONE : + fuzzydate & TIME_TIME_ONLY ? + MYSQL_TIMESTAMP_TIME : + MYSQL_TIMESTAMP_DATETIME; + set_zero_time(this, tstype); + } + protected: my_decimal *bad_to_decimal(my_decimal *to) const; my_decimal *to_decimal(my_decimal *to) const; @@ -465,6 +543,39 @@ protected: *warn= MYSQL_TIME_WARN_OUT_OF_RANGE; time_type= MYSQL_TIMESTAMP_NONE; } + void make_from_sec6(THD *thd, MYSQL_TIME_STATUS *st, + const Sec6 &nr, date_mode_t mode) + { + if (nr.convert_to_mysql_time(thd, &st->warnings, this, mode)) + make_fuzzy_date(&st->warnings, mode); + } + void make_from_str(THD *thd, Warn *warn, + const char *str, size_t length, CHARSET_INFO *cs, + date_mode_t fuzzydate); + void make_from_double(THD *thd, Warn *warn, double nr, date_mode_t mode) + { + make_from_sec6(thd, warn, Sec6(nr), mode); + if (warn->warnings) + warn->set_double(nr); + } + void make_from_longlong_hybrid(THD *thd, Warn *warn, + const Longlong_hybrid &nr, date_mode_t mode) + { + /* + Note: conversion from an integer to TIME can overflow to + '838:59:59.999999', so the conversion result can have fractional digits. + */ + make_from_sec6(thd, warn, Sec6(nr), mode); + if (warn->warnings) + warn->set_longlong(nr); + } + void make_from_decimal(THD *thd, Warn *warn, + const my_decimal *nr, date_mode_t mode) + { + make_from_sec6(thd, warn, Sec6(nr), mode); + if (warn->warnings) + warn->set_decimal(nr); + } bool str_to_time(MYSQL_TIME_STATUS *st, const char *str, size_t length, CHARSET_INFO *cs, date_mode_t fuzzydate); bool str_to_datetime(MYSQL_TIME_STATUS *st, const char *str, size_t length, @@ -506,6 +617,7 @@ public: class Temporal_hybrid: public Temporal { public: + // Contructors for Item Temporal_hybrid(THD *thd, Item *item, date_mode_t fuzzydate); Temporal_hybrid(THD *thd, Item *item) :Temporal_hybrid(thd, item, sql_mode_for_dates(thd)) @@ -513,18 +625,56 @@ public: Temporal_hybrid(Item *item) :Temporal_hybrid(current_thd, item) { } - Temporal_hybrid(MYSQL_TIME_STATUS *st, const char *str, size_t length, - CHARSET_INFO *cs, date_mode_t fuzzydate) + + // Constructors for non-NULL values + Temporal_hybrid(THD *thd, Warn *warn, + const char *str, size_t length, CHARSET_INFO *cs, + date_mode_t fuzzydate) + { + make_from_str(thd, warn, str, length, cs, fuzzydate); + } + Temporal_hybrid(THD *thd, Warn *warn, + const Longlong_hybrid &nr, date_mode_t fuzzydate) + { + make_from_longlong_hybrid(thd, warn, nr, fuzzydate); + } + Temporal_hybrid(THD *thd, Warn *warn, double nr, date_mode_t fuzzydate) { - if (str_to_datetime(st, str, length, cs, fuzzydate)) + make_from_double(thd, warn, nr, fuzzydate); + } + + // Constructors for nullable values + Temporal_hybrid(THD *thd, Warn *warn, const String *str, date_mode_t mode) + { + if (!str) + time_type= MYSQL_TIMESTAMP_NONE; + else + make_from_str(thd, warn, str->ptr(), str->length(), str->charset(), mode); + } + Temporal_hybrid(THD *thd, Warn *warn, + const Longlong_hybrid_null &nr, date_mode_t fuzzydate) + { + if (nr.is_null()) time_type= MYSQL_TIMESTAMP_NONE; + else + make_from_longlong_hybrid(thd, warn, nr, fuzzydate); } - Temporal_hybrid(THD *thd, const Sec6 &sec, date_mode_t fuzzydate, - const ErrConv *str, const char *field_name) + Temporal_hybrid(THD *thd, Warn *warn, const Double_null &nr, date_mode_t mode) { - if (sec.convert_to_mysql_time(thd, this, fuzzydate, str, field_name)) + if (nr.is_null()) time_type= MYSQL_TIMESTAMP_NONE; + else + make_from_double(thd, warn, nr.value(), mode); } + Temporal_hybrid(THD *thd, Warn *warn, const my_decimal *nr, date_mode_t mode) + { + if (!nr) + time_type= MYSQL_TIMESTAMP_NONE; + else + make_from_decimal(thd, warn, nr, mode); + } + // End of constuctors + longlong to_longlong() const { if (!is_valid_temporal()) @@ -705,11 +855,11 @@ public: return 87649415; } public: - Interval_DDhhmmssff(THD *thd, MYSQL_TIME_STATUS *st, bool push_warnings, + Interval_DDhhmmssff(THD *thd, Status *st, bool push_warnings, Item *item, ulong max_hour); Interval_DDhhmmssff(THD *thd, Item *item) { - MYSQL_TIME_STATUS st; + Status st; new(this) Interval_DDhhmmssff(thd, &st, true, item, max_useful_hour()); } const MYSQL_TIME *get_mysql_time() const @@ -2549,8 +2699,11 @@ public: bool Item_sum_variance_fix_length_and_dec(Item_sum_variance *) const= 0; virtual bool Item_val_bool(Item *item) const= 0; - virtual bool Item_get_date(THD *thd, Item *item, MYSQL_TIME *ltime, + virtual void Item_get_date(THD *thd, Item *item, + Temporal::Warn *buff, MYSQL_TIME *ltime, date_mode_t fuzzydate) const= 0; + bool Item_get_date_with_warn(THD *thd, Item *item, MYSQL_TIME *ltime, + date_mode_t fuzzydate) const; virtual longlong Item_val_int_signed_typecast(Item *item) const= 0; virtual longlong Item_val_int_unsigned_typecast(Item *item) const= 0; @@ -2571,10 +2724,15 @@ public: Item_func_hybrid_field_type *, my_decimal *) const= 0; virtual - bool Item_func_hybrid_field_type_get_date(THD *, + void Item_func_hybrid_field_type_get_date(THD *, Item_func_hybrid_field_type *, + Temporal::Warn *, MYSQL_TIME *, date_mode_t fuzzydate) const= 0; + bool Item_func_hybrid_field_type_get_date_with_warn(THD *thd, + Item_func_hybrid_field_type *, + MYSQL_TIME *, + date_mode_t) const; virtual String *Item_func_min_max_val_str(Item_func_min_max *, String *) const= 0; virtual @@ -2836,11 +2994,12 @@ public: DBUG_ASSERT(0); return false; } - bool Item_get_date(THD *thd, Item *item, - MYSQL_TIME *ltime, date_mode_t fuzzydate) const + void Item_get_date(THD *thd, Item *item, + Temporal::Warn *warn, MYSQL_TIME *ltime, + date_mode_t fuzzydate) const { DBUG_ASSERT(0); - return true; + set_zero_time(ltime, MYSQL_TIMESTAMP_NONE); } longlong Item_val_int_signed_typecast(Item *item) const { @@ -2882,13 +3041,14 @@ public: DBUG_ASSERT(0); return NULL; } - bool Item_func_hybrid_field_type_get_date(THD *, + void Item_func_hybrid_field_type_get_date(THD *, Item_func_hybrid_field_type *, - MYSQL_TIME *, + Temporal::Warn *, + MYSQL_TIME *ltime, date_mode_t fuzzydate) const { DBUG_ASSERT(0); - return true; + set_zero_time(ltime, MYSQL_TIMESTAMP_NONE); } String *Item_func_min_max_val_str(Item_func_min_max *, String *) const @@ -3058,8 +3218,8 @@ public: bool Item_func_signed_fix_length_and_dec(Item_func_signed *item) const; bool Item_func_unsigned_fix_length_and_dec(Item_func_unsigned *item) const; bool Item_val_bool(Item *item) const; - bool Item_get_date(THD *thd, Item *item, MYSQL_TIME *ltime, - date_mode_t fuzzydate) const; + void Item_get_date(THD *thd, Item *item, Temporal::Warn *warn, + MYSQL_TIME *ltime, date_mode_t fuzzydate) const; longlong Item_val_int_signed_typecast(Item *item) const; longlong Item_val_int_unsigned_typecast(Item *item) const; String *Item_func_hex_val_str_ascii(Item_func_hex *item, String *str) const; @@ -3072,8 +3232,9 @@ public: my_decimal *Item_func_hybrid_field_type_val_decimal( Item_func_hybrid_field_type *, my_decimal *) const; - bool Item_func_hybrid_field_type_get_date(THD *, + void Item_func_hybrid_field_type_get_date(THD *, Item_func_hybrid_field_type *, + Temporal::Warn *, MYSQL_TIME *, date_mode_t fuzzydate) const; String *Item_func_min_max_val_str(Item_func_min_max *, String *) const; @@ -3156,11 +3317,8 @@ public: { return VDec(item).to_bool(); } - bool Item_get_date(THD *thd, Item *item, MYSQL_TIME *ltime, - date_mode_t fuzzydate) const - { - return VDec(item).to_datetime_with_warn(thd, ltime, fuzzydate, item); - } + void Item_get_date(THD *thd, Item *item, Temporal::Warn *warn, + MYSQL_TIME *ltime, date_mode_t fuzzydate) const; longlong Item_val_int_signed_typecast(Item *item) const; longlong Item_val_int_unsigned_typecast(Item *item) const { @@ -3176,8 +3334,9 @@ public: my_decimal *Item_func_hybrid_field_type_val_decimal( Item_func_hybrid_field_type *, my_decimal *) const; - bool Item_func_hybrid_field_type_get_date(THD *, + void Item_func_hybrid_field_type_get_date(THD *, Item_func_hybrid_field_type *, + Temporal::Warn *, MYSQL_TIME *, date_mode_t fuzzydate) const; String *Item_func_min_max_val_str(Item_func_min_max *, String *) const; @@ -3366,8 +3525,8 @@ public: bool Item_sum_avg_fix_length_and_dec(Item_sum_avg *) const; bool Item_sum_variance_fix_length_and_dec(Item_sum_variance *) const; bool Item_val_bool(Item *item) const; - bool Item_get_date(THD *thd, Item *item, MYSQL_TIME *ltime, - date_mode_t fuzzydate) const; + void Item_get_date(THD *thd, Item *item, Temporal::Warn *warn, + MYSQL_TIME *ltime, date_mode_t fuzzydate) const; longlong Item_val_int_signed_typecast(Item *item) const; longlong Item_val_int_unsigned_typecast(Item *item) const; String *Item_func_hex_val_str_ascii(Item_func_hex *item, String *str) const; @@ -3380,8 +3539,9 @@ public: my_decimal *Item_func_hybrid_field_type_val_decimal( Item_func_hybrid_field_type *, my_decimal *) const; - bool Item_func_hybrid_field_type_get_date(THD *, + void Item_func_hybrid_field_type_get_date(THD *, Item_func_hybrid_field_type *, + Temporal::Warn *, MYSQL_TIME *, date_mode_t fuzzydate) const; String *Item_func_min_max_val_str(Item_func_min_max *, String *) const; @@ -3448,8 +3608,8 @@ public: bool Item_sum_avg_fix_length_and_dec(Item_sum_avg *) const; bool Item_sum_variance_fix_length_and_dec(Item_sum_variance *) const; bool Item_val_bool(Item *item) const; - bool Item_get_date(THD *thd, Item *item, MYSQL_TIME *ltime, - date_mode_t fuzzydate) const; + void Item_get_date(THD *thd, Item *item, Temporal::Warn *warn, + MYSQL_TIME *ltime, date_mode_t fuzzydate) const; longlong Item_val_int_signed_typecast(Item *item) const; longlong Item_val_int_unsigned_typecast(Item *item) const; String *Item_func_hex_val_str_ascii(Item_func_hex *item, String *str) const; @@ -3462,8 +3622,9 @@ public: my_decimal *Item_func_hybrid_field_type_val_decimal( Item_func_hybrid_field_type *, my_decimal *) const; - bool Item_func_hybrid_field_type_get_date(THD *, + void Item_func_hybrid_field_type_get_date(THD *, Item_func_hybrid_field_type *, + Temporal::Warn *, MYSQL_TIME *, date_mode_t fuzzydate) const; bool Item_func_min_max_get_date(THD *thd, Item_func_min_max*, @@ -3565,8 +3726,8 @@ public: bool Item_func_signed_fix_length_and_dec(Item_func_signed *item) const; bool Item_func_unsigned_fix_length_and_dec(Item_func_unsigned *item) const; bool Item_val_bool(Item *item) const; - bool Item_get_date(THD *thd, Item *item, MYSQL_TIME *ltime, - date_mode_t fuzzydate) const; + void Item_get_date(THD *thd, Item *item, Temporal::Warn *warn, + MYSQL_TIME *ltime, date_mode_t fuzzydate) const; longlong Item_val_int_signed_typecast(Item *item) const; longlong Item_val_int_unsigned_typecast(Item *item) const; String *Item_func_hex_val_str_ascii(Item_func_hex *item, String *str) const; @@ -3579,8 +3740,9 @@ public: my_decimal *Item_func_hybrid_field_type_val_decimal( Item_func_hybrid_field_type *, my_decimal *) const; - bool Item_func_hybrid_field_type_get_date(THD *, + void Item_func_hybrid_field_type_get_date(THD *, Item_func_hybrid_field_type *, + Temporal::Warn *, MYSQL_TIME *, date_mode_t fuzzydate) const; String *Item_func_min_max_val_str(Item_func_min_max *, String *) const; @@ -3901,10 +4063,11 @@ public: const Column_definition_attributes *attr, uint32 flags) const; Item_cache *Item_get_cache(THD *thd, const Item *item) const; - bool Item_get_date(THD *thd, Item *item, MYSQL_TIME *ltime, - date_mode_t fuzzydate) const; - bool Item_func_hybrid_field_type_get_date(THD *, + void Item_get_date(THD *thd, Item *item, Temporal::Warn *warn, + MYSQL_TIME *ltime, date_mode_t fuzzydate) const; + void Item_func_hybrid_field_type_get_date(THD *, Item_func_hybrid_field_type *item, + Temporal::Warn *, MYSQL_TIME *to, date_mode_t fuzzydate) const; }; @@ -4088,8 +4251,9 @@ public: my_decimal *Item_func_hybrid_field_type_val_decimal( Item_func_hybrid_field_type *, my_decimal *) const; - bool Item_func_hybrid_field_type_get_date(THD *, + void Item_func_hybrid_field_type_get_date(THD *, Item_func_hybrid_field_type *, + Temporal::Warn *, MYSQL_TIME *, date_mode_t fuzzydate) const; String *Item_func_min_max_val_str(Item_func_min_max *, String *) const; diff --git a/sql/sql_type_int.h b/sql/sql_type_int.h index 6c88222fed0..1cc93415176 100644 --- a/sql/sql_type_int.h +++ b/sql/sql_type_int.h @@ -67,4 +67,16 @@ public: } }; + +class Longlong_hybrid_null: public Longlong_hybrid, + public Null_flag +{ +public: + Longlong_hybrid_null(const Longlong_null &nr, bool unsigned_flag) + :Longlong_hybrid(nr.value(), unsigned_flag), + Null_flag(nr.is_null()) + { } +}; + + #endif // SQL_TYPE_INT_INCLUDED diff --git a/storage/tokudb/mysql-test/tokudb/r/type_datetime.result b/storage/tokudb/mysql-test/tokudb/r/type_datetime.result index 00f7dc650e5..698bad10390 100644 --- a/storage/tokudb/mysql-test/tokudb/r/type_datetime.result +++ b/storage/tokudb/mysql-test/tokudb/r/type_datetime.result @@ -401,7 +401,7 @@ if(@bug28261 = f1, '', @bug28261:= f1) 2001-01-01 2002-02-02 Warnings: -Warning 1292 Incorrect datetime value: '' +Warning 1292 Truncated incorrect datetime value: '' select if(@bug28261 = f1, '', @bug28261:= f1) from t1; if(@bug28261 = f1, '', @bug28261:= f1) 2001-01-01 @@ -425,11 +425,11 @@ f1 2001-01-01 00:00:00 2002-02-02 00:00:00 Warnings: -Warning 1292 Incorrect datetime value: '2002010' +Warning 1292 Truncated incorrect datetime value: '2002010' select * from t1 where f1 between 20020101 and 2007010100000; f1 Warnings: -Warning 1292 Incorrect datetime value: '2007010100000' +Warning 1292 Truncated incorrect datetime value: '2007010100000' drop table t1; # # Bug#27216: functions with parameters of different date types may @@ -500,7 +500,7 @@ f1 45:44:44 15:44:44 Warnings: -Warning 1292 Incorrect datetime value: '1' +Warning 1292 Truncated incorrect datetime value: '1' drop table t1; create table t1 (a tinyint); insert into t1 values (), (), (); |