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

expression: fix inaccurate error info for year column out of range (#18871) #20170

Merged
merged 3 commits into from
Oct 3, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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