Skip to content

Commit

Permalink
expression: improve the compatibility with mysql when datatime… (#11447)
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot authored and zz-jason committed Jul 30, 2019
1 parent 761ba58 commit c71adf9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
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

0 comments on commit c71adf9

Please sign in to comment.