Skip to content

Commit

Permalink
expression: fix inaccurate error info for year column out of range (#…
Browse files Browse the repository at this point in the history
…18871) (#20170)

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
ti-srebot authored Oct 3, 2020
1 parent 6efcee0 commit 8a40601
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions executor/insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ func (s *testSuite3) TestInsertWrongValueForField(c *C) {
tk.MustExec(`create table t1(a bigint);`)
_, err := tk.Exec(`insert into t1 values("asfasdfsajhlkhlksdaf");`)
c.Assert(terror.ErrorEqual(err, table.ErrTruncatedWrongValueForField), IsTrue)

tk.MustExec(`drop table if exists t;`)
tk.MustExec(`create table t (a year);`)
_, err = tk.Exec(`insert into t values(2156);`)
c.Assert(err.Error(), Equals, `[types:1264]Out of range value for column 'a' at row 1`)
}

func (s *testSuite3) TestInsertDateTimeWithTimeZone(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1469,7 +1469,7 @@ func (s *testSuite8) TestUpdate(c *C) {
tk.MustExec("drop table t")
tk.MustExec("CREATE TABLE `t` ( `c1` year DEFAULT NULL, `c2` year DEFAULT NULL, `c3` date DEFAULT NULL, `c4` datetime DEFAULT NULL, KEY `idx` (`c1`,`c2`))")
_, err = tk.Exec("UPDATE t SET c2=16777215 WHERE c1>= -8388608 AND c1 < -9 ORDER BY c1 LIMIT 2")
c.Assert(err.Error(), Equals, "cannot convert datum from bigint to type year.")
c.Assert(err.Error(), Equals, "[types:1690]DECIMAL value is out of range in '(4, 0)'")

tk.MustExec("update (select * from t) t set c1 = 1111111")

Expand Down
2 changes: 1 addition & 1 deletion types/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ func (d *Datum) convertToMysqlYear(sc *stmtctx.StatementContext, target *FieldTy
}
y, err = AdjustYear(y, adjust)
if err != nil {
_, err = invalidConv(d, target.Tp)
err = ErrOverflow.GenWithStackByArgs("DECIMAL", fmt.Sprintf("(%d, %d)", target.Flen, target.Decimal))
}
ret.SetInt64(y)
return ret, err
Expand Down

0 comments on commit 8a40601

Please sign in to comment.