Skip to content

Commit

Permalink
types: convert EOF error to ErrTruncate when parse duration (#11865) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot authored and ngaut committed Aug 28, 2019
1 parent dfcd94c commit af2d78d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2029,6 +2029,17 @@ func (s *testIntegrationSuite) TestTimeBuiltin(c *C) {
result.Check(testkit.Rows("<nil>"))
result = tk.MustQuery(`select tidb_parse_tso(-1)`)
result.Check(testkit.Rows("<nil>"))

// 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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"bytes"
"context"
"fmt"
"io"
"math"
"regexp"
"strconv"
Expand Down Expand Up @@ -1169,6 +1170,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

0 comments on commit af2d78d

Please sign in to comment.