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: improve the compatibility with mysql when datatime is invalid. (#11445) #11447

Merged
merged 10 commits into from
Jul 30, 2019
5 changes: 5 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3528,6 +3528,11 @@ func (s *testIntegrationSuite) TestTimeLiteral(c *C) {
_, err = tk.Exec("select time '20171231235959.999999';")
c.Assert(err, NotNil)
c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("20171231235959.999999")), IsTrue)

_, err = tk.Exec("select ADDDATE('2008-01-34', -1);")
c.Assert(err, IsNil)
tk.MustQuery("Show warnings;").Check(testutil.RowsWithSep("|",
"Warning|1292|Incorrect datetime value: '2008-1-34'"))
}

func (s *testIntegrationSuite) TestTimestampLiteral(c *C) {
Expand Down
4 changes: 2 additions & 2 deletions types/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ func checkDateRange(t MysqlTime) error {

func checkMonthDay(year, month, day int, allowInvalidDate bool) error {
if month < 0 || month > 12 {
return errors.Trace(ErrIncorrectDatetimeValue.GenWithStackByArgs(month))
return errors.Trace(ErrIncorrectDatetimeValue.GenWithStackByArgs(fmt.Sprintf("%d-%d-%d", year, month, day)))
}

maxDay := 31
Expand All @@ -1484,7 +1484,7 @@ func checkMonthDay(year, month, day int, allowInvalidDate bool) error {
}

if day < 0 || day > maxDay {
return errors.Trace(ErrIncorrectDatetimeValue.GenWithStackByArgs(day))
return errors.Trace(ErrIncorrectDatetimeValue.GenWithStackByArgs(fmt.Sprintf("%d-%d-%d", year, month, day)))
}
return nil
}
Expand Down