diff --git a/executor/insert_common.go b/executor/insert_common.go index 6c567116e5173..b9dca684c639a 100644 --- a/executor/insert_common.go +++ b/executor/insert_common.go @@ -245,21 +245,34 @@ func (e *InsertValues) handleErr(col *table.Column, val *types.Datum, rowIdx int return nil } - if types.ErrDataTooLong.Equal(err) { - return resetErrDataTooLong(col.Name.O, rowIdx+1, err) + // Convert the error with full messages. + var ( + colTp byte + colName string + ) + if col != nil { + colTp = col.Tp + colName = col.Name.String() } - if types.ErrOverflow.Equal(err) { - return types.ErrWarnDataOutOfRange.GenWithStackByArgs(col.Name.O, rowIdx+1) - } - if types.ErrTruncated.Equal(err) { + if types.ErrDataTooLong.Equal(err) { + err = resetErrDataTooLong(colName, rowIdx+1, err) + } else if types.ErrOverflow.Equal(err) { + err = types.ErrWarnDataOutOfRange.GenWithStackByArgs(colName, rowIdx+1) + } else if types.ErrTruncated.Equal(err) || types.ErrTruncatedWrongVal.Equal(err) { valStr, err1 := val.ToString() if err1 != nil { logutil.BgLogger().Warn("truncate value failed", zap.Error(err1)) } - return table.ErrTruncatedWrongValueForField.GenWithStackByArgs(types.TypeStr(col.Tp), valStr, col.Name.O, rowIdx+1) + err = table.ErrTruncatedWrongValueForField.GenWithStackByArgs(types.TypeStr(colTp), valStr, colName, rowIdx+1) } - return e.filterErr(err) + + if !e.ctx.GetSessionVars().StmtCtx.DupKeyAsWarning { + return err + } + // TODO: should not filter all types of errors here. + e.handleWarning(err) + return nil } // evalRow evaluates a to-be-inserted row. The value of the column may base on another column, @@ -346,7 +359,7 @@ func (e *InsertValues) setValueForRefColumn(row []types.Datum, hasValue []bool) } else if table.ErrNoDefaultValue.Equal(err) { row[i] = table.GetZeroValue(c.ToInfo()) hasValue[c.Offset] = false - } else if e.filterErr(err) != nil { + } else if e.handleErr(c, &d, 0, err) != nil { return err } } @@ -426,7 +439,7 @@ func (e *InsertValues) getRow(ctx context.Context, vals []types.Datum) ([]types. hasValue := make([]bool, len(e.Table.Cols())) for i, v := range vals { casted, err := table.CastValue(e.ctx, v, e.insertColumns[i].ToInfo()) - if e.filterErr(err) != nil { + if e.handleErr(nil, &v, 0, err) != nil { return nil, err } @@ -442,7 +455,7 @@ func (e *InsertValues) getRowInPlace(ctx context.Context, vals []types.Datum, ro hasValue := make([]bool, len(e.Table.Cols())) for i, v := range vals { casted, err := table.CastValue(e.ctx, v, e.insertColumns[i].ToInfo()) - if e.filterErr(err) != nil { + if e.handleErr(nil, &v, 0, err) != nil { return nil, err } offset := e.insertColumns[i].Offset @@ -452,18 +465,6 @@ func (e *InsertValues) getRowInPlace(ctx context.Context, vals []types.Datum, ro return e.fillRow(ctx, rowBuf, hasValue) } -func (e *InsertValues) filterErr(err error) error { - if err == nil { - return nil - } - if !e.ctx.GetSessionVars().StmtCtx.DupKeyAsWarning { - return err - } - // TODO: should not filter all types of errors here. - e.handleWarning(err) - return nil -} - // getColDefaultValue gets the column default value. func (e *InsertValues) getColDefaultValue(idx int, col *table.Column) (d types.Datum, err error) { if e.colDefaultVals != nil && e.colDefaultVals[idx].valid { @@ -502,7 +503,7 @@ func (e *InsertValues) fillColValue(ctx context.Context, datum types.Datum, idx } if !hasValue { d, err := e.getColDefaultValue(idx, column) - if e.filterErr(err) != nil { + if e.handleErr(column, &datum, 0, err) != nil { return types.Datum{}, err } return d, nil @@ -538,7 +539,7 @@ func (e *InsertValues) fillRow(ctx context.Context, row []types.Datum, hasValue for i, gCol := range gCols { colIdx := gCol.ColumnInfo.Offset val, err := e.GenExprs[i].Eval(chunk.MutRowFromDatums(row).ToRow()) - if e.filterErr(err) != nil { + if e.handleErr(gCol, &val, 0, err) != nil { return nil, err } row[colIdx], err = table.CastValue(e.ctx, val, gCol.ToInfo()) @@ -670,7 +671,7 @@ func (e *InsertValues) lazyAdjustAutoIncrementDatum(ctx context.Context, rows [] // Alloc batch N consecutive (min, max] autoIDs. // max value can be derived from adding one for cnt times. min, _, err := table.AllocBatchAutoIncrementValue(ctx, e.Table, e.ctx, cnt) - if e.filterErr(err) != nil { + if e.handleErr(col, &autoDatum, cnt, err) != nil { return nil, err } // It's compatible with mysql setting the first allocated autoID to lastInsertID. @@ -747,7 +748,7 @@ func (e *InsertValues) adjustAutoIncrementDatum(ctx context.Context, d types.Dat // Change value 0 to auto id, if NoAutoValueOnZero SQL mode is not set. if d.IsNull() || e.ctx.GetSessionVars().SQLMode&mysql.ModeNoAutoValueOnZero == 0 { recordID, err = table.AllocAutoIncrementValue(ctx, e.Table, e.ctx) - if e.filterErr(err) != nil { + if e.handleErr(c, &d, 0, err) != nil { return types.Datum{}, err } // It's compatible with mysql setting the first allocated autoID to lastInsertID. diff --git a/executor/show_test.go b/executor/show_test.go index 6c099b83c18d0..68ff9a164d2c4 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -105,9 +105,9 @@ func (s *testSuite5) TestShowWarnings(c *C) { tk.MustExec("set @@sql_mode=''") tk.MustExec("insert show_warnings values ('a')") c.Assert(tk.Se.GetSessionVars().StmtCtx.WarningCount(), Equals, uint16(1)) - tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1265|Data Truncated")) + tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect FLOAT value: 'a'")) c.Assert(tk.Se.GetSessionVars().StmtCtx.WarningCount(), Equals, uint16(0)) - tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1265|Data Truncated")) + tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect FLOAT value: 'a'")) c.Assert(tk.Se.GetSessionVars().StmtCtx.WarningCount(), Equals, uint16(0)) // Test Warning level 'Error' diff --git a/executor/write_test.go b/executor/write_test.go index befb96ae317e3..85ab105728040 100644 --- a/executor/write_test.go +++ b/executor/write_test.go @@ -209,7 +209,7 @@ func (s *testSuite4) TestInsert(c *C) { tk.MustExec("CREATE TABLE t(a DECIMAL(4,2));") tk.MustExec("INSERT INTO t VALUES (1.000001);") r = tk.MustQuery("SHOW WARNINGS;") - r.Check(testkit.Rows("Warning 1265 Data Truncated")) + r.Check(testkit.Rows("Warning 1292 Truncated incorrect DECIMAL value: '1.000001'")) tk.MustExec("INSERT INTO t VALUES (1.000000);") r = tk.MustQuery("SHOW WARNINGS;") r.Check(testkit.Rows()) @@ -268,7 +268,7 @@ func (s *testSuite4) TestInsert(c *C) { tk.MustExec("insert into t value(20070219173709.055870), (20070219173709.055), (20070219173709.055870123)") tk.MustQuery("select * from t").Check(testkit.Rows("17:37:09.055870", "17:37:09.055000", "17:37:09.055870")) _, err = tk.Exec("insert into t value(-20070219173709.055870)") - c.Assert(err.Error(), Equals, "[types:1292]Incorrect time value: '-20070219173709.055870'") + c.Assert(err.Error(), Equals, "[types:1525]Incorrect time value: '-20070219173709.055870'") tk.MustExec("drop table if exists t") tk.MustExec("set @@sql_mode=''") @@ -496,13 +496,13 @@ func (s *testSuite4) TestInsertIgnore(c *C) { c.Assert(err, IsNil) tk.CheckLastMessage("Records: 1 Duplicates: 0 Warnings: 1") r = tk.MustQuery("SHOW WARNINGS") - r.Check(testkit.Rows("Warning 1265 Data Truncated")) + r.Check(testkit.Rows("Warning 1292 Truncated incorrect FLOAT value: '1a'")) testSQL = "insert ignore into t values ('1a')" _, err = tk.Exec(testSQL) c.Assert(err, IsNil) tk.CheckLastMessage("") r = tk.MustQuery("SHOW WARNINGS") - r.Check(testkit.Rows("Warning 1265 Data Truncated")) + r.Check(testkit.Rows("Warning 1292 Truncated incorrect FLOAT value: '1a'")) // for duplicates with warning testSQL = `drop table if exists t; @@ -1390,7 +1390,7 @@ func (s *testSuite8) TestUpdate(c *C) { _, err = tk.Exec("update ignore t set a = 1 where a = (select '2a')") c.Assert(err, IsNil) r = tk.MustQuery("SHOW WARNINGS;") - r.Check(testkit.Rows("Warning 1265 Data Truncated", "Warning 1265 Data Truncated", "Warning 1062 Duplicate entry '1' for key 'PRIMARY'")) + r.Check(testkit.Rows("Warning 1292 Truncated incorrect FLOAT value: '2a'", "Warning 1292 Truncated incorrect FLOAT value: '2a'", "Warning 1062 Duplicate entry '1' for key 'PRIMARY'")) tk.MustExec("update ignore t set a = 42 where a = 2;") tk.MustQuery("select * from t").Check(testkit.Rows("1", "42")) @@ -1453,7 +1453,7 @@ func (s *testSuite8) TestUpdate(c *C) { // A warning rather than data truncated error. tk.MustExec("update decimals set a = a + 1.23;") tk.CheckLastMessage("Rows matched: 1 Changed: 1 Warnings: 1") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1265 Data Truncated")) + tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1292 Truncated incorrect DECIMAL value: '202.23'")) r = tk.MustQuery("select * from decimals") r.Check(testkit.Rows("202")) @@ -1640,7 +1640,7 @@ func (s *testSuite4) TestPartitionedTableUpdate(c *C) { _, err = tk.Exec("update ignore t set a = 1 where a = (select '2a')") c.Assert(err, IsNil) r = tk.MustQuery("SHOW WARNINGS;") - r.Check(testkit.Rows("Warning 1265 Data Truncated", "Warning 1265 Data Truncated")) + r.Check(testkit.Rows("Warning 1292 Truncated incorrect FLOAT value: '2a'", "Warning 1292 Truncated incorrect FLOAT value: '2a'")) // test update ignore for unique key tk.MustExec("drop table if exists t;") @@ -1802,7 +1802,7 @@ func (s *testSuite) TestDelete(c *C) { c.Assert(err, IsNil) tk.CheckExecResult(1, 0) r := tk.MustQuery("SHOW WARNINGS;") - r.Check(testkit.Rows("Warning 1265 Data Truncated", "Warning 1265 Data Truncated")) + r.Check(testkit.Rows("Warning 1292 Truncated incorrect FLOAT value: '2a'", "Warning 1292 Truncated incorrect FLOAT value: '2a'")) tk.MustExec(`delete from delete_test ;`) tk.CheckExecResult(1, 0) @@ -1848,7 +1848,7 @@ func (s *testSuite4) TestPartitionedTableDelete(c *C) { c.Assert(err, IsNil) tk.CheckExecResult(1, 0) r := tk.MustQuery("SHOW WARNINGS;") - r.Check(testkit.Rows("Warning 1265 Data Truncated", "Warning 1265 Data Truncated")) + r.Check(testkit.Rows("Warning 1292 Truncated incorrect FLOAT value: '2a'", "Warning 1292 Truncated incorrect FLOAT value: '2a'")) // Test delete without using index, involve multiple partitions. tk.MustExec("delete from t ignore index(id) where id >= 13 and id <= 17") diff --git a/expression/builtin_string_test.go b/expression/builtin_string_test.go index 1604a1368ee7f..eeee5aad9e4fa 100644 --- a/expression/builtin_string_test.go +++ b/expression/builtin_string_test.go @@ -1813,7 +1813,7 @@ func (s *testEvaluatorSuite) TestFormat(c *C) { warnings := s.ctx.GetSessionVars().StmtCtx.GetWarnings() c.Assert(len(warnings), Equals, tt.warnings, Commentf("test %v", tt)) for i := 0; i < tt.warnings; i++ { - c.Assert(terror.ErrorEqual(types.ErrTruncated, warnings[i].Err), IsTrue, Commentf("test %v", tt)) + c.Assert(terror.ErrorEqual(types.ErrTruncatedWrongVal, warnings[i].Err), IsTrue, Commentf("test %v", tt)) } s.ctx.GetSessionVars().StmtCtx.SetWarnings([]stmtctx.SQLWarn{}) } diff --git a/expression/builtin_time.go b/expression/builtin_time.go index 26f60cd70dc80..41b339dca9189 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -293,7 +293,7 @@ func (b *builtinDateSig) evalTime(row chunk.Row) (types.Time, bool, error) { } if expr.IsZero() { - return types.Time{}, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(expr.String())) + return types.Time{}, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, expr.String())) } expr.Time = types.FromDate(expr.Time.Year(), expr.Time.Month(), expr.Time.Day(), 0, 0, 0, 0) @@ -319,7 +319,7 @@ func (c *dateLiteralFunctionClass) getFunction(ctx sessionctx.Context, args []Ex } str := dt.GetString() if !datePattern.MatchString(str) { - return nil, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(str) + return nil, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, str) } tm, err := types.ParseDate(ctx.GetSessionVars().StmtCtx, str) if err != nil { @@ -347,10 +347,10 @@ func (b *builtinDateLiteralSig) Clone() builtinFunc { func (b *builtinDateLiteralSig) evalTime(row chunk.Row) (types.Time, bool, error) { mode := b.ctx.GetSessionVars().SQLMode if mode.HasNoZeroDateMode() && b.literal.IsZero() { - return b.literal, true, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(b.literal.String()) + return b.literal, true, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, b.literal.String()) } if mode.HasNoZeroInDateMode() && (b.literal.InvalidZero() && !b.literal.IsZero()) { - return b.literal, true, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(b.literal.String()) + return b.literal, true, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, b.literal.String()) } return b.literal, false, nil } @@ -392,10 +392,10 @@ func (b *builtinDateDiffSig) evalInt(row chunk.Row) (int64, bool, error) { } if invalidLHS, invalidRHS := lhs.InvalidZero(), rhs.InvalidZero(); invalidLHS || invalidRHS { if invalidLHS { - err = handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(lhs.String())) + err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, lhs.String())) } if invalidRHS { - err = handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(rhs.String())) + err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, rhs.String())) } return 0, true, err } @@ -822,7 +822,7 @@ func (b *builtinDateFormatSig) evalString(row chunk.Row) (string, bool, error) { if isOriginalIntOrDecimalZero && !isOriginalStringZero { return "", true, nil } - return "", true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(t.String())) + return "", true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())) } res, err := t.DateFormat(formatMask) @@ -1045,7 +1045,7 @@ func (b *builtinMonthSig) evalInt(row chunk.Row) (int64, bool, error) { if date.IsZero() { if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() { - return 0, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(date.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) } return 0, false, nil } @@ -1086,7 +1086,7 @@ func (b *builtinMonthNameSig) evalString(row chunk.Row) (string, bool, error) { } mon := arg.Time.Month() if (arg.IsZero() && b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode()) || mon < 0 || mon > len(types.MonthNames) { - return "", true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(arg.String())) + return "", true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())) } else if mon == 0 || arg.IsZero() { return "", true, nil } @@ -1124,7 +1124,7 @@ func (b *builtinDayNameSig) evalIndex(row chunk.Row) (int64, bool, error) { return 0, isNull, err } if arg.InvalidZero() { - return 0, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(arg.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())) } // Monday is 0, ... Sunday = 6 in MySQL // but in go, Sunday is 0, ... Saturday is 6 @@ -1193,7 +1193,7 @@ func (b *builtinDayOfMonthSig) evalInt(row chunk.Row) (int64, bool, error) { } if arg.IsZero() { if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() { - return 0, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(arg.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())) } return 0, false, nil } @@ -1233,7 +1233,7 @@ func (b *builtinDayOfWeekSig) evalInt(row chunk.Row) (int64, bool, error) { return 0, true, handleInvalidTimeError(b.ctx, err) } if arg.InvalidZero() { - return 0, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(arg.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())) } // 1 is Sunday, 2 is Monday, .... 7 is Saturday return int64(arg.Time.Weekday() + 1), false, nil @@ -1272,7 +1272,7 @@ func (b *builtinDayOfYearSig) evalInt(row chunk.Row) (int64, bool, error) { return 0, isNull, handleInvalidTimeError(b.ctx, err) } if arg.InvalidZero() { - return 0, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(arg.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())) } return int64(arg.Time.YearDay()), false, nil @@ -1327,7 +1327,7 @@ func (b *builtinWeekWithModeSig) evalInt(row chunk.Row) (int64, bool, error) { } if date.IsZero() { - return 0, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(date.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) } mode, isNull, err := b.args[1].EvalInt(b.ctx, row) @@ -1359,7 +1359,7 @@ func (b *builtinWeekWithoutModeSig) evalInt(row chunk.Row) (int64, bool, error) } if date.IsZero() { - return 0, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(date.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) } mode := 0 @@ -1410,7 +1410,7 @@ func (b *builtinWeekDaySig) evalInt(row chunk.Row) (int64, bool, error) { } if date.IsZero() { - return 0, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(date.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) } return int64(date.Time.Weekday()+6) % 7, false, nil @@ -1451,7 +1451,7 @@ func (b *builtinWeekOfYearSig) evalInt(row chunk.Row) (int64, bool, error) { } if date.IsZero() { - return 0, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(date.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) } week := date.Time.Week(3) @@ -1494,7 +1494,7 @@ func (b *builtinYearSig) evalInt(row chunk.Row) (int64, bool, error) { if date.IsZero() { if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() { - return 0, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(date.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) } return 0, false, nil } @@ -1547,7 +1547,7 @@ func (b *builtinYearWeekWithModeSig) evalInt(row chunk.Row) (int64, bool, error) return 0, isNull, handleInvalidTimeError(b.ctx, err) } if date.IsZero() { - return 0, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(date.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) } mode, isNull, err := b.args[1].EvalInt(b.ctx, row) @@ -1585,7 +1585,7 @@ func (b *builtinYearWeekWithoutModeSig) evalInt(row chunk.Row) (int64, bool, err } if date.InvalidZero() { - return 0, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(date.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) } year, week := date.Time.YearWeek(0) @@ -1869,10 +1869,10 @@ func (b *builtinStrToDateDateSig) evalTime(row chunk.Row) (types.Time, bool, err sc := b.ctx.GetSessionVars().StmtCtx succ := t.StrToDate(sc, date, format) if !succ { - return types.Time{}, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(t.String())) + return types.Time{}, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())) } if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() && (t.Time.Year() == 0 || t.Time.Month() == 0 || t.Time.Day() == 0) { - return types.Time{}, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(t.String())) + return types.Time{}, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())) } t.Type, t.Fsp = mysql.TypeDate, types.MinFsp return t, false, nil @@ -1901,10 +1901,10 @@ func (b *builtinStrToDateDatetimeSig) evalTime(row chunk.Row) (types.Time, bool, sc := b.ctx.GetSessionVars().StmtCtx succ := t.StrToDate(sc, date, format) if !succ { - return types.Time{}, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(t.String())) + return types.Time{}, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())) } if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() && (t.Time.Year() == 0 || t.Time.Month() == 0 || t.Time.Day() == 0) { - return types.Time{}, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(t.String())) + return types.Time{}, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())) } t.Type, t.Fsp = mysql.TypeDatetime, int8(b.tp.Decimal) return t, false, nil @@ -1936,10 +1936,10 @@ func (b *builtinStrToDateDurationSig) evalDuration(row chunk.Row) (types.Duratio sc := b.ctx.GetSessionVars().StmtCtx succ := t.StrToDate(sc, date, format) if !succ { - return types.Duration{}, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(t.String())) + return types.Duration{}, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())) } if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() && (t.Time.Year() == 0 || t.Time.Month() == 0 || t.Time.Day() == 0) { - return types.Duration{}, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(t.String())) + return types.Duration{}, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())) } t.Fsp = int8(b.tp.Decimal) dur, err := t.ConvertToDuration() @@ -2224,7 +2224,7 @@ func (c *timeLiteralFunctionClass) getFunction(ctx sessionctx.Context, args []Ex } str := dt.GetString() if !isDuration(str) { - return nil, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(str) + return nil, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, str) } duration, err := types.ParseDuration(ctx.GetSessionVars().StmtCtx, str, types.GetFsp(str)) if err != nil { @@ -4230,10 +4230,10 @@ func (b *builtinTimestampDiffSig) evalInt(row chunk.Row) (int64, bool, error) { } if invalidLHS, invalidRHS := lhs.InvalidZero(), rhs.InvalidZero(); invalidLHS || invalidRHS { if invalidLHS { - err = handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(lhs.String())) + err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, lhs.String())) } if invalidRHS { - err = handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(rhs.String())) + err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, rhs.String())) } return 0, true, err } @@ -4378,7 +4378,7 @@ func (b *builtinUnixTimestampIntSig) Clone() builtinFunc { // See https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_unix-timestamp func (b *builtinUnixTimestampIntSig) evalInt(row chunk.Row) (int64, bool, error) { val, isNull, err := b.args[0].EvalTime(b.ctx, row) - if err != nil && terror.ErrorEqual(types.ErrInvalidTimeFormat.GenWithStackByArgs(val), err) { + if err != nil && terror.ErrorEqual(types.ErrWrongValue.GenWithStackByArgs(types.TimeStr, val), err) { // Return 0 for invalid date time. return 0, false, nil } @@ -4580,7 +4580,7 @@ func (c *timestampLiteralFunctionClass) getFunction(ctx sessionctx.Context, args return nil, err } if !timestampPattern.MatchString(str) { - return nil, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(str) + return nil, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, str) } tm, err := types.ParseTime(ctx.GetSessionVars().StmtCtx, str, mysql.TypeTimestamp, types.GetFsp(str)) if err != nil { @@ -5326,7 +5326,7 @@ func (b *builtinMakeDateSig) evalTime(row chunk.Row) (d types.Time, isNull bool, } retTimestamp := types.TimestampDiff("DAY", types.ZeroDate, startTime) if retTimestamp == 0 { - return d, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(startTime.String())) + return d, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, startTime.String())) } ret := types.TimeFromDays(retTimestamp + dayOfYear - 1) if ret.IsZero() || ret.Time.Year() > 9999 { @@ -5628,7 +5628,7 @@ func (b *builtinQuarterSig) evalInt(row chunk.Row) (int64, bool, error) { if isOriginalIntOrDecimalZero && !isOriginalStringZero { return 0, false, nil } - return 0, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(date.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())) } return int64((date.Time.Month() + 2) / 3), false, nil @@ -6295,7 +6295,7 @@ func (b *builtinTimestampAddSig) evalString(row chunk.Row) (string, bool, error) case "YEAR": tb = tm1.AddDate(int(v), 0, 0) default: - return "", true, types.ErrInvalidTimeFormat.GenWithStackByArgs(unit) + return "", true, types.ErrWrongValue.GenWithStackByArgs(types.TimeStr, unit) } r := types.Time{Time: types.FromGoTime(tb), Type: b.resolveType(arg.Type, unit), Fsp: fsp} if err = r.Check(b.ctx.GetSessionVars().StmtCtx); err != nil { @@ -6355,7 +6355,7 @@ func (b *builtinToDaysSig) evalInt(row chunk.Row) (int64, bool, error) { } ret := types.TimestampDiff("DAY", types.ZeroDate, arg) if ret == 0 { - return 0, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(arg.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())) } return ret, false, nil } @@ -6393,7 +6393,7 @@ func (b *builtinToSecondsSig) evalInt(row chunk.Row) (int64, bool, error) { } ret := types.TimestampDiff("SECOND", types.ZeroDate, arg) if ret == 0 { - return 0, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(arg.String())) + return 0, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())) } return ret, false, nil } @@ -6534,7 +6534,7 @@ func (b *builtinLastDaySig) evalTime(row chunk.Row) (types.Time, bool, error) { tm := arg.Time year, month := tm.Year(), tm.Month() if arg.InvalidZero() { - return types.Time{}, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(arg.String())) + return types.Time{}, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())) } lastDay := types.GetLastDay(year, month) ret := types.Time{ diff --git a/expression/builtin_time_vec.go b/expression/builtin_time_vec.go index 9e1776fdd3dcd..94ef46ad3db87 100644 --- a/expression/builtin_time_vec.go +++ b/expression/builtin_time_vec.go @@ -49,7 +49,7 @@ func (b *builtinMonthSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) e } if ds[i].IsZero() { if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() { - if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(ds[i].String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { return err } result.SetNull(i, true) @@ -88,7 +88,7 @@ func (b *builtinYearSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) er } if ds[i].IsZero() { if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() { - if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(ds[i].String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { return err } result.SetNull(i, true) @@ -116,7 +116,7 @@ func (b *builtinDateSig) vecEvalTime(input *chunk.Chunk, result *chunk.Column) e continue } if times[i].IsZero() { - if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(times[i].String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, times[i].String())); err != nil { return err } result.SetNull(i, true) @@ -281,7 +281,7 @@ func (b *builtinDayNameSig) vecEvalIndex(input *chunk.Chunk, apply func(i, res i continue } if ds[i].InvalidZero() { - if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(ds[i].String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { return err } applyNull(i) @@ -366,7 +366,7 @@ func (b *builtinWeekDaySig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) continue } if ds[i].IsZero() { - if err = handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(ds[i].String())); err != nil { + if err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { return err } result.SetNull(i, true) @@ -529,7 +529,7 @@ func (b *builtinYearWeekWithoutModeSig) vecEvalInt(input *chunk.Chunk, result *c } date := ds[i] if date.InvalidZero() { - if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(date.String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())); err != nil { return err } result.SetNull(i, true) @@ -765,7 +765,7 @@ func (b *builtinLastDaySig) vecEvalTime(input *chunk.Chunk, result *chunk.Column continue } if times[i].InvalidZero() { - if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(times[i].String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, times[i].String())); err != nil { return err } result.SetNull(i, true) @@ -842,14 +842,14 @@ func (b *builtinStrToDateDateSig) vecEvalTime(input *chunk.Chunk, result *chunk. var t types.Time succ := t.StrToDate(sc, bufStrings.GetString(i), bufFormats.GetString(i)) if !succ { - if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(t.String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())); err != nil { return err } result.SetNull(i, true) continue } if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() && (t.Time.Year() == 0 || t.Time.Month() == 0 || t.Time.Day() == 0) { - if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(t.String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())); err != nil { return err } result.SetNull(i, true) @@ -1076,7 +1076,7 @@ func (b *builtinQuarterSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) } date := ds[i] if date.IsZero() { - if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(date.String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())); err != nil { return err } result.SetNull(i, true) @@ -1122,7 +1122,7 @@ func (b *builtinWeekWithModeSig) vecEvalInt(input *chunk.Chunk, result *chunk.Co } date := ds[i] if date.IsZero() { - if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(date.String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())); err != nil { return err } result.SetNull(i, true) @@ -1191,7 +1191,7 @@ func (b *builtinToSecondsSig) vecEvalInt(input *chunk.Chunk, result *chunk.Colum arg := ds[i] ret := types.TimestampDiff("SECOND", types.ZeroDate, arg) if ret == 0 { - if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(arg.String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())); err != nil { return err } result.SetNull(i, true) @@ -1361,7 +1361,7 @@ func (b *builtinMakeDateSig) vecEvalTime(input *chunk.Chunk, result *chunk.Colum } retTimestamp := types.TimestampDiff("DAY", types.ZeroDate, startTime) if retTimestamp == 0 { - if err = handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(startTime.String())); err != nil { + if err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, startTime.String())); err != nil { return err } result.SetNull(i, true) @@ -1402,7 +1402,7 @@ func (b *builtinWeekOfYearSig) vecEvalInt(input *chunk.Chunk, result *chunk.Colu continue } if ds[i].IsZero() { - if err = handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(ds[i].String())); err != nil { + if err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { return err } result.SetNull(i, true) @@ -1549,14 +1549,14 @@ func (b *builtinStrToDateDatetimeSig) vecEvalTime(input *chunk.Chunk, result *ch var t types.Time succ := t.StrToDate(sc, dateBuf.GetString(i), formatBuf.GetString(i)) if !succ { - if err = handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(t.String())); err != nil { + if err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())); err != nil { return err } result.SetNull(i, true) continue } if hasNoZeroDateMode && (t.Time.Year() == 0 || t.Time.Month() == 0 || t.Time.Day() == 0) { - if err = handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(t.String())); err != nil { + if err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())); err != nil { return err } result.SetNull(i, true) @@ -1626,7 +1626,7 @@ func (b *builtinWeekWithoutModeSig) vecEvalInt(input *chunk.Chunk, result *chunk } date := ds[i] if date.IsZero() { - if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(date.String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())); err != nil { return err } result.SetNull(i, true) @@ -1760,7 +1760,7 @@ func (b *builtinTimestampAddSig) vecEvalString(input *chunk.Chunk, result *chunk case "YEAR": tb = tm1.AddDate(int(v), 0, 0) default: - return types.ErrInvalidTimeFormat.GenWithStackByArgs(unit) + return types.ErrWrongValue.GenWithStackByArgs(types.TimeStr, unit) } r := types.Time{Time: types.FromGoTime(tb), Type: b.resolveType(arg.Type, unit), Fsp: fsp} if err = r.Check(b.ctx.GetSessionVars().StmtCtx); err != nil { @@ -1803,7 +1803,7 @@ func (b *builtinToDaysSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) arg := ds[i] ret := types.TimestampDiff("DAY", types.ZeroDate, arg) if ret == 0 { - if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(arg.String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, arg.String())); err != nil { return err } result.SetNull(i, true) @@ -2048,10 +2048,10 @@ func (b *builtinDateDiffSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column } if invalidArg0, invalidArg1 := args0[i].InvalidZero(), args1[i].InvalidZero(); invalidArg0 || invalidArg1 { if invalidArg0 { - err = handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(args0[i].String())) + err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, args0[i].String())) } if invalidArg1 { - err = handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(args1[i].String())) + err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, args1[i].String())) } if err != nil { return err @@ -2155,7 +2155,7 @@ func (b *builtinDayOfYearSig) vecEvalInt(input *chunk.Chunk, result *chunk.Colum continue } if ds[i].InvalidZero() { - if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(ds[i].String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { return err } result.SetNull(i, true) @@ -2244,7 +2244,7 @@ func (b *builtinYearWeekWithModeSig) vecEvalInt(input *chunk.Chunk, result *chun } date := ds[i] if date.IsZero() { - if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(date.String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, date.String())); err != nil { return err } result.SetNull(i, true) @@ -2307,10 +2307,10 @@ func (b *builtinTimestampDiffSig) vecEvalInt(input *chunk.Chunk, result *chunk.C } if invalidLHS, invalidRHS := lhs[i].InvalidZero(), rhs[i].InvalidZero(); invalidLHS || invalidRHS { if invalidLHS { - err = handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(lhs[i].String())) + err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, lhs[i].String())) } if invalidRHS { - err = handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(rhs[i].String())) + err = handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, rhs[i].String())) } if err != nil { return err @@ -2411,10 +2411,10 @@ func (b *builtinDateLiteralSig) vecEvalTime(input *chunk.Chunk, result *chunk.Co n := input.NumRows() mode := b.ctx.GetSessionVars().SQLMode if mode.HasNoZeroDateMode() && b.literal.IsZero() { - return types.ErrIncorrectDatetimeValue.GenWithStackByArgs(b.literal.String()) + return types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, b.literal.String()) } if mode.HasNoZeroInDateMode() && (b.literal.InvalidZero() && !b.literal.IsZero()) { - return types.ErrIncorrectDatetimeValue.GenWithStackByArgs(b.literal.String()) + return types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, b.literal.String()) } result.ResizeTime(n, false) @@ -2474,7 +2474,7 @@ func (b *builtinMonthNameSig) vecEvalString(input *chunk.Chunk, result *chunk.Co } mon := ds[i].Time.Month() if (ds[i].IsZero() && b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode()) || mon < 0 || mon > len(types.MonthNames) { - if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(ds[i].String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { return err } result.AppendNull() @@ -2539,7 +2539,7 @@ func (b *builtinDayOfWeekSig) vecEvalInt(input *chunk.Chunk, result *chunk.Colum continue } if ds[i].InvalidZero() { - if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(ds[i].String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { return err } result.SetNull(i, true) @@ -2751,7 +2751,7 @@ func (b *builtinDayOfMonthSig) vecEvalInt(input *chunk.Chunk, result *chunk.Colu } if ds[i].IsZero() { if b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() { - if err := handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(ds[i].String())); err != nil { + if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, ds[i].String())); err != nil { return err } result.SetNull(i, true) diff --git a/expression/errors.go b/expression/errors.go index 6976b307f5f07..10a719d54230a 100644 --- a/expression/errors.go +++ b/expression/errors.go @@ -72,8 +72,8 @@ func init() { // handleInvalidTimeError reports error or warning depend on the context. func handleInvalidTimeError(ctx sessionctx.Context, err error) error { - if err == nil || !(terror.ErrorEqual(err, types.ErrInvalidTimeFormat) || types.ErrIncorrectDatetimeValue.Equal(err) || - types.ErrTruncatedWrongValue.Equal(err) || types.ErrInvalidWeekModeFormat.Equal(err) || + if err == nil || !(types.ErrWrongValue.Equal(err) || + types.ErrTruncatedWrongVal.Equal(err) || types.ErrInvalidWeekModeFormat.Equal(err) || types.ErrDatetimeFunctionOverflow.Equal(err)) { return err } diff --git a/expression/integration_test.go b/expression/integration_test.go index 78c2dc33f5223..6d3f4f16385d8 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -158,7 +158,7 @@ func (s *testIntegrationSuite) TestMiscellaneousBuiltin(c *C) { tk.MustQuery("select sleep(1);").Check(testkit.Rows("0")) tk.MustQuery("select sleep(0);").Check(testkit.Rows("0")) tk.MustQuery("select sleep('a');").Check(testkit.Rows("0")) - tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1265 Data Truncated")) + tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1292 Truncated incorrect FLOAT value: 'a'")) rs, err := tk.Exec("select sleep(-1);") c.Assert(err, IsNil) c.Assert(rs, NotNil) @@ -1190,22 +1190,22 @@ func (s *testIntegrationSuite2) TestTimeBuiltin(c *C) { tk.MustExec(`create table t(a bigint)`) _, err := tk.Exec(`insert into t select year("aa")`) c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrInvalidTimeFormat), IsTrue, Commentf("err %v", err)) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue), IsTrue, Commentf("err %v", err)) tk.MustExec(`set sql_mode='STRICT_TRANS_TABLES'`) // without zero date tk.MustExec(`insert into t select year("0000-00-00 00:00:00")`) tk.MustExec(`set sql_mode="NO_ZERO_DATE";`) // with zero date tk.MustExec(`insert into t select year("0000-00-00 00:00:00")`) - tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Incorrect datetime value: '0000-00-00 00:00:00.000000'")) + tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1525|Incorrect datetime value: '0000-00-00 00:00:00.000000'")) tk.MustExec(`set sql_mode="NO_ZERO_DATE,STRICT_TRANS_TABLES";`) _, err = tk.Exec(`insert into t select year("0000-00-00 00:00:00");`) c.Assert(err, NotNil) - c.Assert(types.ErrIncorrectDatetimeValue.Equal(err), IsTrue, Commentf("err %v", err)) + c.Assert(types.ErrWrongValue.Equal(err), IsTrue, Commentf("err %v", err)) tk.MustExec(`insert into t select 1`) tk.MustExec(`set sql_mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION";`) _, err = tk.Exec(`update t set a = year("aa")`) - c.Assert(terror.ErrorEqual(err, types.ErrInvalidTimeFormat), IsTrue, Commentf("err %v", err)) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue), IsTrue, Commentf("err %v", err)) _, err = tk.Exec(`delete from t where a = year("aa")`) - c.Assert(terror.ErrorEqual(err, types.ErrInvalidTimeFormat), IsTrue, Commentf("err %v", err)) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue), IsTrue, Commentf("err %v", err)) // for month result = tk.MustQuery(`select month("2013-01-09"), month("2013-00-09"), month("000-01-09"), month("1-01-09"), month("20131-01-09"), month(null);`) @@ -1220,22 +1220,22 @@ func (s *testIntegrationSuite2) TestTimeBuiltin(c *C) { tk.MustExec(`create table t(a bigint)`) _, err = tk.Exec(`insert into t select month("aa")`) c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrInvalidTimeFormat), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue), IsTrue, Commentf("err: %v", err)) tk.MustExec(`insert into t select month("0000-00-00 00:00:00")`) tk.MustExec(`set sql_mode="NO_ZERO_DATE";`) tk.MustExec(`insert into t select month("0000-00-00 00:00:00")`) - tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Incorrect datetime value: '0000-00-00 00:00:00.000000'")) + tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1525|Incorrect datetime value: '0000-00-00 00:00:00.000000'")) tk.MustExec(`set sql_mode="NO_ZERO_DATE,STRICT_TRANS_TABLES";`) _, err = tk.Exec(`insert into t select month("0000-00-00 00:00:00");`) c.Assert(err, NotNil) - c.Assert(types.ErrIncorrectDatetimeValue.Equal(err), IsTrue, Commentf("err %v", err)) + c.Assert(types.ErrWrongValue.Equal(err), IsTrue, Commentf("err %v", err)) tk.MustExec(`insert into t select 1`) tk.MustExec(`set sql_mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION";`) tk.MustExec(`insert into t select 1`) _, err = tk.Exec(`update t set a = month("aa")`) - c.Assert(terror.ErrorEqual(err, types.ErrInvalidTimeFormat), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue), IsTrue) _, err = tk.Exec(`delete from t where a = month("aa")`) - c.Assert(terror.ErrorEqual(err, types.ErrInvalidTimeFormat), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue), IsTrue) // for week result = tk.MustQuery(`select week("2012-12-22"), week("2012-12-22", -2), week("2012-12-22", 0), week("2012-12-22", 1), week("2012-12-22", 2), week("2012-12-22", 200);`) @@ -1252,12 +1252,12 @@ func (s *testIntegrationSuite2) TestTimeBuiltin(c *C) { tk.MustExec(`create table t(a datetime)`) _, err = tk.Exec(`insert into t select week("aa", 1)`) c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrInvalidTimeFormat), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue), IsTrue) tk.MustExec(`insert into t select now()`) _, err = tk.Exec(`update t set a = week("aa", 1)`) - c.Assert(terror.ErrorEqual(err, types.ErrInvalidTimeFormat), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue), IsTrue) _, err = tk.Exec(`delete from t where a = week("aa", 1)`) - c.Assert(terror.ErrorEqual(err, types.ErrInvalidTimeFormat), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue), IsTrue) // for weekofyear result = tk.MustQuery(`select weekofyear("2012-12-22"), weekofyear("2008-02-20"), weekofyear("aa"), weekofyear(null), weekofyear(11), weekofyear(12.99);`) @@ -1266,12 +1266,12 @@ func (s *testIntegrationSuite2) TestTimeBuiltin(c *C) { tk.MustExec(`create table t(a bigint)`) _, err = tk.Exec(`insert into t select weekofyear("aa")`) c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrInvalidTimeFormat), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue), IsTrue) tk.MustExec(`insert into t select 1`) _, err = tk.Exec(`update t set a = weekofyear("aa")`) - c.Assert(terror.ErrorEqual(err, types.ErrInvalidTimeFormat), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue), IsTrue) _, err = tk.Exec(`delete from t where a = weekofyear("aa")`) - c.Assert(terror.ErrorEqual(err, types.ErrInvalidTimeFormat), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue), IsTrue) // for weekday result = tk.MustQuery(`select weekday("2012-12-20"), weekday("2012-12-21"), weekday("2012-12-22"), weekday("2012-12-23"), weekday("2012-12-24"), weekday("2012-12-25"), weekday("2012-12-26"), weekday("2012-12-27");`) @@ -1287,8 +1287,8 @@ func (s *testIntegrationSuite2) TestTimeBuiltin(c *C) { result = tk.MustQuery(`select quarter("0000-00-00"), quarter("0000-00-00 00:00:00");`) result.Check(testkit.Rows(" ")) tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", - "Warning|1292|Incorrect datetime value: '0000-00-00 00:00:00.000000'", - "Warning|1292|Incorrect datetime value: '0000-00-00 00:00:00.000000'")) + "Warning|1525|Incorrect datetime value: '0000-00-00 00:00:00.000000'", + "Warning|1525|Incorrect datetime value: '0000-00-00 00:00:00.000000'")) result = tk.MustQuery(`select quarter(0), quarter(0.0), quarter(0e1), quarter(0.00);`) result.Check(testkit.Rows("0 0 0 0")) tk.MustQuery("show warnings").Check(testkit.Rows()) @@ -1643,12 +1643,12 @@ func (s *testIntegrationSuite2) TestTimeBuiltin(c *C) { result = tk.MustQuery(`SELECT DATE_FORMAT('0000-00-00', '%W %M %e %Y %r %y');`) result.Check(testkit.Rows("")) tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", - "Warning|1292|Incorrect datetime value: '0000-00-00 00:00:00.000000'")) + "Warning|1525|Incorrect datetime value: '0000-00-00 00:00:00.000000'")) result = tk.MustQuery(`SELECT DATE_FORMAT('0', '%W %M %e %Y %r %y'), DATE_FORMAT('0.0', '%W %M %e %Y %r %y'), DATE_FORMAT(0, 0);`) result.Check(testkit.Rows(" 0")) tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", - "Warning|1292|invalid time format: '0'", - "Warning|1292|invalid time format: '0.0'")) + "Warning|1525|Incorrect time value: '0'", + "Warning|1525|Incorrect time value: '0.0'")) result = tk.MustQuery(`SELECT DATE_FORMAT(0, '%W %M %e %Y %r %y'), DATE_FORMAT(0.0, '%W %M %e %Y %r %y');`) result.Check(testkit.Rows(" ")) tk.MustQuery("show warnings").Check(testkit.Rows()) @@ -1683,33 +1683,33 @@ func (s *testIntegrationSuite2) TestTimeBuiltin(c *C) { tk.MustExec("set sql_mode = 'STRICT_TRANS_TABLES'") _, err = tk.Exec("insert into t value(dayOfWeek('0000-00-00'))") - c.Assert(types.ErrIncorrectDatetimeValue.Equal(err), IsTrue) + c.Assert(types.ErrWrongValue.Equal(err), IsTrue) _, err = tk.Exec(`update t set a = dayOfWeek("0000-00-00")`) - c.Assert(types.ErrIncorrectDatetimeValue.Equal(err), IsTrue) + c.Assert(types.ErrWrongValue.Equal(err), IsTrue) _, err = tk.Exec(`delete from t where a = dayOfWeek(123)`) c.Assert(err, IsNil) _, err = tk.Exec("insert into t value(dayOfMonth('2017-00-00'))") - c.Assert(types.ErrIncorrectDatetimeValue.Equal(err), IsTrue) + c.Assert(types.ErrWrongValue.Equal(err), IsTrue) tk.MustExec("insert into t value(dayOfMonth('0000-00-00'))") tk.MustExec(`update t set a = dayOfMonth("0000-00-00")`) tk.MustExec("set sql_mode = 'NO_ZERO_DATE';") tk.MustExec("insert into t value(dayOfMonth('0000-00-00'))") - tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Incorrect datetime value: '0000-00-00 00:00:00.000000'")) + tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1525|Incorrect datetime value: '0000-00-00 00:00:00.000000'")) tk.MustExec(`update t set a = dayOfMonth("0000-00-00")`) tk.MustExec("set sql_mode = 'NO_ZERO_DATE,STRICT_TRANS_TABLES';") _, err = tk.Exec("insert into t value(dayOfMonth('0000-00-00'))") - c.Assert(types.ErrIncorrectDatetimeValue.Equal(err), IsTrue) + c.Assert(types.ErrWrongValue.Equal(err), IsTrue) tk.MustExec("insert into t value(0)") _, err = tk.Exec(`update t set a = dayOfMonth("0000-00-00")`) - c.Assert(types.ErrIncorrectDatetimeValue.Equal(err), IsTrue) + c.Assert(types.ErrWrongValue.Equal(err), IsTrue) _, err = tk.Exec(`delete from t where a = dayOfMonth(123)`) c.Assert(err, IsNil) _, err = tk.Exec("insert into t value(dayOfYear('0000-00-00'))") - c.Assert(types.ErrIncorrectDatetimeValue.Equal(err), IsTrue) + c.Assert(types.ErrWrongValue.Equal(err), IsTrue) _, err = tk.Exec(`update t set a = dayOfYear("0000-00-00")`) - c.Assert(types.ErrIncorrectDatetimeValue.Equal(err), IsTrue) + c.Assert(types.ErrWrongValue.Equal(err), IsTrue) _, err = tk.Exec(`delete from t where a = dayOfYear(123)`) c.Assert(err, IsNil) @@ -1784,18 +1784,18 @@ func (s *testIntegrationSuite2) TestTimeBuiltin(c *C) { tk.MustExec(`update t set a = monthname("0000-00-00")`) tk.MustExec("set sql_mode = 'NO_ZERO_DATE'") tk.MustExec("insert into t value(monthname('0000-00-00'))") - tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Incorrect datetime value: '0000-00-00 00:00:00.000000'")) + tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1525|Incorrect datetime value: '0000-00-00 00:00:00.000000'")) tk.MustExec(`update t set a = monthname("0000-00-00")`) tk.MustExec("set sql_mode = ''") tk.MustExec("insert into t value(monthname('0000-00-00'))") tk.MustExec("set sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_DATE'") _, err = tk.Exec(`update t set a = monthname("0000-00-00")`) - c.Assert(types.ErrIncorrectDatetimeValue.Equal(err), IsTrue) + c.Assert(types.ErrWrongValue.Equal(err), IsTrue) _, err = tk.Exec(`delete from t where a = monthname(123)`) c.Assert(err, IsNil) result = tk.MustQuery(`select monthname("2017-12-01"), monthname("0000-00-00"), monthname("0000-01-00"), monthname("0000-01-00 00:00:00")`) result.Check(testkit.Rows("December January January")) - tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Incorrect datetime value: '0000-00-00 00:00:00.000000'")) + tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1525|Incorrect datetime value: '0000-00-00 00:00:00.000000'")) // for dayname tk.MustExec(`drop table if exists t`) @@ -1804,17 +1804,17 @@ func (s *testIntegrationSuite2) TestTimeBuiltin(c *C) { tk.MustExec("set sql_mode = 'STRICT_TRANS_TABLES'") _, err = tk.Exec("insert into t value(dayname('0000-00-00'))") - c.Assert(types.ErrIncorrectDatetimeValue.Equal(err), IsTrue) + c.Assert(types.ErrWrongValue.Equal(err), IsTrue) _, err = tk.Exec(`update t set a = dayname("0000-00-00")`) - c.Assert(types.ErrIncorrectDatetimeValue.Equal(err), IsTrue) + c.Assert(types.ErrWrongValue.Equal(err), IsTrue) _, err = tk.Exec(`delete from t where a = dayname(123)`) c.Assert(err, IsNil) result = tk.MustQuery(`select dayname("2017-12-01"), dayname("0000-00-00"), dayname("0000-01-00"), dayname("0000-01-00 00:00:00")`) result.Check(testkit.Rows("Friday ")) tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", - "Warning|1292|Incorrect datetime value: '0000-00-00 00:00:00.000000'", - "Warning|1292|Incorrect datetime value: '0000-01-00 00:00:00.000000'", - "Warning|1292|Incorrect datetime value: '0000-01-00 00:00:00.000000'")) + "Warning|1525|Incorrect datetime value: '0000-00-00 00:00:00.000000'", + "Warning|1525|Incorrect datetime value: '0000-01-00 00:00:00.000000'", + "Warning|1525|Incorrect datetime value: '0000-01-00 00:00:00.000000'")) // for sec_to_time result = tk.MustQuery("select sec_to_time(NULL)") @@ -1846,7 +1846,7 @@ func (s *testIntegrationSuite2) TestTimeBuiltin(c *C) { result = tk.MustQuery("select str_to_date('01-01-2017', '%d'), str_to_date('59', '%d-%Y')") // TODO: MySQL returns " ". result.Check(testkit.Rows("0000-00-01 ")) - tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Incorrect datetime value: '0000-00-00 00:00:00'")) + tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1525|Incorrect datetime value: '0000-00-00 00:00:00'")) result = tk.MustQuery("select str_to_date('2018-6-1', '%Y-%m-%d'), str_to_date('2018-6-1', '%Y-%c-%d'), str_to_date('59:20:1', '%s:%i:%k'), str_to_date('59:20:1', '%s:%i:%l')") result.Check(testkit.Rows("2018-06-01 2018-06-01 01:20:59 01:20:59")) @@ -3403,18 +3403,18 @@ func (s *testIntegrationSuite) TestCompareBuiltin(c *C) { // for greatest result = tk.MustQuery(`select greatest(1, 2, 3), greatest("a", "b", "c"), greatest(1.1, 1.2, 1.3), greatest("123a", 1, 2)`) result.Check(testkit.Rows("3 c 1.3 123")) - tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1265|Data Truncated")) + tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect FLOAT value: '123a'")) result = tk.MustQuery(`select greatest(cast("2017-01-01" as datetime), "123", "234", cast("2018-01-01" as date)), greatest(cast("2017-01-01" as date), "123", null)`) // todo: MySQL returns "2018-01-01 " result.Check(testkit.Rows("2018-01-01 00:00:00 ")) - tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|invalid time format: '123'", "Warning|1292|invalid time format: '234'", "Warning|1292|invalid time format: '123'")) + tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1525|Incorrect time value: '123'", "Warning|1525|Incorrect time value: '234'", "Warning|1525|Incorrect time value: '123'")) // for least result = tk.MustQuery(`select least(1, 2, 3), least("a", "b", "c"), least(1.1, 1.2, 1.3), least("123a", 1, 2)`) result.Check(testkit.Rows("1 a 1.1 1")) - tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1265|Data Truncated")) + tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect FLOAT value: '123a'")) result = tk.MustQuery(`select least(cast("2017-01-01" as datetime), "123", "234", cast("2018-01-01" as date)), least(cast("2017-01-01" as date), "123", null)`) result.Check(testkit.Rows("123 ")) - tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|invalid time format: '123'", "Warning|1292|invalid time format: '234'", "Warning|1292|invalid time format: '123'")) + tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1525|Incorrect time value: '123'", "Warning|1525|Incorrect time value: '234'", "Warning|1525|Incorrect time value: '123'")) tk.MustQuery(`select 1 < 17666000000000000000, 1 > 17666000000000000000, 1 = 17666000000000000000`).Check(testkit.Rows("1 0 0")) tk.MustExec("drop table if exists t") @@ -3698,7 +3698,7 @@ func (s *testIntegrationSuite) TestDateBuiltin(c *C) { c.Assert(err, IsNil) _, err = session.GetRows4Test(ctx, tk.Se, rs) c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("0000-00-00")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, "0000-00-00")), IsTrue) c.Assert(rs.Close(), IsNil) tk.MustExec("set sql_mode = ''") @@ -3709,7 +3709,7 @@ func (s *testIntegrationSuite) TestDateBuiltin(c *C) { rs, _ = tk.Exec("select date '2007-10-00';") _, err = session.GetRows4Test(ctx, tk.Se, rs) c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("2017-10-00")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, "2017-10-00")), IsTrue) c.Assert(rs.Close(), IsNil) tk.MustExec("set sql_mode = 'NO_ZERO_DATE'") @@ -3721,14 +3721,14 @@ func (s *testIntegrationSuite) TestDateBuiltin(c *C) { rs, _ = tk.Exec("select date '2007-10-00';") _, err = session.GetRows4Test(ctx, tk.Se, rs) c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("2017-10-00")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, "2017-10-00")), IsTrue) c.Assert(rs.Close(), IsNil) rs, err = tk.Exec("select date '0000-00-00';") c.Assert(err, IsNil) _, err = session.GetRows4Test(ctx, tk.Se, rs) c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("0000-00-00")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, "0000-00-00")), IsTrue) c.Assert(rs.Close(), IsNil) r = tk.MustQuery("select date'1998~01~02'") @@ -3739,23 +3739,23 @@ func (s *testIntegrationSuite) TestDateBuiltin(c *C) { _, err = tk.Exec("select date '0000-00-00 00:00:00';") c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("0000-00-00 00:00:00")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, "0000-00-00 00:00:00")), IsTrue) _, err = tk.Exec("select date '2017-99-99';") c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrInvalidTimeFormat), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue), IsTrue, Commentf("err: %v", err)) _, err = tk.Exec("select date '2017-2-31';") c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrInvalidTimeFormat), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue), IsTrue, Commentf("err: %v", err)) _, err = tk.Exec("select date '201712-31';") c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("201712-31")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, "201712-31")), IsTrue, Commentf("err: %v", err)) _, err = tk.Exec("select date 'abcdefg';") c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("abcdefg")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, "abcdefg")), IsTrue, Commentf("err: %v", err)) } func (s *testIntegrationSuite) TestJSONBuiltin(c *C) { @@ -3834,20 +3834,20 @@ func (s *testIntegrationSuite) TestTimeLiteral(c *C) { _, err := tk.Exec("select time '2017-01-01 00:00:00';") c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("2017-01-01 00:00:00")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, "2017-01-01 00:00:00")), IsTrue) _, err = tk.Exec("select time '071231235959.999999';") c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("071231235959.999999")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, "071231235959.999999")), IsTrue) _, err = tk.Exec("select time '20171231235959.999999';") c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("20171231235959.999999")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, "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'")) + "Warning|1525|Incorrect datetime value: '2008-1-34'")) } func (s *testIntegrationSuite) TestTimestampLiteral(c *C) { @@ -3868,15 +3868,15 @@ func (s *testIntegrationSuite) TestTimestampLiteral(c *C) { _, err := tk.Exec("select timestamp '00:00:00';") c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("00:00:00")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, "00:00:00")), IsTrue) _, err = tk.Exec("select timestamp '1992-01-03';") c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("1992-01-03")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, "1992-01-03")), IsTrue) _, err = tk.Exec("select timestamp '20171231235959.999999';") c.Assert(err, NotNil) - c.Assert(terror.ErrorEqual(err, types.ErrIncorrectDatetimeValue.GenWithStackByArgs("20171231235959.999999")), IsTrue) + c.Assert(terror.ErrorEqual(err, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, "20171231235959.999999")), IsTrue) } func (s *testIntegrationSuite) TestLiterals(c *C) { diff --git a/kv/error_test.go b/kv/error_test.go index 00900c0c789f2..a5a608ac4849e 100644 --- a/kv/error_test.go +++ b/kv/error_test.go @@ -37,6 +37,7 @@ func (s testErrorSuite) TestError(c *C) { ErrWriteConflictInTiDB, } for _, err := range kvErrs { - c.Assert(err.ToSQLError().Code != mysql.ErrUnknown, IsTrue) + code := err.ToSQLError().Code + c.Assert(code != mysql.ErrUnknown && code == uint16(err.Code()), IsTrue, Commentf("err: %v", err)) } } diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index 6520a8b41c2b6..8c5488784b530 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -2270,7 +2270,7 @@ func (b *PlanBuilder) convertValue(valueItem ast.ExprNode, mockTablePlan Logical } d, err = value.ConvertTo(b.ctx.GetSessionVars().StmtCtx, &col.FieldType) if err != nil { - if !types.ErrTruncated.Equal(err) { + if !types.ErrTruncated.Equal(err) && !types.ErrTruncatedWrongVal.Equal(err) { return d, err } valStr, err1 := value.ToString() diff --git a/table/column.go b/table/column.go index cb1729c95c610..fbbbac1f0f863 100644 --- a/table/column.go +++ b/table/column.go @@ -168,7 +168,15 @@ func CastValue(ctx sessionctx.Context, val types.Datum, col *model.ColumnInfo) ( sc := ctx.GetSessionVars().StmtCtx casted, err = val.ConvertTo(sc, &col.FieldType) // TODO: make sure all truncate errors are handled by ConvertTo. - err = sc.HandleTruncate(err) + if types.ErrTruncated.Equal(err) { + str, err1 := val.ToString() + if err1 != nil { + logutil.BgLogger().Warn("Datum ToString failed", zap.Stringer("Datum", val), zap.Error(err1)) + } + err = sc.HandleTruncate(types.ErrTruncatedWrongVal.GenWithStackByArgs(col.FieldType.CompactStr(), str)) + } else { + err = sc.HandleTruncate(err) + } if err != nil { return casted, err } diff --git a/types/convert.go b/types/convert.go index 596647e78a652..81245c864f152 100644 --- a/types/convert.go +++ b/types/convert.go @@ -356,7 +356,7 @@ func NumberToDuration(number int64, fsp int8) (Duration, error) { } if number/10000 > TimeMaxHour || number%100 >= 60 || (number/100)%100 >= 60 { - return ZeroDuration, errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(number)) + return ZeroDuration, errors.Trace(ErrWrongValue.GenWithStackByArgs(TimeStr, strconv.FormatInt(number, 10))) } t := Time{Time: FromDate(0, 0, 0, int(number/10000), int((number/100)%100), int(number%100), 0), Type: mysql.TypeDuration, Fsp: fsp} dur, err := t.ConvertToDuration() @@ -673,7 +673,7 @@ func getValidFloatPrefix(sc *stmtctx.StatementContext, s string) (valid string, valid = "0" } if validLen == 0 || validLen != len(s) { - err = errors.Trace(handleTruncateError(sc, ErrTruncated)) + err = errors.Trace(handleTruncateError(sc, ErrTruncatedWrongVal.GenWithStackByArgs("FLOAT", s))) } return valid, err } diff --git a/types/convert_test.go b/types/convert_test.go index f88defda557be..33023e99d191f 100644 --- a/types/convert_test.go +++ b/types/convert_test.go @@ -238,7 +238,7 @@ func (s *testTypeConvertSuite) TestConvertType(c *C) { c.Assert(err, IsNil, Commentf(errors.ErrorStack(err))) c.Assert(v.(*MyDecimal).String(), Equals, "3.1416") v, err = Convert("3.1415926", ft) - c.Assert(terror.ErrorEqual(err, ErrTruncated), IsTrue, Commentf("err %v", err)) + c.Assert(terror.ErrorEqual(err, ErrTruncatedWrongVal), IsTrue, Commentf("err %v", err)) c.Assert(v.(*MyDecimal).String(), Equals, "3.1416") v, err = Convert("99999", ft) c.Assert(terror.ErrorEqual(err, ErrOverflow), IsTrue, Commentf("err %v", err)) @@ -345,7 +345,7 @@ func (s *testTypeConvertSuite) TestConvertToString(c *C) { ft.Flen = 10 ft.Decimal = 5 v, err := Convert(3.1415926, ft) - c.Assert(terror.ErrorEqual(err, ErrTruncated), IsTrue, Commentf("err %v", err)) + c.Assert(terror.ErrorEqual(err, ErrTruncatedWrongVal), IsTrue, Commentf("err %v", err)) testToString(c, v, "3.14159") _, err = ToString(&invalidMockType{}) @@ -426,10 +426,10 @@ func (s *testTypeConvertSuite) TestStrToNum(c *C) { testStrToInt(c, "65.0", 65, false, nil) testStrToInt(c, "65.0", 65, true, nil) testStrToInt(c, "", 0, false, nil) - testStrToInt(c, "", 0, true, ErrTruncated) - testStrToInt(c, "xx", 0, true, ErrTruncated) + testStrToInt(c, "", 0, true, ErrTruncatedWrongVal) + testStrToInt(c, "xx", 0, true, ErrTruncatedWrongVal) testStrToInt(c, "xx", 0, false, nil) - testStrToInt(c, "11xx", 11, true, ErrTruncated) + testStrToInt(c, "11xx", 11, true, ErrTruncatedWrongVal) testStrToInt(c, "11xx", 11, false, nil) testStrToInt(c, "xx11", 0, false, nil) @@ -440,20 +440,20 @@ func (s *testTypeConvertSuite) TestStrToNum(c *C) { testStrToUint(c, "100", 100, true, nil) testStrToUint(c, "+100", 100, true, nil) testStrToUint(c, "65.0", 65, true, nil) - testStrToUint(c, "xx", 0, true, ErrTruncated) - testStrToUint(c, "11xx", 11, true, ErrTruncated) - testStrToUint(c, "xx11", 0, true, ErrTruncated) + testStrToUint(c, "xx", 0, true, ErrTruncatedWrongVal) + testStrToUint(c, "11xx", 11, true, ErrTruncatedWrongVal) + testStrToUint(c, "xx11", 0, true, ErrTruncatedWrongVal) // TODO: makes StrToFloat return truncated value instead of zero to make it pass. - testStrToFloat(c, "", 0, true, ErrTruncated) + testStrToFloat(c, "", 0, true, ErrTruncatedWrongVal) testStrToFloat(c, "-1", -1.0, true, nil) testStrToFloat(c, "1.11", 1.11, true, nil) testStrToFloat(c, "1.11.00", 1.11, false, nil) - testStrToFloat(c, "1.11.00", 1.11, true, ErrTruncated) + testStrToFloat(c, "1.11.00", 1.11, true, ErrTruncatedWrongVal) testStrToFloat(c, "xx", 0.0, false, nil) testStrToFloat(c, "0x00", 0.0, false, nil) testStrToFloat(c, "11.xx", 11.0, false, nil) - testStrToFloat(c, "11.xx", 11.0, true, ErrTruncated) + testStrToFloat(c, "11.xx", 11.0, true, ErrTruncatedWrongVal) testStrToFloat(c, "xx.11", 0.0, false, nil) // for issue #5111 @@ -803,7 +803,7 @@ func (s *testTypeConvertSuite) TestGetValidInt(c *C) { for _, tt := range tests2 { prefix, err := getValidIntPrefix(sc, tt.origin) if tt.warning { - c.Assert(terror.ErrorEqual(err, ErrTruncated), IsTrue) + c.Assert(terror.ErrorEqual(err, ErrTruncatedWrongVal), IsTrue) } else { c.Assert(err, IsNil) } diff --git a/types/datum.go b/types/datum.go index 2d7414f19f65d..125313ec558bc 100644 --- a/types/datum.go +++ b/types/datum.go @@ -1098,10 +1098,10 @@ func (d *Datum) convertToMysqlDuration(sc *stmtctx.StatementContext, target *Fie if timeNum > MaxDuration && timeNum < 10000000000 { // mysql return max in no strict sql mode. ret.SetValue(Duration{Duration: MaxTime, Fsp: 0}) - return ret, ErrInvalidTimeFormat.GenWithStack("Incorrect time value: '%s'", timeStr) + return ret, ErrWrongValue.GenWithStackByArgs(TimeStr, timeStr) } if timeNum < -MaxDuration { - return ret, ErrInvalidTimeFormat.GenWithStack("Incorrect time value: '%s'", timeStr) + return ret, ErrWrongValue.GenWithStackByArgs(TimeStr, timeStr) } t, err := ParseDuration(sc, timeStr, fsp) ret.SetValue(t) @@ -1195,10 +1195,10 @@ func ProduceDecWithSpecifiedTp(dec *MyDecimal, tp *FieldType, sc *stmtctx.Statem if sc.InInsertStmt || sc.InUpdateStmt || sc.InDeleteStmt { // fix https://github.com/pingcap/tidb/issues/3895 // fix https://github.com/pingcap/tidb/issues/5532 - sc.AppendWarning(ErrTruncated) + sc.AppendWarning(ErrTruncatedWrongVal.GenWithStackByArgs("DECIMAL", &old)) err = nil } else { - err = sc.HandleTruncate(ErrTruncated) + err = sc.HandleTruncate(ErrTruncatedWrongVal.GenWithStackByArgs("DECIMAL", &old)) } } } diff --git a/types/errors.go b/types/errors.go index 7e7f39ecf2f92..21e202e82cfd1 100644 --- a/types/errors.go +++ b/types/errors.go @@ -14,122 +14,96 @@ package types import ( - "github.com/pingcap/errors" "github.com/pingcap/parser/mysql" "github.com/pingcap/parser/terror" parser_types "github.com/pingcap/parser/types" ) +// const strings for ErrWrongValue +const ( + DateTimeStr = "datetime" + TimeStr = "time" +) + var ( + // ErrInvalidDefault is returned when meet a invalid default value. + ErrInvalidDefault = parser_types.ErrInvalidDefault // ErrDataTooLong is returned when converts a string value that is longer than field type length. - ErrDataTooLong = terror.ClassTypes.New(codeDataTooLong, "Data Too Long") + ErrDataTooLong = terror.ClassTypes.New(mysql.ErrDataTooLong, mysql.MySQLErrName[mysql.ErrDataTooLong]) // ErrIllegalValueForType is returned when value of type is illegal. - ErrIllegalValueForType = terror.ClassTypes.New(codeIllegalValueForType, mysql.MySQLErrName[mysql.ErrIllegalValueForType]) + ErrIllegalValueForType = terror.ClassTypes.New(mysql.ErrIllegalValueForType, mysql.MySQLErrName[mysql.ErrIllegalValueForType]) // ErrTruncated is returned when data has been truncated during conversion. - ErrTruncated = terror.ClassTypes.New(codeTruncated, "Data Truncated") - // ErrTruncatedWrongVal is returned when data has been truncated during conversion. - ErrTruncatedWrongVal = terror.ClassTypes.New(codeTruncatedWrongValue, msgTruncatedWrongVal) + ErrTruncated = terror.ClassTypes.New(mysql.WarnDataTruncated, mysql.MySQLErrName[mysql.WarnDataTruncated]) // ErrOverflow is returned when data is out of range for a field type. - ErrOverflow = terror.ClassTypes.New(codeOverflow, msgOverflow) + ErrOverflow = terror.ClassTypes.New(mysql.ErrDataOutOfRange, mysql.MySQLErrName[mysql.ErrDataOutOfRange]) // ErrDivByZero is return when do division by 0. - ErrDivByZero = terror.ClassTypes.New(codeDivByZero, "Division by 0") + ErrDivByZero = terror.ClassTypes.New(mysql.ErrDivisionByZero, mysql.MySQLErrName[mysql.ErrDivisionByZero]) // ErrTooBigDisplayWidth is return when display width out of range for column. - ErrTooBigDisplayWidth = terror.ClassTypes.New(codeTooBigDisplayWidth, mysql.MySQLErrName[mysql.ErrTooBigDisplaywidth]) + ErrTooBigDisplayWidth = terror.ClassTypes.New(mysql.ErrTooBigDisplaywidth, mysql.MySQLErrName[mysql.ErrTooBigDisplaywidth]) // ErrTooBigFieldLength is return when column length too big for column. - ErrTooBigFieldLength = terror.ClassTypes.New(codeTooBigFieldLength, "Too Big Field length") + ErrTooBigFieldLength = terror.ClassTypes.New(mysql.ErrTooBigFieldlength, mysql.MySQLErrName[mysql.ErrTooBigFieldlength]) // ErrTooBigSet is returned when too many strings for column. - ErrTooBigSet = terror.ClassTypes.New(codeTooBigSet, "Too Big Set") + ErrTooBigSet = terror.ClassTypes.New(mysql.ErrTooBigSet, mysql.MySQLErrName[mysql.ErrTooBigSet]) // ErrTooBigScale is returned when type DECIMAL/NUMERIC scale is bigger than mysql.MaxDecimalScale. - ErrTooBigScale = terror.ClassTypes.New(codeTooBigScale, mysql.MySQLErrName[mysql.ErrTooBigScale]) + ErrTooBigScale = terror.ClassTypes.New(mysql.ErrTooBigScale, mysql.MySQLErrName[mysql.ErrTooBigScale]) // ErrTooBigPrecision is returned when type DECIMAL/NUMERIC precision is bigger than mysql.MaxDecimalWidth - ErrTooBigPrecision = terror.ClassTypes.New(codeTooBigPrecision, mysql.MySQLErrName[mysql.ErrTooBigPrecision]) - // ErrWrongFieldSpec is return when incorrect column specifier for column. - ErrWrongFieldSpec = terror.ClassTypes.New(codeWrongFieldSpec, "Wrong Field Spec") + ErrTooBigPrecision = terror.ClassTypes.New(mysql.ErrTooBigPrecision, mysql.MySQLErrName[mysql.ErrTooBigPrecision]) // ErrBadNumber is return when parsing an invalid binary decimal number. - ErrBadNumber = terror.ClassTypes.New(codeBadNumber, "Bad Number") - // ErrInvalidDefault is returned when meet a invalid default value. - ErrInvalidDefault = parser_types.ErrInvalidDefault + ErrBadNumber = terror.ClassTypes.New(mysql.ErrBadNumber, mysql.MySQLErrName[mysql.ErrBadNumber]) // ErrInvalidFieldSize is returned when the precision of a column is out of range. - ErrInvalidFieldSize = terror.ClassTypes.New(codeInvalidFieldSize, mysql.MySQLErrName[mysql.ErrInvalidFieldSize]) - // ErrCastAsSignedOverflow is returned when positive out-of-range integer, and convert to it's negative complement. - ErrCastAsSignedOverflow = terror.ClassTypes.New(codeUnknown, msgCastAsSignedOverflow) - // ErrCastNegIntAsUnsigned is returned when a negative integer be casted to an unsigned int. - ErrCastNegIntAsUnsigned = terror.ClassTypes.New(codeUnknown, msgCastNegIntAsUnsigned) + ErrInvalidFieldSize = terror.ClassTypes.New(mysql.ErrInvalidFieldSize, mysql.MySQLErrName[mysql.ErrInvalidFieldSize]) // ErrMBiggerThanD is returned when precision less than the scale. - ErrMBiggerThanD = terror.ClassTypes.New(codeMBiggerThanD, mysql.MySQLErrName[mysql.ErrMBiggerThanD]) + ErrMBiggerThanD = terror.ClassTypes.New(mysql.ErrMBiggerThanD, mysql.MySQLErrName[mysql.ErrMBiggerThanD]) // ErrWarnDataOutOfRange is returned when the value in a numeric column that is outside the permissible range of the column data type. // See https://dev.mysql.com/doc/refman/5.5/en/out-of-range-and-overflow.html for details - ErrWarnDataOutOfRange = terror.ClassTypes.New(codeDataOutOfRange, mysql.MySQLErrName[mysql.ErrWarnDataOutOfRange]) + ErrWarnDataOutOfRange = terror.ClassTypes.New(mysql.ErrWarnDataOutOfRange, mysql.MySQLErrName[mysql.ErrWarnDataOutOfRange]) // ErrDuplicatedValueInType is returned when enum column has duplicated value. - ErrDuplicatedValueInType = terror.ClassTypes.New(codeDuplicatedValueInType, mysql.MySQLErrName[mysql.ErrDuplicatedValueInType]) + ErrDuplicatedValueInType = terror.ClassTypes.New(mysql.ErrDuplicatedValueInType, mysql.MySQLErrName[mysql.ErrDuplicatedValueInType]) // ErrDatetimeFunctionOverflow is returned when the calculation in datetime function cause overflow. - ErrDatetimeFunctionOverflow = terror.ClassTypes.New(codeDatetimeFunctionOverflow, mysql.MySQLErrName[mysql.ErrDatetimeFunctionOverflow]) - // ErrInvalidTimeFormat is returned when the time format is not correct. - ErrInvalidTimeFormat = terror.ClassTypes.New(mysql.ErrTruncatedWrongValue, "invalid time format: '%v'") - // ErrInvalidWeekModeFormat is returned when the week mode is wrong. - ErrInvalidWeekModeFormat = terror.ClassTypes.New(mysql.ErrTruncatedWrongValue, "invalid week mode format: '%v'") + ErrDatetimeFunctionOverflow = terror.ClassTypes.New(mysql.ErrDatetimeFunctionOverflow, mysql.MySQLErrName[mysql.ErrDatetimeFunctionOverflow]) + // ErrCastAsSignedOverflow is returned when positive out-of-range integer, and convert to it's negative complement. + ErrCastAsSignedOverflow = terror.ClassTypes.New(mysql.ErrCastAsSignedOverflow, mysql.MySQLErrName[mysql.ErrCastAsSignedOverflow]) + // ErrCastNegIntAsUnsigned is returned when a negative integer be casted to an unsigned int. + ErrCastNegIntAsUnsigned = terror.ClassTypes.New(mysql.ErrCastNegIntAsUnsigned, mysql.MySQLErrName[mysql.ErrCastNegIntAsUnsigned]) // ErrInvalidYearFormat is returned when the input is not a valid year format. - ErrInvalidYearFormat = errors.New("invalid year format") + ErrInvalidYearFormat = terror.ClassTypes.New(mysql.ErrInvalidYearFormat, mysql.MySQLErrName[mysql.ErrInvalidYearFormat]) // ErrInvalidYear is returned when the input value is not a valid year. - ErrInvalidYear = errors.New("invalid year") - // ErrIncorrectDatetimeValue is returned when the input is not valid date time value. - ErrIncorrectDatetimeValue = terror.ClassTypes.New(mysql.ErrTruncatedWrongValue, "Incorrect datetime value: '%s'") - // ErrTruncatedWrongValue is returned then - ErrTruncatedWrongValue = terror.ClassTypes.New(mysql.ErrTruncatedWrongValue, mysql.MySQLErrName[mysql.ErrTruncatedWrongValue]) -) - -const ( - codeBadNumber terror.ErrCode = 1 - - codeDataTooLong = terror.ErrCode(mysql.ErrDataTooLong) - codeIllegalValueForType = terror.ErrCode(mysql.ErrIllegalValueForType) - codeTruncated = terror.ErrCode(mysql.WarnDataTruncated) - codeOverflow = terror.ErrCode(mysql.ErrDataOutOfRange) - codeDivByZero = terror.ErrCode(mysql.ErrDivisionByZero) - codeTooBigDisplayWidth = terror.ErrCode(mysql.ErrTooBigDisplaywidth) - codeTooBigFieldLength = terror.ErrCode(mysql.ErrTooBigFieldlength) - codeTooBigSet = terror.ErrCode(mysql.ErrTooBigSet) - codeTooBigScale = terror.ErrCode(mysql.ErrTooBigScale) - codeTooBigPrecision = terror.ErrCode(mysql.ErrTooBigPrecision) - codeWrongFieldSpec = terror.ErrCode(mysql.ErrWrongFieldSpec) - codeTruncatedWrongValue = terror.ErrCode(mysql.ErrTruncatedWrongValue) - codeUnknown = terror.ErrCode(mysql.ErrUnknown) - codeInvalidDefault = terror.ErrCode(mysql.ErrInvalidDefault) - codeInvalidFieldSize = terror.ErrCode(mysql.ErrInvalidFieldSize) - codeMBiggerThanD = terror.ErrCode(mysql.ErrMBiggerThanD) - codeDataOutOfRange = terror.ErrCode(mysql.ErrWarnDataOutOfRange) - codeDuplicatedValueInType = terror.ErrCode(mysql.ErrDuplicatedValueInType) - codeDatetimeFunctionOverflow = terror.ErrCode(mysql.ErrDatetimeFunctionOverflow) -) - -var ( - msgOverflow = mysql.MySQLErrName[mysql.ErrDataOutOfRange] - msgTruncatedWrongVal = mysql.MySQLErrName[mysql.ErrTruncatedWrongValue] - msgCastAsSignedOverflow = "Cast to signed converted positive out-of-range integer to it's negative complement" - msgCastNegIntAsUnsigned = "Cast to unsigned converted negative integer to it's positive complement" + ErrInvalidYear = terror.ClassTypes.New(mysql.ErrInvalidYear, mysql.MySQLErrName[mysql.ErrInvalidYear]) + // ErrTruncatedWrongVal is returned when data has been truncated during conversion. + ErrTruncatedWrongVal = terror.ClassTypes.New(mysql.ErrTruncatedWrongValue, mysql.MySQLErrName[mysql.ErrTruncatedWrongValue]) + // ErrInvalidWeekModeFormat is returned when the week mode is wrong. + ErrInvalidWeekModeFormat = terror.ClassTypes.New(mysql.ErrInvalidWeekModeFormat, mysql.MySQLErrName[mysql.ErrInvalidWeekModeFormat]) + // ErrWrongValue is returned when the input value is in wrong format. + ErrWrongValue = terror.ClassTypes.New(mysql.ErrWrongValue, mysql.MySQLErrName[mysql.ErrWrongValue]) ) func init() { typesMySQLErrCodes := map[terror.ErrCode]uint16{ - codeDataTooLong: mysql.ErrDataTooLong, - codeIllegalValueForType: mysql.ErrIllegalValueForType, - codeTruncated: mysql.WarnDataTruncated, - codeOverflow: mysql.ErrDataOutOfRange, - codeDivByZero: mysql.ErrDivisionByZero, - codeTooBigDisplayWidth: mysql.ErrTooBigDisplaywidth, - codeTooBigFieldLength: mysql.ErrTooBigFieldlength, - codeTooBigSet: mysql.ErrTooBigSet, - codeTooBigScale: mysql.ErrTooBigScale, - codeTooBigPrecision: mysql.ErrTooBigPrecision, - codeWrongFieldSpec: mysql.ErrWrongFieldSpec, - codeTruncatedWrongValue: mysql.ErrTruncatedWrongValue, - codeUnknown: mysql.ErrUnknown, - codeInvalidDefault: mysql.ErrInvalidDefault, - codeInvalidFieldSize: mysql.ErrInvalidFieldSize, - codeMBiggerThanD: mysql.ErrMBiggerThanD, - codeDataOutOfRange: mysql.ErrWarnDataOutOfRange, - codeDuplicatedValueInType: mysql.ErrDuplicatedValueInType, - codeDatetimeFunctionOverflow: mysql.ErrDatetimeFunctionOverflow, + mysql.ErrInvalidDefault: mysql.ErrInvalidDefault, + mysql.ErrDataTooLong: mysql.ErrDataTooLong, + mysql.ErrIllegalValueForType: mysql.ErrIllegalValueForType, + mysql.WarnDataTruncated: mysql.WarnDataTruncated, + mysql.ErrDataOutOfRange: mysql.ErrDataOutOfRange, + mysql.ErrDivisionByZero: mysql.ErrDivisionByZero, + mysql.ErrTooBigDisplaywidth: mysql.ErrTooBigDisplaywidth, + mysql.ErrTooBigFieldlength: mysql.ErrTooBigFieldlength, + mysql.ErrTooBigSet: mysql.ErrTooBigSet, + mysql.ErrTooBigScale: mysql.ErrTooBigScale, + mysql.ErrTooBigPrecision: mysql.ErrTooBigPrecision, + mysql.ErrBadNumber: mysql.ErrBadNumber, + mysql.ErrInvalidFieldSize: mysql.ErrInvalidFieldSize, + mysql.ErrMBiggerThanD: mysql.ErrMBiggerThanD, + mysql.ErrWarnDataOutOfRange: mysql.ErrWarnDataOutOfRange, + mysql.ErrDuplicatedValueInType: mysql.ErrDuplicatedValueInType, + mysql.ErrDatetimeFunctionOverflow: mysql.ErrDatetimeFunctionOverflow, + mysql.ErrCastAsSignedOverflow: mysql.ErrCastAsSignedOverflow, + mysql.ErrCastNegIntAsUnsigned: mysql.ErrCastNegIntAsUnsigned, + mysql.ErrInvalidYearFormat: mysql.ErrInvalidYearFormat, + mysql.ErrInvalidYear: mysql.ErrInvalidYear, + mysql.ErrTruncatedWrongValue: mysql.ErrTruncatedWrongValue, + mysql.ErrInvalidTimeFormat: mysql.ErrInvalidTimeFormat, + mysql.ErrInvalidWeekModeFormat: mysql.ErrInvalidWeekModeFormat, + mysql.ErrWrongValue: mysql.ErrWrongValue, } terror.ErrClassToMySQLCodes[terror.ClassTypes] = typesMySQLErrCodes } diff --git a/types/errors_test.go b/types/errors_test.go new file mode 100644 index 0000000000000..6f7c92b613f3b --- /dev/null +++ b/types/errors_test.go @@ -0,0 +1,57 @@ +// Copyright 2019 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// See the License for the specific language governing permissions and +// limitations under the License. + +package types + +import ( + . "github.com/pingcap/check" + "github.com/pingcap/parser/mysql" + "github.com/pingcap/parser/terror" +) + +type testErrorSuite struct{} + +var _ = Suite(testErrorSuite{}) + +func (s testErrorSuite) TestError(c *C) { + kvErrs := []*terror.Error{ + ErrInvalidDefault, + ErrDataTooLong, + ErrIllegalValueForType, + ErrTruncated, + ErrOverflow, + ErrDivByZero, + ErrTooBigDisplayWidth, + ErrTooBigFieldLength, + ErrTooBigSet, + ErrTooBigScale, + ErrTooBigPrecision, + ErrBadNumber, + ErrInvalidFieldSize, + ErrMBiggerThanD, + ErrWarnDataOutOfRange, + ErrDuplicatedValueInType, + ErrDatetimeFunctionOverflow, + ErrCastAsSignedOverflow, + ErrCastNegIntAsUnsigned, + ErrInvalidYearFormat, + ErrInvalidYear, + ErrTruncatedWrongVal, + ErrInvalidWeekModeFormat, + ErrWrongValue, + } + for _, err := range kvErrs { + code := err.ToSQLError().Code + c.Assert(code != mysql.ErrUnknown && code == uint16(err.Code()), IsTrue, Commentf("err: %v", err)) + } +} diff --git a/types/mytime.go b/types/mytime.go index b5923eec36b0a..f7a59c1c53653 100644 --- a/types/mytime.go +++ b/types/mytime.go @@ -121,7 +121,7 @@ func (t MysqlTime) GoTime(loc *gotime.Location) (gotime.Time, error) { if year != t.Year() || int(month) != t.Month() || day != t.Day() || hour != t.Hour() || minute != t.Minute() || second != t.Second() || microsec != t.Microsecond() { - return tm, errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(t)) + return tm, errors.Trace(ErrWrongValue.GenWithStackByArgs(TimeStr, t)) } return tm, nil } diff --git a/types/time.go b/types/time.go index 3127aa32bb696..cc9a766d2376e 100644 --- a/types/time.go +++ b/types/time.go @@ -438,7 +438,7 @@ func (t Time) RoundFrac(sc *stmtctx.StatementContext, fsp int8) (Time, error) { // TODO: when hh:mm:ss overflow one day after rounding, it should be add to yy:mm:dd part, // but mm:dd may contain 0, it makes the code complex, so we ignore it here. if t2.Day()-1 > 0 { - return t, errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(t.String())) + return t, errors.Trace(ErrWrongValue.GenWithStackByArgs(TimeStr, t.String())) } nt = FromDate(t.Time.Year(), t.Time.Month(), t.Time.Day(), hour, minute, second, microsecond) } @@ -735,7 +735,7 @@ func parseDatetime(sc *stmtctx.StatementContext, str string, fsp int8, isFloat b _, err = fmt.Sscanf(seps[0], "%2d%2d%2d", &year, &month, &day) year = adjustYear(year) default: - return ZeroDatetime, errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(str)) + return ZeroDatetime, errors.Trace(ErrWrongValue.GenWithStackByArgs(TimeStr, str)) } if l == 5 || l == 6 || l == 8 { // YYMMDD or YYYYMMDD @@ -767,13 +767,13 @@ func parseDatetime(sc *stmtctx.StatementContext, str string, fsp int8, isFloat b truncatedOrIncorrect = err != nil } if truncatedOrIncorrect && sc != nil { - sc.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs("datetime", str)) + sc.AppendWarning(ErrTruncatedWrongVal.GenWithStackByArgs("datetime", str)) err = nil } case 2: // YYYY-MM is not valid if len(fracStr) == 0 { - return ZeroDatetime, errors.Trace(ErrIncorrectDatetimeValue.GenWithStackByArgs(str)) + return ZeroDatetime, errors.Trace(ErrWrongValue.GenWithStackByArgs(DateTimeStr, str)) } // YYYY-MM.DD, DD is treat as fracStr @@ -794,7 +794,7 @@ func parseDatetime(sc *stmtctx.StatementContext, str string, fsp int8, isFloat b err = scanTimeArgs(seps, &year, &month, &day, &hour, &minute, &second) hhmmss = true default: - return ZeroDatetime, errors.Trace(ErrIncorrectDatetimeValue.GenWithStackByArgs(str)) + return ZeroDatetime, errors.Trace(ErrWrongValue.GenWithStackByArgs(DateTimeStr, str)) } if err != nil { return ZeroDatetime, errors.Trace(err) @@ -841,7 +841,7 @@ func parseDatetime(sc *stmtctx.StatementContext, str string, fsp int8, isFloat b func scanTimeArgs(seps []string, args ...*int) error { if len(seps) != len(args) { - return errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(seps)) + return errors.Trace(ErrWrongValue.GenWithStackByArgs(TimeStr, seps)) } var err error @@ -1275,7 +1275,7 @@ func parseDateTimeFromNum(sc *stmtctx.StatementContext, num int64) (Time, error) // Check MMDD. if num < 101 { - return t, errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(num)) + return t, errors.Trace(ErrWrongValue.GenWithStackByArgs(TimeStr, strconv.FormatInt(num, 10))) } // Adjust year @@ -1287,7 +1287,7 @@ func parseDateTimeFromNum(sc *stmtctx.StatementContext, num int64) (Time, error) // Check YYMMDD. if num < 70*10000+101 { - return t, errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(num)) + return t, errors.Trace(ErrWrongValue.GenWithStackByArgs(TimeStr, num)) } // Adjust year @@ -1299,7 +1299,7 @@ func parseDateTimeFromNum(sc *stmtctx.StatementContext, num int64) (Time, error) // Check YYYYMMDD. if num < 10000101 { - return t, errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(num)) + return t, errors.Trace(ErrWrongValue.GenWithStackByArgs(TimeStr, num)) } // Adjust hour/min/second. @@ -1310,7 +1310,7 @@ func parseDateTimeFromNum(sc *stmtctx.StatementContext, num int64) (Time, error) // Check MMDDHHMMSS. if num < 101000000 { - return t, errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(num)) + return t, errors.Trace(ErrWrongValue.GenWithStackByArgs(TimeStr, num)) } // Set TypeDatetime type. @@ -1325,7 +1325,7 @@ func parseDateTimeFromNum(sc *stmtctx.StatementContext, num int64) (Time, error) // Check YYYYMMDDHHMMSS. if num < 70*10000000000+101000000 { - return t, errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(num)) + return t, errors.Trace(ErrWrongValue.GenWithStackByArgs(TimeStr, num)) } // Adjust year @@ -1462,7 +1462,7 @@ func checkDateType(t MysqlTime, allowZeroInDate, allowInvalidDate bool) error { } if !allowZeroInDate && (month == 0 || day == 0) { - return ErrIncorrectDatetimeValue.GenWithStackByArgs(fmt.Sprintf("%04d-%02d-%02d", year, month, day)) + return ErrWrongValue.GenWithStackByArgs(DateTimeStr, fmt.Sprintf("%04d-%02d-%02d", year, month, day)) } if err := checkDateRange(t); err != nil { @@ -1480,17 +1480,17 @@ func checkDateRange(t MysqlTime) error { // Oddly enough, MySQL document says date range should larger than '1000-01-01', // but we can insert '0001-01-01' actually. if t.Year() < 0 || t.Month() < 0 || t.Day() < 0 { - return errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(t)) + return errors.Trace(ErrWrongValue.GenWithStackByArgs(TimeStr, t)) } if compareTime(t, MaxDatetime) > 0 { - return errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(t)) + return errors.Trace(ErrWrongValue.GenWithStackByArgs(TimeStr, t)) } return nil } func checkMonthDay(year, month, day int, allowInvalidDate bool) error { if month < 0 || month > 12 { - return errors.Trace(ErrIncorrectDatetimeValue.GenWithStackByArgs(fmt.Sprintf("%d-%d-%d", year, month, day))) + return errors.Trace(ErrWrongValue.GenWithStackByArgs(DateTimeStr, fmt.Sprintf("%d-%d-%d", year, month, day))) } maxDay := 31 @@ -1504,7 +1504,7 @@ func checkMonthDay(year, month, day int, allowInvalidDate bool) error { } if day < 0 || day > maxDay { - return errors.Trace(ErrIncorrectDatetimeValue.GenWithStackByArgs(fmt.Sprintf("%d-%d-%d", year, month, day))) + return errors.Trace(ErrWrongValue.GenWithStackByArgs(DateTimeStr, fmt.Sprintf("%d-%d-%d", year, month, day))) } return nil } @@ -1530,7 +1530,7 @@ func checkTimestampType(sc *stmtctx.StatementContext, t MysqlTime) error { checkTime = t } if compareTime(checkTime, MaxTimestamp.Time) > 0 || compareTime(checkTime, MinTimestamp.Time) < 0 { - return errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(t)) + return errors.Trace(ErrWrongValue.GenWithStackByArgs(TimeStr, t)) } if _, err := t.GoTime(sc.TimeZone); err != nil { @@ -1547,13 +1547,13 @@ func checkDatetimeType(t MysqlTime, allowZeroInDate, allowInvalidDate bool) erro hour, minute, second := t.Hour(), t.Minute(), t.Second() if hour < 0 || hour >= 24 { - return errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(hour)) + return errors.Trace(ErrWrongValue.GenWithStackByArgs(TimeStr, hour)) } if minute < 0 || minute >= 60 { - return errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(minute)) + return errors.Trace(ErrWrongValue.GenWithStackByArgs(TimeStr, minute)) } if second < 0 || second >= 60 { - return errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(second)) + return errors.Trace(ErrWrongValue.GenWithStackByArgs(TimeStr, second)) } return nil @@ -1646,7 +1646,7 @@ func parseSingleTimeValue(unit string, format string, strictCheck bool) (int64, } iv, err := strconv.ParseInt(format[0:decimalPointPos], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) + return 0, 0, 0, 0, ErrWrongValue.GenWithStackByArgs(DateTimeStr, format) } riv := iv // Rounded integer value @@ -1657,18 +1657,18 @@ func parseSingleTimeValue(unit string, format string, strictCheck bool) (int64, if lf-decimalPointPos >= 6 { // MySQL rounds down to 1e-6. if dv, err = strconv.ParseInt(format[decimalPointPos+1:decimalPointPos+7], 10, 64); err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) + return 0, 0, 0, 0, ErrWrongValue.GenWithStackByArgs(DateTimeStr, format) } } else { if dv, err = strconv.ParseInt(format[decimalPointPos+1:]+"000000"[:6-(lf-decimalPointPos)], 10, 64); err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(format) + return 0, 0, 0, 0, ErrWrongValue.GenWithStackByArgs(DateTimeStr, format) } } if dv >= 500000 { // Round up, and we should keep 6 digits for microsecond, so dv should in [000000, 999999]. riv += sign } if unit != "SECOND" { - err = ErrTruncatedWrongValue.GenWithStackByArgs(format) + err = ErrTruncatedWrongVal.GenWithStackByArgs(format) } dv *= sign } @@ -1749,7 +1749,7 @@ func parseTimeValue(format string, index, cnt int) (int64, int64, int64, int64, } matches := numericRegex.FindAllString(format, -1) if len(matches) > cnt { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(originalFmt) + return 0, 0, 0, 0, ErrWrongValue.GenWithStackByArgs(DateTimeStr, originalFmt) } for i := range matches { if neg { @@ -1762,32 +1762,32 @@ func parseTimeValue(format string, index, cnt int) (int64, int64, int64, int64, years, err := strconv.ParseInt(fields[YearIndex], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(originalFmt) + return 0, 0, 0, 0, ErrWrongValue.GenWithStackByArgs(DateTimeStr, originalFmt) } months, err := strconv.ParseInt(fields[MonthIndex], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(originalFmt) + return 0, 0, 0, 0, ErrWrongValue.GenWithStackByArgs(DateTimeStr, originalFmt) } days, err := strconv.ParseInt(fields[DayIndex], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(originalFmt) + return 0, 0, 0, 0, ErrWrongValue.GenWithStackByArgs(DateTimeStr, originalFmt) } hours, err := strconv.ParseInt(fields[HourIndex], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(originalFmt) + return 0, 0, 0, 0, ErrWrongValue.GenWithStackByArgs(DateTimeStr, originalFmt) } minutes, err := strconv.ParseInt(fields[MinuteIndex], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(originalFmt) + return 0, 0, 0, 0, ErrWrongValue.GenWithStackByArgs(DateTimeStr, originalFmt) } seconds, err := strconv.ParseInt(fields[SecondIndex], 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(originalFmt) + return 0, 0, 0, 0, ErrWrongValue.GenWithStackByArgs(DateTimeStr, originalFmt) } microseconds, err := strconv.ParseInt(alignFrac(fields[MicrosecondIndex], int(MaxFsp)), 10, 64) if err != nil { - return 0, 0, 0, 0, ErrIncorrectDatetimeValue.GenWithStackByArgs(originalFmt) + return 0, 0, 0, 0, ErrWrongValue.GenWithStackByArgs(DateTimeStr, originalFmt) } seconds = hours*3600 + minutes*60 + seconds days += seconds / (3600 * 24) @@ -1999,13 +1999,13 @@ func (t Time) convertDateFormat(b rune, buf *bytes.Buffer) error { case 'b': m := t.Time.Month() if m == 0 || m > 12 { - return errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(m)) + return errors.Trace(ErrWrongValue.GenWithStackByArgs(TimeStr, m)) } buf.WriteString(MonthNames[m-1][:3]) case 'M': m := t.Time.Month() if m == 0 || m > 12 { - return errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(m)) + return errors.Trace(ErrWrongValue.GenWithStackByArgs(TimeStr, m)) } buf.WriteString(MonthNames[m-1]) case 'm': @@ -2169,10 +2169,10 @@ func mysqlTimeFix(t *MysqlTime, ctx map[string]int) error { } if valueAMorPm, ok := ctx["%p"]; ok { if _, ok := ctx["%H"]; ok { - return ErrInvalidTimeFormat.GenWithStackByArgs(t) + return ErrWrongValue.GenWithStackByArgs(TimeStr, t) } if t.hour == 0 { - return ErrInvalidTimeFormat.GenWithStackByArgs(t) + return ErrWrongValue.GenWithStackByArgs(TimeStr, t) } if t.hour == 12 { // 12 is a special hour. diff --git a/types/time_test.go b/types/time_test.go index f9e3dd20a57ff..b878afbc216ad 100644 --- a/types/time_test.go +++ b/types/time_test.go @@ -1478,8 +1478,8 @@ func (s *testTimeSuite) TestParseDurationValue(c *C) { {"-1 1", "YEAR_MONTH", -1, -1, 0, 0, nil}, {"-aa1bb1", "YEAR_MONTH", -1, -1, 0, 0, nil}, {" \t\n\r\n - aa1bb1 \t\n ", "YEAR_MONTH", -1, -1, 0, 0, nil}, - {"1.111", "MICROSECOND", 0, 0, 0, 1000, types.ErrTruncatedWrongValue}, - {"1.111", "DAY", 0, 0, 1, 0, types.ErrTruncatedWrongValue}, + {"1.111", "MICROSECOND", 0, 0, 0, 1000, types.ErrTruncatedWrongVal}, + {"1.111", "DAY", 0, 0, 1, 0, types.ErrTruncatedWrongVal}, } for _, col := range tbl { comment := Commentf("Extract %v Unit %v", col.format, col.unit) @@ -1694,7 +1694,7 @@ func (s *testTimeSuite) TestCheckMonthDay(c *C) { if t.isValidDate { c.Check(err, IsNil) } else { - c.Check(types.ErrIncorrectDatetimeValue.Equal(err), IsTrue) + c.Check(types.ErrWrongValue.Equal(err), IsTrue) } } }