Skip to content

Commit

Permalink
types: handle io.EOF error when to parse datatime (#39405)
Browse files Browse the repository at this point in the history
close #35678
  • Loading branch information
hawkingrei authored Nov 28, 2022
1 parent 0e6364f commit f713bc9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions executor/executor_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions types/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"math"
"regexp"
"strconv"
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit f713bc9

Please sign in to comment.