From f713bc90ff16b23711846f7fa862bc151b9533e2 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Mon, 28 Nov 2022 15:22:00 +0800 Subject: [PATCH] types: handle io.EOF error when to parse datatime (#39405) close pingcap/tidb#35678 --- executor/executor_issue_test.go | 3 +++ types/time.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/executor/executor_issue_test.go b/executor/executor_issue_test.go index 5d2912f78f449..6417d663d3790 100644 --- a/executor/executor_issue_test.go +++ b/executor/executor_issue_test.go @@ -684,6 +684,9 @@ func TestIssue22231(t *testing.T) { tk.MustQuery("select cast('2020-05-28 23:59:59 00:00:00' as datetime)").Check(testkit.Rows("2020-05-28 23:59:59")) tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1292 Truncated incorrect datetime value: '2020-05-28 23:59:59 00:00:00'")) tk.MustExec("drop table if exists t_issue_22231") + + tk.MustQuery("SELECT CAST(\"1111111111-\" AS DATE);") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '1111111111-'")) } // TestIssue2612 is related with https://github.com/pingcap/tidb/issues/2612 diff --git a/types/time.go b/types/time.go index 974b69602dd63..ebdfc462d8cdb 100644 --- a/types/time.go +++ b/types/time.go @@ -18,6 +18,7 @@ import ( "bytes" "encoding/json" "fmt" + "io" "math" "regexp" "strconv" @@ -1155,6 +1156,9 @@ func parseDatetime(sc *stmtctx.StatementContext, str string, fsp int, isFloat bo hhmmss = true } if err != nil { + if err == io.EOF { + return ZeroDatetime, errors.Trace(ErrWrongValue.GenWithStackByArgs(DateTimeStr, str)) + } return ZeroDatetime, errors.Trace(err) }