From 0bd69f4ad974aa238b11b62f438f2ce65ea91a48 Mon Sep 17 00:00:00 2001 From: H-ZeX Date: Mon, 29 Jul 2019 13:05:35 +0800 Subject: [PATCH 1/2] fix error in ConvertJSONToInt error msg Signed-off-by: H-ZeX --- types/convert.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/convert.go b/types/convert.go index 4c427c5522a4f..079a2b0e152ba 100644 --- a/types/convert.go +++ b/types/convert.go @@ -560,10 +560,10 @@ func ConvertJSONToInt(sc *stmtctx.StatementContext, j json.BinaryJSON, unsigned if !unsigned { lBound := IntergerSignedLowerBound(mysql.TypeLonglong) uBound := IntergerSignedUpperBound(mysql.TypeLonglong) - return ConvertFloatToInt(f, lBound, uBound, mysql.TypeDouble) + return ConvertFloatToInt(f, lBound, uBound, mysql.TypeLonglong) } bound := IntergerUnsignedUpperBound(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: str := string(hack.String(j.GetString())) From 0b054feea2c63d369e037005c1ea206dc7899af4 Mon Sep 17 00:00:00 2001 From: H-ZeX Date: Tue, 30 Jul 2019 18:50:30 +0800 Subject: [PATCH 2/2] add integration test Signed-off-by: H-ZeX --- expression/integration_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index ed4e73872fc2d..187ec13315963 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -2186,6 +2186,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")) @@ -2372,7 +2379,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,