From d261d881c4f8f695c227b32820d831e4cb081fc0 Mon Sep 17 00:00:00 2001 From: fanrenhoo Date: Sun, 17 Apr 2022 20:48:28 +0800 Subject: [PATCH 1/2] fix bad error message for numeric conversion issue#32744 Signed-off-by: fanrenhoo --- ddl/column_type_change_test.go | 2 +- types/mydecimal.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ddl/column_type_change_test.go b/ddl/column_type_change_test.go index 4d29f0ad18b8b..8e2ca668743f7 100644 --- a/ddl/column_type_change_test.go +++ b/ddl/column_type_change_test.go @@ -1302,7 +1302,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\" ")) diff --git a/types/mydecimal.go b/types/mydecimal.go index c1e09808c6d20..7c4874792dc32 100644 --- a/types/mydecimal.go +++ b/types/mydecimal.go @@ -402,7 +402,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 '-': @@ -430,7 +430,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) From b8e20f7740f2b85650e0b2a5e2587a145deeac41 Mon Sep 17 00:00:00 2001 From: fanrenhoo Date: Sun, 17 Apr 2022 21:54:22 +0800 Subject: [PATCH 2/2] fix bad error message for numeric conversion issue#32744 Signed-off-by: fanrenhoo --- ddl/column_type_change_test.go | 2 +- types/convert_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ddl/column_type_change_test.go b/ddl/column_type_change_test.go index 8e2ca668743f7..40dfd475a72ae 100644 --- a/ddl/column_type_change_test.go +++ b/ddl/column_type_change_test.go @@ -665,7 +665,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) { diff --git a/types/convert_test.go b/types/convert_test.go index 6a4f91a5d30ff..d0c7f6dc8b783 100644 --- a/types/convert_test.go +++ b/types/convert_test.go @@ -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)