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: convert EOF error to ErrTruncate when parse duration (#11865) #11910

Merged
merged 4 commits into from Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions expression/integration_test.go
Expand Up @@ -1892,6 +1892,17 @@ func (s *testIntegrationSuite) TestTimeBuiltin(c *C) {
// for current_timestamp, current_timestamp()
result = tk.MustQuery(`select current_timestamp() = now(), current_timestamp = now()`)
result.Check(testkit.Rows("1 1"))

// fix issue 10308
result = tk.MustQuery("select time(\"- -\");")
result.Check(testkit.Rows("00:00:00"))
tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1292 Truncated incorrect time value: '- -'"))
result = tk.MustQuery("select time(\"---1\");")
result.Check(testkit.Rows("00:00:00"))
tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1292 Truncated incorrect time value: '---1'"))
result = tk.MustQuery("select time(\"-- --1\");")
result.Check(testkit.Rows("00:00:00"))
tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1292 Truncated incorrect time value: '-- --1'"))
}

func (s *testIntegrationSuite) TestOpBuiltin(c *C) {
Expand Down
4 changes: 4 additions & 0 deletions types/time.go
Expand Up @@ -17,6 +17,7 @@ import (
"bytes"
"context"
"fmt"
"io"
"math"
"regexp"
"strconv"
Expand Down Expand Up @@ -1162,6 +1163,9 @@ func ParseDuration(sc *stmtctx.StatementContext, str string, fsp int) (Duration,
return ZeroDuration, ErrTruncatedWrongVal.GenWithStackByArgs("time", origStr)
}

if terror.ErrorEqual(err, io.EOF) {
err = ErrTruncatedWrongVal.GenWithStackByArgs("time", origStr)
}
if err != nil {
return ZeroDuration, errors.Trace(err)
}
Expand Down