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 the bug about the wrong query result for decimal type #22507

Merged
merged 21 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3868,6 +3868,17 @@ func (s *testSerialSuite) TestIssue20840(c *C) {
tk.MustExec("drop table t1")
}

func (s *testSerialSuite) TestIssue22496(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t12")
tk.MustExec("set sql_mode=''")
jyz0309 marked this conversation as resolved.
Show resolved Hide resolved
tk.MustExec("create table t12(d decimal(15,2));")
tk.MustExec("insert into t12 values('1,999.00');")
tk.MustQuery("SELECT * FROM t12;").Check(testkit.Rows("0.00"))
jyz0309 marked this conversation as resolved.
Show resolved Hide resolved
tk.MustExec("drop table t12")
}

func (s *testSuite) TestEqualDatumsAsBinary(c *C) {
tests := []struct {
a []interface{}
Expand Down
6 changes: 6 additions & 0 deletions types/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ func (s *testTypeConvertSuite) TestConvertType(c *C) {
v, err = Convert("-10000", ft)
c.Assert(terror.ErrorEqual(err, ErrOverflow), IsTrue, Commentf("err %v", err))
c.Assert(v.(*MyDecimal).String(), Equals, "-9999.9999")
v, err = Convert("1,999.00", ft)
c.Assert(terror.ErrorEqual(err, ErrBadNumber), IsTrue, Commentf("err %v", err))
c.Assert(v.(*MyDecimal).String(), Equals, "0.0000")
v, err = Convert("1,999,999.00", ft)
c.Assert(terror.ErrorEqual(err, ErrBadNumber), IsTrue, Commentf("err %v", err))
c.Assert(v.(*MyDecimal).String(), Equals, "0.0000")
jyz0309 marked this conversation as resolved.
Show resolved Hide resolved

// Test Datum.ToDecimal with bad number.
d := NewDatum("hello")
Expand Down
3 changes: 3 additions & 0 deletions types/mydecimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ func (d *MyDecimal) FromString(str []byte) error {
endIdx++
}
digitsFrac = endIdx - strIdx - 1
} else if strIdx < len(str) && (str[strIdx] != 'e' && str[strIdx] != 'E') {
*d = zeroMyDecimal
return ErrBadNumber
} else {
digitsFrac = 0
endIdx = strIdx
Expand Down