Skip to content

Commit

Permalink
fix HandleTruncate
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongjiwei committed Dec 21, 2022
1 parent 5c1bce6 commit d67d951
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions sessionctx/stmtctx/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ go_library(
importpath = "github.com/pingcap/tidb/sessionctx/stmtctx",
visibility = ["//visibility:public"],
deps = [
"//errno",
"//parser",
"//parser/ast",
"//parser/model",
Expand Down
14 changes: 10 additions & 4 deletions sessionctx/stmtctx/stmtctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"time"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/errno"
"github.com/pingcap/tidb/parser"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/parser/model"
Expand Down Expand Up @@ -868,10 +869,15 @@ func (sc *StatementContext) HandleTruncate(err error) error {

err = errors.Cause(err)
if e, ok := err.(*errors.Error); !ok ||
(e.Code() != mysql.ErrTruncatedWrongValue &&
e.Code() != mysql.ErrDataTooLong &&
e.Code() != mysql.ErrTruncatedWrongValueForField &&
e.Code() != mysql.WarnDataTruncated) {
(e.Code() != errno.ErrTruncatedWrongValue &&
e.Code() != errno.ErrDataTooLong &&
e.Code() != errno.ErrTruncatedWrongValueForField &&
e.Code() != errno.ErrWarnDataOutOfRange &&
e.Code() != errno.ErrDataOutOfRange &&
e.Code() != errno.ErrBadNumber &&
e.Code() != errno.ErrWrongValueForType &&
e.Code() != errno.ErrDatetimeFunctionOverflow &&
e.Code() != errno.WarnDataTruncated) {
return err
}

Expand Down
1 change: 1 addition & 0 deletions table/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ func CastValue(ctx sessionctx.Context, val types.Datum, col *model.ColumnInfo, r
}

err = sc.HandleTruncate(err)
err = sc.HandleOverflow(err, err)

if forceIgnoreTruncate {
err = nil
Expand Down

0 comments on commit d67d951

Please sign in to comment.