Skip to content

Commit

Permalink
fix(tianmu): fix bug: Convert DATETIME to TIME type error. (stoneatom…
Browse files Browse the repository at this point in the history
…#995)

[summary]
1 treat zero data legal;
  • Loading branch information
lujiashun authored and konghaiya committed Mar 7, 2023
1 parent 0accba9 commit deaf4c6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
15 changes: 15 additions & 0 deletions mysql-test/suite/tianmu/r/issue995.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
USE test;
CREATE TABLE t1 (a CHAR(1), b INT, c DATETIME, d DOUBLE);
INSERT INTO t1 VALUES ('', NULL, '0-0-0', NULL),
('a', 12, '1212-12-12', 1.19691E+100),
('b', 13, '1313-3-13 13:13:13', 2.1961E+18),
('c', 14, '1414-4-14', 0.16191),
('d', 15, '2015-5-15 15:15:15', 1.971917);
SELECT CONVERT(c, TIME) FROM t1;
CONVERT(c, TIME)
00:00:00
00:00:00
13:13:13
00:00:00
15:15:15
DROP TABLE t1;
1 change: 1 addition & 0 deletions mysql-test/suite/tianmu/t/issue995-master.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--sql_mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
14 changes: 14 additions & 0 deletions mysql-test/suite/tianmu/t/issue995.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--source include/have_tianmu.inc

USE test;

CREATE TABLE t1 (a CHAR(1), b INT, c DATETIME, d DOUBLE);

INSERT INTO t1 VALUES ('', NULL, '0-0-0', NULL),
('a', 12, '1212-12-12', 1.19691E+100),
('b', 13, '1313-3-13 13:13:13', 2.1961E+18),
('c', 14, '1414-4-14', 0.16191),
('d', 15, '2015-5-15 15:15:15', 1.971917);

SELECT CONVERT(c, TIME) FROM t1;
DROP TABLE t1;
9 changes: 5 additions & 4 deletions storage/tianmu/core/item_tianmu_field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,11 @@ bool Item_tianmufield::get_date(MYSQL_TIME *ltime, uint fuzzydate) {
}

bool Item_tianmufield::get_time(MYSQL_TIME *ltime) {
if ((null_value = buf->null) ||
((tianmu_type.attrtype == common::ColumnType::DATETIME || tianmu_type.attrtype == common::ColumnType::DATE) &&
buf->x == 0)) // zero date is illegal
return 1; // like in Item_field::get_time - return 1 on null value.
// Consider zero date is legal , not consider the sql_mode NO_ZERO_DATE/NO_ZERO_IN_DATE.
// Because NO_ZERO_DATE/NO_ZERO_IN_DATE is deprecated; expect it to be removed in a future
// release of MySQL as a separate mode name and its effect included in the effects of strict SQL mode.
if ((null_value = buf->null))
return 1; // like in Item_field::get_time - return 1 on null value.
FeedValue();
return ivalue->get_time(ltime);
}
Expand Down

0 comments on commit deaf4c6

Please sign in to comment.