Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types: fix bad error message for numeric conversion issue#32744 #34047

Merged
merged 7 commits into from
Jun 23, 2022
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