From 8e03a974e60c34a6ea8248d9a3645095889c912e Mon Sep 17 00:00:00 2001 From: ono yoko Date: Thu, 25 Jul 2019 16:38:18 +0800 Subject: [PATCH 1/5] fix issue 11304 --- expression/integration_test.go | 7 +++++++ types/time.go | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index 4a158cc2e1b24..bbe8d5cab3e14 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -3512,12 +3512,19 @@ 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, NotNil) + + c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("2008-01-34")), IsTrue) } func (s *testIntegrationSuite) TestTimestampLiteral(c *C) { defer s.cleanEnv(c) + tk := testkit.NewTestKit(c, s.store) + r := tk.MustQuery("select timestamp '2017-01-01 00:00:00';") r.Check(testkit.Rows("2017-01-01 00:00:00")) diff --git a/types/time.go b/types/time.go index 1915b01873629..b67f28749f311 100644 --- a/types/time.go +++ b/types/time.go @@ -1469,8 +1469,9 @@ func checkDateRange(t MysqlTime) error { } func checkMonthDay(year, month, day int, allowInvalidDate bool) error { + dateTimeInStr := fmt.Sprintf("%d-%d-%d", year, month, day) if month < 0 || month > 12 { - return errors.Trace(ErrIncorrectDatetimeValue.GenWithStackByArgs(month)) + return errors.Trace(ErrIncorrectDatetimeValue.GenWithStackByArgs(dateTimeInStr)) } maxDay := 31 @@ -1484,7 +1485,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(dateTimeInStr)) } return nil } From 45d7abc4b57471b18aef466e12be023121c23a07 Mon Sep 17 00:00:00 2001 From: ono yoko Date: Thu, 25 Jul 2019 16:43:55 +0800 Subject: [PATCH 2/5] fmt code --- expression/integration_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index bbe8d5cab3e14..acb4eb7fa9a24 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -3521,9 +3521,8 @@ func (s *testIntegrationSuite) TestTimeLiteral(c *C) { func (s *testIntegrationSuite) TestTimestampLiteral(c *C) { defer s.cleanEnv(c) - - tk := testkit.NewTestKit(c, s.store) + tk := testkit.NewTestKit(c, s.store) r := tk.MustQuery("select timestamp '2017-01-01 00:00:00';") r.Check(testkit.Rows("2017-01-01 00:00:00")) From 542dd903dfe638aa1a66aa3a3240c7079ecbeb29 Mon Sep 17 00:00:00 2001 From: ono yoko Date: Thu, 25 Jul 2019 16:56:20 +0800 Subject: [PATCH 3/5] fix test --- expression/integration_test.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index acb4eb7fa9a24..a066c37c4e0c0 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -3514,14 +3514,12 @@ func (s *testIntegrationSuite) TestTimeLiteral(c *C) { c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("20171231235959.999999")), IsTrue) _, err = tk.Exec("select ADDDATE('2008-01-34', -1);") - c.Assert(err, NotNil) - - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("2008-01-34")), IsTrue) + tk.MustQuery("Show warnings;").Check(testutil.RowsWithSep("|", + "Warning|1292|Incorrect datetime value: '2008-1-34'")) } func (s *testIntegrationSuite) TestTimestampLiteral(c *C) { defer s.cleanEnv(c) - tk := testkit.NewTestKit(c, s.store) r := tk.MustQuery("select timestamp '2017-01-01 00:00:00';") From 99dafae9cf89904366abcc3bd411c38a1fd190ab Mon Sep 17 00:00:00 2001 From: ono yoko Date: Thu, 25 Jul 2019 17:02:50 +0800 Subject: [PATCH 4/5] address reviewer's comment --- types/time.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/types/time.go b/types/time.go index b67f28749f311..cb9355acdafc6 100644 --- a/types/time.go +++ b/types/time.go @@ -1469,9 +1469,8 @@ func checkDateRange(t MysqlTime) error { } func checkMonthDay(year, month, day int, allowInvalidDate bool) error { - dateTimeInStr := fmt.Sprintf("%d-%d-%d", year, month, day) if month < 0 || month > 12 { - return errors.Trace(ErrIncorrectDatetimeValue.GenWithStackByArgs(dateTimeInStr)) + return errors.Trace(ErrIncorrectDatetimeValue.GenWithStackByArgs(fmt.Sprintf("%d-%d-%d", year, month, day))) } maxDay := 31 @@ -1485,7 +1484,7 @@ func checkMonthDay(year, month, day int, allowInvalidDate bool) error { } if day < 0 || day > maxDay { - return errors.Trace(ErrIncorrectDatetimeValue.GenWithStackByArgs(dateTimeInStr)) + return errors.Trace(ErrIncorrectDatetimeValue.GenWithStackByArgs(fmt.Sprintf("%d-%d-%d", year, month, day))) } return nil } From daef27c740d9c9497c662bf4f3e906bb8f4052c4 Mon Sep 17 00:00:00 2001 From: ono yoko Date: Thu, 25 Jul 2019 17:10:28 +0800 Subject: [PATCH 5/5] fix test --- expression/integration_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/expression/integration_test.go b/expression/integration_test.go index a066c37c4e0c0..f896c7929f206 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -3514,6 +3514,7 @@ func (s *testIntegrationSuite) TestTimeLiteral(c *C) { 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'")) }