← Back to team overview

maria-developers team mailing list archive

MDEV-11819 NO_ZERO_IN_DATE: Incorrect generated column value

 

Hello Sergei,

Please review a patch for MDEV-11819.

Thanks.

commit e30b6a983fe135dd1af0c79c81dbdb5b14b881c8
Author: Alexander Barkov <bar@xxxxxxxxxxx>
Date:   Fri Oct 6 18:23:40 2017 +0400

    MDEV-11819 NO_ZERO_IN_DATE: Incorrect generated column value

diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result
index 68b1e0f..fa15997 100644
--- a/mysql-test/r/func_time.result
+++ b/mysql-test/r/func_time.result
@@ -2626,3 +2626,17 @@ DROP TABLE t1;
 SELECT 1 MOD ADDTIME( '13:58:57', '00:00:01' ) + 2;
 1 MOD ADDTIME( '13:58:57', '00:00:01' ) + 2
 3
+#
+# MDEV-11819 NO_ZERO_IN_DATE: Incorrect generated column value
+#
+SET sql_mode='NO_ZERO_IN_DATE';
+CREATE TABLE t1 (a TIME(6));
+INSERT INTO t1 SELECT timediff(timestamp'2008-12-31 23:59:59.000001',timestamp'2008-12-30 01:01:01.000002');
+SELECT * FROM t1;
+a
+46:58:57.999999
+DROP TABLE t1;
+SET sql_mode=DEFAULT;
+#
+# End of 5.5 tests
+#
diff --git a/mysql-test/suite/vcol/r/vcol_misc.result b/mysql-test/suite/vcol/r/vcol_misc.result
index 699b6d4..0a8d87d 100644
--- a/mysql-test/suite/vcol/r/vcol_misc.result
+++ b/mysql-test/suite/vcol/r/vcol_misc.result
@@ -337,3 +337,22 @@ tsv timestamp as (adddate(ts, interval 1 day)) virtual
 );
 drop table t1;
 set sql_mode=default;
+#
+# MDEV-11819 NO_ZERO_IN_DATE: Incorrect generated column value
+#
+SET sql_mode='NO_ZERO_IN_DATE';
+CREATE TABLE t1
+(
+a datetime DEFAULT NULL,
+b datetime DEFAULT NULL,
+c time GENERATED ALWAYS AS (timediff(`a`,`b`)) VIRTUAL
+);
+INSERT INTO t1 VALUES ('2008-12-31 23:59:59.000001','2008-12-30 01:01:01.000002',DEFAULT);
+SELECT * FROM t1;
+a	b	c
+2008-12-31 23:59:59	2008-12-30 01:01:01	46:58:58
+DROP TABLE t1;
+SET sql_mode=DEFAULT;
+#
+# End of 5.5 tests
+#
diff --git a/mysql-test/suite/vcol/t/vcol_misc.test b/mysql-test/suite/vcol/t/vcol_misc.test
index 80a36d9..1ac0b4f 100644
--- a/mysql-test/suite/vcol/t/vcol_misc.test
+++ b/mysql-test/suite/vcol/t/vcol_misc.test
@@ -301,3 +301,23 @@ create table t1 (
 );
 drop table t1;
 set sql_mode=default;
+
+--echo #
+--echo # MDEV-11819 NO_ZERO_IN_DATE: Incorrect generated column value
+--echo #
+
+SET sql_mode='NO_ZERO_IN_DATE';
+CREATE TABLE t1
+(
+  a datetime DEFAULT NULL,
+  b datetime DEFAULT NULL,
+  c time GENERATED ALWAYS AS (timediff(`a`,`b`)) VIRTUAL
+);
+INSERT INTO t1 VALUES ('2008-12-31 23:59:59.000001','2008-12-30 01:01:01.000002',DEFAULT);
+SELECT * FROM t1;
+DROP TABLE t1;
+SET sql_mode=DEFAULT;
+
+--echo #
+--echo # End of 5.5 tests
+--echo #
diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test
index 92e1c38..7544f9e 100644
--- a/mysql-test/t/func_time.test
+++ b/mysql-test/t/func_time.test
@@ -1602,3 +1602,19 @@ DROP TABLE t1;
 --echo # MDEV-10524 Assertion `arg1_int >= 0' failed in Item_func_additive_op::result_precision()
 --echo #
 SELECT 1 MOD ADDTIME( '13:58:57', '00:00:01' ) + 2;
+
+
+--echo #
+--echo # MDEV-11819 NO_ZERO_IN_DATE: Incorrect generated column value
+--echo #
+
+SET sql_mode='NO_ZERO_IN_DATE';
+CREATE TABLE t1 (a TIME(6));
+INSERT INTO t1 SELECT timediff(timestamp'2008-12-31 23:59:59.000001',timestamp'2008-12-30 01:01:01.000002');
+SELECT * FROM t1;
+DROP TABLE t1;
+SET sql_mode=DEFAULT;
+
+--echo #
+--echo # End of 5.5 tests
+--echo #
diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h
index 0062d50..5be9c5c 100644
--- a/sql/item_timefunc.h
+++ b/sql/item_timefunc.h
@@ -500,8 +500,16 @@ class Item_temporal_func: public Item_func
   { return  val_decimal_from_date(decimal_value); }
   Field *tmp_table_field(TABLE *table)
   { return tmp_table_field_from_field_type(table, 0); }
+#if MARIADB_VERSION_ID > 100300
+#error This code should be removed in 10.3, to use the derived save_in_field()
+#else
   int save_in_field(Field *field, bool no_conversions)
-  { return save_date_in_field(field); }
+  {
+    return field_type() == MYSQL_TYPE_TIME ?
+           save_time_in_field(field) :
+           save_date_in_field(field);
+  }
+#endif
   void fix_length_and_dec();
 };
 

Follow ups