From 3259a8166ba2e0b840fa5b18e0a6991a8e03063a Mon Sep 17 00:00:00 2001 From: Zejun Li Date: Fri, 11 Jan 2019 18:14:44 +0800 Subject: [PATCH 1/4] types: support sql_mode ALLOW_INVALID_DATES --- executor/executor.go | 12 +++++++++--- executor/insert_test.go | 32 ++++++++++++++++++++++++++++++++ go.mod | 2 ++ go.sum | 1 + sessionctx/stmtctx/stmtctx.go | 1 + types/time.go | 28 ++++++++++++++++------------ 6 files changed, 61 insertions(+), 15 deletions(-) diff --git a/executor/executor.go b/executor/executor.go index 25a27a36b0ca4..eae395c1e153a 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -1277,7 +1277,8 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) { sc.BadNullAsWarning = !vars.StrictSQLMode || stmt.IgnoreErr sc.TruncateAsWarning = !vars.StrictSQLMode || stmt.IgnoreErr sc.DividedByZeroAsWarning = !vars.StrictSQLMode || stmt.IgnoreErr - sc.IgnoreZeroInDate = !vars.StrictSQLMode || stmt.IgnoreErr + sc.AllowInvalidDate = vars.SQLMode&mysql.ModeAllowInvalidDates != 0 + sc.IgnoreZeroInDate = !vars.StrictSQLMode || stmt.IgnoreErr || sc.AllowInvalidDate sc.Priority = stmt.Priority case *ast.DeleteStmt: sc.InDeleteStmt = true @@ -1285,7 +1286,8 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) { sc.BadNullAsWarning = !vars.StrictSQLMode || stmt.IgnoreErr sc.TruncateAsWarning = !vars.StrictSQLMode || stmt.IgnoreErr sc.DividedByZeroAsWarning = !vars.StrictSQLMode || stmt.IgnoreErr - sc.IgnoreZeroInDate = !vars.StrictSQLMode || stmt.IgnoreErr + sc.AllowInvalidDate = vars.SQLMode&mysql.ModeAllowInvalidDates != 0 + sc.IgnoreZeroInDate = !vars.StrictSQLMode || stmt.IgnoreErr || sc.AllowInvalidDate sc.Priority = stmt.Priority case *ast.InsertStmt: sc.InInsertStmt = true @@ -1293,7 +1295,8 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) { sc.BadNullAsWarning = !vars.StrictSQLMode || stmt.IgnoreErr sc.TruncateAsWarning = !vars.StrictSQLMode || stmt.IgnoreErr sc.DividedByZeroAsWarning = !vars.StrictSQLMode || stmt.IgnoreErr - sc.IgnoreZeroInDate = !vars.StrictSQLMode || stmt.IgnoreErr + sc.AllowInvalidDate = vars.SQLMode&mysql.ModeAllowInvalidDates != 0 + sc.IgnoreZeroInDate = !vars.StrictSQLMode || stmt.IgnoreErr || sc.AllowInvalidDate sc.Priority = stmt.Priority case *ast.CreateTableStmt, *ast.AlterTableStmt: // Make sure the sql_mode is strict when checking column default value. @@ -1314,6 +1317,7 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) { // Return warning for truncate error in selection. sc.TruncateAsWarning = true sc.IgnoreZeroInDate = true + sc.AllowInvalidDate = vars.SQLMode&mysql.ModeAllowInvalidDates != 0 if opts := stmt.SelectStmtOpts; opts != nil { sc.Priority = opts.Priority sc.NotFillCache = !opts.SQLCache @@ -1322,6 +1326,7 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) { case *ast.ShowStmt: sc.IgnoreTruncate = true sc.IgnoreZeroInDate = true + sc.AllowInvalidDate = vars.SQLMode&mysql.ModeAllowInvalidDates != 0 if stmt.Tp == ast.ShowWarnings || stmt.Tp == ast.ShowErrors { sc.InShowWarning = true sc.SetWarnings(vars.StmtCtx.GetWarnings()) @@ -1329,6 +1334,7 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) { default: sc.IgnoreTruncate = true sc.IgnoreZeroInDate = true + sc.AllowInvalidDate = vars.SQLMode&mysql.ModeAllowInvalidDates != 0 } vars.PreparedParams = vars.PreparedParams[:0] if !vars.InRestrictedSQL { diff --git a/executor/insert_test.go b/executor/insert_test.go index 2542da7461aca..70fd328282dc5 100644 --- a/executor/insert_test.go +++ b/executor/insert_test.go @@ -14,6 +14,7 @@ package executor_test import ( + "fmt" . "github.com/pingcap/check" "github.com/pingcap/parser/terror" "github.com/pingcap/tidb/table" @@ -233,3 +234,34 @@ func (s *testSuite3) TestInsertZeroYear(c *C) { `2000`, )) } + +func (s *testSuite3) TestAllowInvalidDates(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec(`use test`) + tk.MustExec(`drop table if exists t1;`) + tk.MustExec(`create table t1(d date);`) + tk.MustExec(`create table t2(d datetime);`) + tk.MustExec(`create table t3(d date);`) + tk.MustExec(`create table t4(d datetime);`) + + runWithMode := func(mode string) { + inputs := []string{"0000-00-00", "2019-00-00", "2019-01-00", "2019-00-01", "2019-02-31"} + results := testkit.Rows(`0 0 0`, `2019 0 0`, `2019 1 0`, `2019 0 1`, `2019 2 31`) + + tk.MustExec(`truncate t1;truncate t2;truncate t3;truncate t4;`) + tk.MustExec(fmt.Sprintf(`set sql_mode='%s';`, mode)) + for _, input := range inputs { + tk.MustExec(fmt.Sprintf(`insert into t1 values ('%s')`, input)) + tk.MustExec(fmt.Sprintf(`insert into t2 values ('%s')`, input)) + } + tk.MustQuery(`select year(d), month(d), day(d) from t1;`).Check(results) + tk.MustQuery(`select year(d), month(d), day(d) from t2;`).Check(results) + tk.MustExec(`insert t3 select d from t1;`) + tk.MustQuery(`select year(d), month(d), day(d) from t3;`).Check(results) + tk.MustExec(`insert t4 select d from t2;`) + tk.MustQuery(`select year(d), month(d), day(d) from t4;`).Check(results) + } + + runWithMode("STRICT_TRANS_TABLES,ALLOW_INVALID_DATES") + runWithMode("ALLOW_INVALID_DATES") +} diff --git a/go.mod b/go.mod index 45ba9b40cc01a..e56231709e554 100644 --- a/go.mod +++ b/go.mod @@ -86,3 +86,5 @@ require ( sourcegraph.com/sourcegraph/appdash v0.0.0-20180531100431-4c381bd170b4 sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67 ) + +replace github.com/pingcap/parser => github.com/bobotu/parser v0.0.0-20190111095600-ec4163045017 diff --git a/go.sum b/go.sum index c7358410e7861..fca097ddfce29 100644 --- a/go.sum +++ b/go.sum @@ -7,6 +7,7 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLM github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/blacktear23/go-proxyprotocol v0.0.0-20171102103907-62e368e1c470 h1:AAFU1eDJHimRQvJGBBnhO0Cm4oe7V2GG3CLtiQk/6wg= github.com/blacktear23/go-proxyprotocol v0.0.0-20171102103907-62e368e1c470/go.mod h1:VKt7CNAQxpFpSDz3sXyj9hY/GbVsQCr0sB3w59nE7lU= +github.com/bobotu/parser v0.0.0-20190111095600-ec4163045017/go.mod h1:rtt+tpWlmShJj1sAXi+9oAScwFAWwM8HnLfNOSPqEig= github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= diff --git a/sessionctx/stmtctx/stmtctx.go b/sessionctx/stmtctx/stmtctx.go index 87d856d089c41..ab308f7a8d1dd 100644 --- a/sessionctx/stmtctx/stmtctx.go +++ b/sessionctx/stmtctx/stmtctx.go @@ -63,6 +63,7 @@ type StatementContext struct { PadCharToFullLength bool BatchCheck bool InNullRejectCheck bool + AllowInvalidDate bool // mu struct holds variables that change during execution. mu struct { diff --git a/types/time.go b/types/time.go index 41d32a7422245..7432afbb8a448 100644 --- a/types/time.go +++ b/types/time.go @@ -474,18 +474,20 @@ func (t *Time) FromPackedUint(packed uint64) error { // FIXME: See https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_no_zero_in_date func (t *Time) check(sc *stmtctx.StatementContext) error { allowZeroInDate := false + allowInvalidDate := false // We should avoid passing sc as nil here as far as possible. if sc != nil { allowZeroInDate = sc.IgnoreZeroInDate + allowInvalidDate = sc.AllowInvalidDate } var err error switch t.Type { case mysql.TypeTimestamp: err = checkTimestampType(sc, t.Time) case mysql.TypeDatetime: - err = checkDatetimeType(t.Time, allowZeroInDate) + err = checkDatetimeType(t.Time, allowZeroInDate, allowInvalidDate) case mysql.TypeDate: - err = checkDateType(t.Time, allowZeroInDate) + err = checkDateType(t.Time, allowZeroInDate, allowInvalidDate) } return errors.Trace(err) } @@ -1344,7 +1346,7 @@ func TimeFromDays(num int64) Time { } } -func checkDateType(t MysqlTime, allowZeroInDate bool) error { +func checkDateType(t MysqlTime, allowZeroInDate, allowInvalidDate bool) error { year, month, day := t.Year(), t.Month(), t.Day() if year == 0 && month == 0 && day == 0 { return nil @@ -1358,7 +1360,7 @@ func checkDateType(t MysqlTime, allowZeroInDate bool) error { return errors.Trace(err) } - if err := checkMonthDay(year, month, day); err != nil { + if err := checkMonthDay(year, month, day, allowInvalidDate); err != nil { return errors.Trace(err) } @@ -1377,17 +1379,19 @@ func checkDateRange(t MysqlTime) error { return nil } -func checkMonthDay(year, month, day int) error { +func checkMonthDay(year, month, day int, allowInvalidDate bool) error { if month < 0 || month > 12 { return errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(month)) } maxDay := 31 - if month > 0 { - maxDay = maxDaysInMonth[month-1] - } - if month == 2 && year%4 != 0 { - maxDay = 28 + if !allowInvalidDate { + if month > 0 { + maxDay = maxDaysInMonth[month-1] + } + if month == 2 && year%4 != 0 { + maxDay = 28 + } } if day < 0 || day > maxDay { @@ -1427,8 +1431,8 @@ func checkTimestampType(sc *stmtctx.StatementContext, t MysqlTime) error { return nil } -func checkDatetimeType(t MysqlTime, allowZeroInDate bool) error { - if err := checkDateType(t, allowZeroInDate); err != nil { +func checkDatetimeType(t MysqlTime, allowZeroInDate, allowInvalidDate bool) error { + if err := checkDateType(t, allowZeroInDate, allowInvalidDate); err != nil { return errors.Trace(err) } From 7897e2c8ec131f3051fac529effb227de9acbdff Mon Sep 17 00:00:00 2001 From: Zejun Li Date: Sat, 12 Jan 2019 15:03:53 +0800 Subject: [PATCH 2/4] address comment --- executor/executor.go | 12 ++++++------ executor/insert_test.go | 1 + go.mod | 2 +- go.sum | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/executor/executor.go b/executor/executor.go index eae395c1e153a..650afbc4b08c2 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -1277,7 +1277,7 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) { sc.BadNullAsWarning = !vars.StrictSQLMode || stmt.IgnoreErr sc.TruncateAsWarning = !vars.StrictSQLMode || stmt.IgnoreErr sc.DividedByZeroAsWarning = !vars.StrictSQLMode || stmt.IgnoreErr - sc.AllowInvalidDate = vars.SQLMode&mysql.ModeAllowInvalidDates != 0 + sc.AllowInvalidDate = vars.SQLMode.HasAllowInvalidDatesMode() sc.IgnoreZeroInDate = !vars.StrictSQLMode || stmt.IgnoreErr || sc.AllowInvalidDate sc.Priority = stmt.Priority case *ast.DeleteStmt: @@ -1286,7 +1286,7 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) { sc.BadNullAsWarning = !vars.StrictSQLMode || stmt.IgnoreErr sc.TruncateAsWarning = !vars.StrictSQLMode || stmt.IgnoreErr sc.DividedByZeroAsWarning = !vars.StrictSQLMode || stmt.IgnoreErr - sc.AllowInvalidDate = vars.SQLMode&mysql.ModeAllowInvalidDates != 0 + sc.AllowInvalidDate = vars.SQLMode.HasAllowInvalidDatesMode() sc.IgnoreZeroInDate = !vars.StrictSQLMode || stmt.IgnoreErr || sc.AllowInvalidDate sc.Priority = stmt.Priority case *ast.InsertStmt: @@ -1295,7 +1295,7 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) { sc.BadNullAsWarning = !vars.StrictSQLMode || stmt.IgnoreErr sc.TruncateAsWarning = !vars.StrictSQLMode || stmt.IgnoreErr sc.DividedByZeroAsWarning = !vars.StrictSQLMode || stmt.IgnoreErr - sc.AllowInvalidDate = vars.SQLMode&mysql.ModeAllowInvalidDates != 0 + sc.AllowInvalidDate = vars.SQLMode.HasAllowInvalidDatesMode() sc.IgnoreZeroInDate = !vars.StrictSQLMode || stmt.IgnoreErr || sc.AllowInvalidDate sc.Priority = stmt.Priority case *ast.CreateTableStmt, *ast.AlterTableStmt: @@ -1317,7 +1317,7 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) { // Return warning for truncate error in selection. sc.TruncateAsWarning = true sc.IgnoreZeroInDate = true - sc.AllowInvalidDate = vars.SQLMode&mysql.ModeAllowInvalidDates != 0 + sc.AllowInvalidDate = vars.SQLMode.HasAllowInvalidDatesMode() if opts := stmt.SelectStmtOpts; opts != nil { sc.Priority = opts.Priority sc.NotFillCache = !opts.SQLCache @@ -1326,7 +1326,7 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) { case *ast.ShowStmt: sc.IgnoreTruncate = true sc.IgnoreZeroInDate = true - sc.AllowInvalidDate = vars.SQLMode&mysql.ModeAllowInvalidDates != 0 + sc.AllowInvalidDate = vars.SQLMode.HasAllowInvalidDatesMode() if stmt.Tp == ast.ShowWarnings || stmt.Tp == ast.ShowErrors { sc.InShowWarning = true sc.SetWarnings(vars.StmtCtx.GetWarnings()) @@ -1334,7 +1334,7 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) { default: sc.IgnoreTruncate = true sc.IgnoreZeroInDate = true - sc.AllowInvalidDate = vars.SQLMode&mysql.ModeAllowInvalidDates != 0 + sc.AllowInvalidDate = vars.SQLMode.HasAllowInvalidDatesMode() } vars.PreparedParams = vars.PreparedParams[:0] if !vars.InRestrictedSQL { diff --git a/executor/insert_test.go b/executor/insert_test.go index 70fd328282dc5..4d94bba572564 100644 --- a/executor/insert_test.go +++ b/executor/insert_test.go @@ -15,6 +15,7 @@ package executor_test import ( "fmt" + . "github.com/pingcap/check" "github.com/pingcap/parser/terror" "github.com/pingcap/tidb/table" diff --git a/go.mod b/go.mod index e56231709e554..3858934870eaf 100644 --- a/go.mod +++ b/go.mod @@ -87,4 +87,4 @@ require ( sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67 ) -replace github.com/pingcap/parser => github.com/bobotu/parser v0.0.0-20190111095600-ec4163045017 +replace github.com/pingcap/parser => github.com/bobotu/parser v0.0.0-20190112065818-c102abdccdb1 diff --git a/go.sum b/go.sum index fca097ddfce29..8cab870aec88d 100644 --- a/go.sum +++ b/go.sum @@ -7,7 +7,7 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLM github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/blacktear23/go-proxyprotocol v0.0.0-20171102103907-62e368e1c470 h1:AAFU1eDJHimRQvJGBBnhO0Cm4oe7V2GG3CLtiQk/6wg= github.com/blacktear23/go-proxyprotocol v0.0.0-20171102103907-62e368e1c470/go.mod h1:VKt7CNAQxpFpSDz3sXyj9hY/GbVsQCr0sB3w59nE7lU= -github.com/bobotu/parser v0.0.0-20190111095600-ec4163045017/go.mod h1:rtt+tpWlmShJj1sAXi+9oAScwFAWwM8HnLfNOSPqEig= +github.com/bobotu/parser v0.0.0-20190112065818-c102abdccdb1/go.mod h1:rtt+tpWlmShJj1sAXi+9oAScwFAWwM8HnLfNOSPqEig= github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= From cb5e7fb3a7f01fd1ae8438fc6424de10a7043762 Mon Sep 17 00:00:00 2001 From: Zejun Li Date: Mon, 14 Jan 2019 14:06:56 +0800 Subject: [PATCH 3/4] update go.mod --- go.mod | 4 +--- go.sum | 5 ++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 3858934870eaf..dfd4657d44993 100644 --- a/go.mod +++ b/go.mod @@ -48,7 +48,7 @@ require ( github.com/pingcap/gofail v0.0.0-20181217135706-6a951c1e42c3 github.com/pingcap/goleveldb v0.0.0-20171020122428-b9ff6c35079e github.com/pingcap/kvproto v0.0.0-20181203065228-c14302da291c - github.com/pingcap/parser v0.0.0-20190108104142-35fab0be7fca + github.com/pingcap/parser v0.0.0-20190114060015-cf5695a447d2 github.com/pingcap/pd v2.1.0-rc.4+incompatible github.com/pingcap/tidb-tools v2.1.3-0.20190104033906-883b07a04a73+incompatible github.com/pingcap/tipb v0.0.0-20181012112600-11e33c750323 @@ -86,5 +86,3 @@ require ( sourcegraph.com/sourcegraph/appdash v0.0.0-20180531100431-4c381bd170b4 sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67 ) - -replace github.com/pingcap/parser => github.com/bobotu/parser v0.0.0-20190112065818-c102abdccdb1 diff --git a/go.sum b/go.sum index 8cab870aec88d..491cf454f79ed 100644 --- a/go.sum +++ b/go.sum @@ -7,7 +7,6 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLM github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/blacktear23/go-proxyprotocol v0.0.0-20171102103907-62e368e1c470 h1:AAFU1eDJHimRQvJGBBnhO0Cm4oe7V2GG3CLtiQk/6wg= github.com/blacktear23/go-proxyprotocol v0.0.0-20171102103907-62e368e1c470/go.mod h1:VKt7CNAQxpFpSDz3sXyj9hY/GbVsQCr0sB3w59nE7lU= -github.com/bobotu/parser v0.0.0-20190112065818-c102abdccdb1/go.mod h1:rtt+tpWlmShJj1sAXi+9oAScwFAWwM8HnLfNOSPqEig= github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= @@ -111,8 +110,8 @@ github.com/pingcap/goleveldb v0.0.0-20171020122428-b9ff6c35079e h1:P73/4dPCL96rG github.com/pingcap/goleveldb v0.0.0-20171020122428-b9ff6c35079e/go.mod h1:O17XtbryoCJhkKGbT62+L2OlrniwqiGLSqrmdHCMzZw= github.com/pingcap/kvproto v0.0.0-20181203065228-c14302da291c h1:Qf5St5XGwKgKQLar9lEXoeO0hJMVaFBj3JqvFguWtVg= github.com/pingcap/kvproto v0.0.0-20181203065228-c14302da291c/go.mod h1:Ja9XPjot9q4/3JyCZodnWDGNXt4pKemhIYCvVJM7P24= -github.com/pingcap/parser v0.0.0-20190108104142-35fab0be7fca h1:BIk063GpkHOJzR4Bp9I8xfsjp3nSvElvhIUjDgmInoo= -github.com/pingcap/parser v0.0.0-20190108104142-35fab0be7fca/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA= +github.com/pingcap/parser v0.0.0-20190114060015-cf5695a447d2 h1:5RdXoZ6io7x1qXu6GSmOn8uqhdBA2RJpl6XCMVLNAEM= +github.com/pingcap/parser v0.0.0-20190114060015-cf5695a447d2/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA= github.com/pingcap/pd v2.1.0-rc.4+incompatible h1:/buwGk04aHO5odk/+O8ZOXGs4qkUjYTJ2UpCJXna8NE= github.com/pingcap/pd v2.1.0-rc.4+incompatible/go.mod h1:nD3+EoYes4+aNNODO99ES59V83MZSI+dFbhyr667a0E= github.com/pingcap/tidb-tools v2.1.3-0.20190104033906-883b07a04a73+incompatible h1:Ba48wwPwPq5hd1kkQpgua49dqB5cthC2zXVo7fUUDec= From 5f30947aa1358d8eb1651c425c6e5b96ed2bd949 Mon Sep 17 00:00:00 2001 From: Zejun Li Date: Mon, 14 Jan 2019 17:14:45 +0800 Subject: [PATCH 4/4] address comment --- executor/insert_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/executor/insert_test.go b/executor/insert_test.go index 4d94bba572564..216ec0c10a87d 100644 --- a/executor/insert_test.go +++ b/executor/insert_test.go @@ -239,7 +239,7 @@ func (s *testSuite3) TestInsertZeroYear(c *C) { func (s *testSuite3) TestAllowInvalidDates(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec(`use test`) - tk.MustExec(`drop table if exists t1;`) + tk.MustExec(`drop table if exists t1, t2, t3, t4;`) tk.MustExec(`create table t1(d date);`) tk.MustExec(`create table t2(d datetime);`) tk.MustExec(`create table t3(d date);`) @@ -248,6 +248,10 @@ func (s *testSuite3) TestAllowInvalidDates(c *C) { runWithMode := func(mode string) { inputs := []string{"0000-00-00", "2019-00-00", "2019-01-00", "2019-00-01", "2019-02-31"} results := testkit.Rows(`0 0 0`, `2019 0 0`, `2019 1 0`, `2019 0 1`, `2019 2 31`) + oldMode := tk.MustQuery(`select @@sql_mode`).Rows()[0][0] + defer func() { + tk.MustExec(fmt.Sprintf(`set sql_mode='%s'`, oldMode)) + }() tk.MustExec(`truncate t1;truncate t2;truncate t3;truncate t4;`) tk.MustExec(fmt.Sprintf(`set sql_mode='%s';`, mode))