Skip to content

Commit

Permalink
types: fix bad error message for numeric conversion issue#32744 (#34047)
Browse files Browse the repository at this point in the history
close #32744
  • Loading branch information
fanrenhoo authored Jun 23, 2022
1 parent 2bd4c4a commit b5ed38d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ddl/column_type_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ func TestColumnTypeChangeFromStringToOthers(t *testing.T) {

// MySQL will get "ERROR 1366 (HY000): Incorrect DECIMAL value: '0' for column '' at row -1" error.
tk.MustExec("insert into t(vc) values ('abc')")
tk.MustGetErrCode("alter table t modify vc decimal(5,3)", errno.ErrBadNumber)
tk.MustGetErrCode("alter table t modify vc decimal(5,3)", errno.ErrTruncatedWrongValue)
}

func TestColumnTypeChangeFromNumericToOthers(t *testing.T) {
Expand Down Expand Up @@ -1298,7 +1298,7 @@ func TestColumnTypeChangeFromJsonToOthers(t *testing.T) {
tk.MustExec("alter table t modify ui decimal(20, 10)")
tk.MustExec("alter table t modify f64 decimal(20, 10)")
// MySQL will get "ERROR 1366 (HY000): Incorrect DECIMAL value: '0' for column '' at row -1".
tk.MustGetErrCode("alter table t modify str decimal(20, 10)", errno.ErrBadNumber)
tk.MustGetErrCode("alter table t modify str decimal(20, 10)", errno.ErrTruncatedWrongValue)
tk.MustExec("alter table t modify nul decimal(20, 10)")
tk.MustQuery("select * from t").Check(testkit.Rows("{\"obj\": 100} [-1, 0, 1] null 1.0000000000 0.0000000000 -22.0000000000 22.0000000000 323232323.3232323500 \"json string\" <nil>"))

Expand Down
2 changes: 1 addition & 1 deletion types/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func TestConvertType(t *testing.T) {
// Test Datum.ToDecimal with bad number.
d := NewDatum("hello")
_, err = d.ToDecimal(sc)
require.Truef(t, terror.ErrorEqual(err, ErrBadNumber), "err %v", err)
require.Truef(t, terror.ErrorEqual(err, ErrTruncatedWrongVal), "err %v", err)

sc.IgnoreTruncate = true
v, err = d.ToDecimal(sc)
Expand Down
4 changes: 2 additions & 2 deletions types/mydecimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func (d *MyDecimal) FromString(str []byte) error {
}
if len(str) == 0 {
*d = zeroMyDecimal
return ErrBadNumber
return ErrTruncatedWrongVal.GenWithStackByArgs("DECIMAL", str)
}
switch str[0] {
case '-':
Expand Down Expand Up @@ -431,7 +431,7 @@ func (d *MyDecimal) FromString(str []byte) error {
}
if digitsInt+digitsFrac == 0 {
*d = zeroMyDecimal
return ErrBadNumber
return ErrTruncatedWrongVal.GenWithStackByArgs("DECIMAL", str)
}
wordsInt := digitsToWords(digitsInt)
wordsFrac := digitsToWords(digitsFrac)
Expand Down

0 comments on commit b5ed38d

Please sign in to comment.