Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types: handle io.EOF error when to parse datatime #39405

Merged
merged 9 commits into from
Nov 28, 2022
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