From 9b79888df82259743284501af5b156a18edc427f Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Mon, 22 May 2017 17:13:15 +0400 Subject: [PATCH] MDEV-12866 Out-of-range error with CREATE..SELECT..TO_SECONDS(NOW()) --- mysql-test/r/func_time.result | 12 ++++++++++++ mysql-test/r/metadata.result | 2 +- mysql-test/r/partition_column.result | 2 +- mysql-test/t/func_time.test | 9 +++++++++ sql/item_timefunc.h | 6 +++--- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result index 50ea5e207bf..fb0179026c9 100644 --- a/mysql-test/r/func_time.result +++ b/mysql-test/r/func_time.result @@ -3282,3 +3282,15 @@ DROP TABLE t2; DROP VIEW v1; DROP TABLE t1; SET sql_mode=DEFAULT; +# +# MDEV-12866 Out-of-range error with CREATE..SELECT..TO_SECONDS(NOW()) +# +SET sql_mode=STRICT_ALL_TABLES; +CREATE TABLE t1 AS SELECT TO_SECONDS('9999-12-31 23:59:59'); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `TO_SECONDS('9999-12-31 23:59:59')` bigint(12) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +SET sql_mode=DEFAULT; diff --git a/mysql-test/r/metadata.result b/mysql-test/r/metadata.result index b588a6a9525..7e57fa74663 100644 --- a/mysql-test/r/metadata.result +++ b/mysql-test/r/metadata.result @@ -476,7 +476,7 @@ def PERIOD_DIFF(200802,200703) 3 6 2 N 32897 0 63 def TO_DAYS('2007-10-07') 3 6 6 Y 32896 0 63 def DAYOFMONTH('2007-02-03') 3 2 1 Y 32896 0 63 def DAYOFWEEK('2007-02-03') 3 1 1 Y 32896 0 63 -def TO_SECONDS('2013-06-13') 3 6 11 Y 32896 0 63 +def TO_SECONDS('2013-06-13') 8 12 11 Y 32896 0 63 PERIOD_ADD(200801,2) PERIOD_DIFF(200802,200703) TO_DAYS('2007-10-07') DAYOFMONTH('2007-02-03') DAYOFWEEK('2007-02-03') TO_SECONDS('2013-06-13') 200803 11 733321 3 7 63538300800 SELECT diff --git a/mysql-test/r/partition_column.result b/mysql-test/r/partition_column.result index 3df31078a50..cba1e283474 100644 --- a/mysql-test/r/partition_column.result +++ b/mysql-test/r/partition_column.result @@ -542,7 +542,7 @@ create table t1 as select to_seconds(null) as to_seconds; select data_type from information_schema.columns where table_schema='test' and column_name='to_seconds'; data_type -int +bigint drop table t1; create table t1 (a int, b int) partition by list columns(a,b) diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test index 216b059038b..a3f542aaf57 100644 --- a/mysql-test/t/func_time.test +++ b/mysql-test/t/func_time.test @@ -1871,3 +1871,12 @@ DROP TABLE t2; DROP VIEW v1; DROP TABLE t1; SET sql_mode=DEFAULT; + +--echo # +--echo # MDEV-12866 Out-of-range error with CREATE..SELECT..TO_SECONDS(NOW()) +--echo # +SET sql_mode=STRICT_ALL_TABLES; +CREATE TABLE t1 AS SELECT TO_SECONDS('9999-12-31 23:59:59'); +SHOW CREATE TABLE t1; +DROP TABLE t1; +SET sql_mode=DEFAULT; diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index 4890a2a7f08..55193bce207 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -89,16 +89,16 @@ public: }; -class Item_func_to_seconds :public Item_long_func +class Item_func_to_seconds :public Item_longlong_func { public: - Item_func_to_seconds(THD *thd, Item *a): Item_long_func(thd, a) {} + Item_func_to_seconds(THD *thd, Item *a): Item_longlong_func(thd, a) {} longlong val_int(); const char *func_name() const { return "to_seconds"; } void fix_length_and_dec() { decimals=0; - max_length=6*MY_CHARSET_BIN_MB_MAXLEN; + fix_char_length(12); maybe_null= 1; } enum_monotonicity_info get_monotonicity_info() const;