Skip to content

Commit

Permalink
expression: fix compatibility behaviors in time_format with MySQL (pi…
Browse files Browse the repository at this point in the history
  • Loading branch information
wshwsh12 authored Dec 17, 2020
1 parent 556cccc commit b25f62d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions expression/builtin_cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,9 @@ func (b *builtinCastIntAsDurationSig) evalDuration(row chunk.Row) (res types.Dur
if types.ErrOverflow.Equal(err) {
err = b.ctx.GetSessionVars().StmtCtx.HandleOverflow(err, err)
}
if types.ErrTruncatedWrongVal.Equal(err) {
err = b.ctx.GetSessionVars().StmtCtx.HandleTruncate(err)
}
return res, true, err
}
return dur, false, err
Expand Down
3 changes: 3 additions & 0 deletions expression/builtin_cast_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ func (b *builtinCastIntAsDurationSig) vecEvalDuration(input *chunk.Chunk, result
if types.ErrOverflow.Equal(err) {
err = b.ctx.GetSessionVars().StmtCtx.HandleOverflow(err, err)
}
if types.ErrTruncatedWrongVal.Equal(err) {
err = b.ctx.GetSessionVars().StmtCtx.HandleTruncate(err)
}
if err != nil {
return err
}
Expand Down
11 changes: 11 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8324,6 +8324,17 @@ func (s *testIntegrationSuite) TestIssue12205(c *C) {
testkit.Rows("Warning 1292 Truncated incorrect time value: '18446744072635875000'"))
}

func (s *testSuite) TestIssue12206(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t12206;")
tk.MustExec("create table t12206(\n `col_tinyint_unsigned` tinyint(3) unsigned DEFAULT NULL,\n `col_double_unsigned` double unsigned DEFAULT NULL,\n `col_year_key` year(4) DEFAULT NULL\n);")
tk.MustExec("insert into t12206 values(73,0,0000);")
tk.MustQuery("SELECT TIME_FORMAT( `col_tinyint_unsigned`, ( IFNULL( `col_double_unsigned`, `col_year_key` ) ) ) AS field1 FROM `t12206`;").Check(
testkit.Rows("<nil>"))
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1292 Truncated incorrect time value: '73'"))
}

func (s *testIntegrationSuite2) TestCastCoer(c *C) {
tk := testkit.NewTestKit(c, s.store)

Expand Down
2 changes: 1 addition & 1 deletion types/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func NumberToDuration(number int64, fsp int8) (Duration, error) {
}

if number/10000 > TimeMaxHour || number%100 >= 60 || (number/100)%100 >= 60 {
return ZeroDuration, errors.Trace(ErrWrongValue.GenWithStackByArgs(TimeStr, strconv.FormatInt(number, 10)))
return ZeroDuration, errors.Trace(ErrTruncatedWrongVal.GenWithStackByArgs(TimeStr, strconv.FormatInt(number, 10)))
}
dur := NewDuration(int(number/10000), int((number/100)%100), int(number%100), 0, fsp)
if neg {
Expand Down

0 comments on commit b25f62d

Please sign in to comment.