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

fix error in ConvertJSONToInt error msg (#11493) #11562

Merged
merged 3 commits into from
Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 8 additions & 1 deletion expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2049,6 +2049,13 @@ func (s *testIntegrationSuite) TestBuiltin(c *C) {
tk.MustExec(`insert into tb5 (a, b) select * from (select cast(a as json) as a1, b from tb5) as t where t.a1 = t.b;`)
tk.MustExec(`drop table tb5;`)

tk.MustExec(`create table tb5(a float(64));`)
tk.MustExec(`insert into tb5(a) values (13835058055282163712);`)
err := tk.QueryToErr(`select convert(t.a1, signed int) from (select convert(a, json) as a1 from tb5) as t`)
msg := strings.Split(err.Error(), " ")
last := msg[len(msg)-1]
c.Assert(last, Equals, "bigint")

// Test corner cases of cast string as datetime
result = tk.MustQuery(`select cast("170102034" as datetime);`)
result.Check(testkit.Rows("2017-01-02 03:04:00"))
Expand Down Expand Up @@ -2207,7 +2214,7 @@ func (s *testIntegrationSuite) TestBuiltin(c *C) {
result.Check(testkit.Rows("99999.99"))
result = tk.MustQuery("select cast(s1 as decimal(8, 2)) from t1;")
result.Check(testkit.Rows("111111.00"))
_, err := tk.Exec("insert into t1 values(cast('111111.00' as decimal(7, 2)));")
_, err = tk.Exec("insert into t1 values(cast('111111.00' as decimal(7, 2)));")
c.Assert(err, NotNil)

result = tk.MustQuery(`select CAST(0x8fffffffffffffff as signed) a,
Expand Down
4 changes: 2 additions & 2 deletions types/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,10 @@ func ConvertJSONToInt(sc *stmtctx.StatementContext, j json.BinaryJSON, unsigned
if !unsigned {
lBound := SignedLowerBound[mysql.TypeLonglong]
uBound := SignedUpperBound[mysql.TypeLonglong]
return ConvertFloatToInt(f, lBound, uBound, mysql.TypeDouble)
return ConvertFloatToInt(f, lBound, uBound, mysql.TypeLonglong)
}
bound := UnsignedUpperBound[mysql.TypeLonglong]
u, err := ConvertFloatToUint(sc, f, bound, mysql.TypeDouble)
u, err := ConvertFloatToUint(sc, f, bound, mysql.TypeLonglong)
return int64(u), errors.Trace(err)
case json.TypeCodeString:
return StrToInt(sc, hack.String(j.GetString()))
Expand Down