From 7b0c4adcfed372d225ec8c4db4a4af0a5fa29dd5 Mon Sep 17 00:00:00 2001 From: lance6716 Date: Fri, 7 Aug 2020 20:07:00 +0800 Subject: [PATCH 1/5] syncer: fix wrong conversion for mysql BIT --- syncer/dml.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syncer/dml.go b/syncer/dml.go index d53fe021a8..61c3a12cc6 100644 --- a/syncer/dml.go +++ b/syncer/dml.go @@ -312,7 +312,7 @@ func castUnsigned(data interface{}, ft *types.FieldType) interface{} { } return uint32(v) case int64: - return strconv.FormatUint(uint64(v), 10) + return uint64(v) } return data From 29c1254eee63d49c1909de1f2ab0a1ae03b5f11d Mon Sep 17 00:00:00 2001 From: lance6716 Date: Fri, 7 Aug 2020 22:49:22 +0800 Subject: [PATCH 2/5] fix test --- syncer/dml_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/syncer/dml_test.go b/syncer/dml_test.go index 1bbaf5649c..f4d7b7ea41 100644 --- a/syncer/dml_test.go +++ b/syncer/dml_test.go @@ -15,7 +15,6 @@ package syncer import ( "math" - "strconv" . "github.com/pingcap/check" "github.com/pingcap/parser" @@ -44,8 +43,8 @@ func (s *testSyncerSuite) TestCastUnsigned(c *C) { {int32(-math.Exp2(23)), true, mysql.TypeInt24, uint32(math.Exp2(23))}, {int32(-math.Exp2(31)), false, mysql.TypeLong, int32(-math.Exp2(31))}, // INT {int32(-math.Exp2(31)), true, mysql.TypeLong, uint32(math.Exp2(31))}, - {int64(-math.Exp2(63)), false, mysql.TypeLonglong, int64(-math.Exp2(63))}, // BIGINT - {int64(-math.Exp2(63)), true, mysql.TypeLonglong, strconv.FormatUint(uint64(math.Exp2(63)), 10)}, // special case use string to represent uint64 + {int64(-math.Exp2(63)), false, mysql.TypeLonglong, int64(-math.Exp2(63))}, // BIGINT + {int64(-math.Exp2(63)), true, mysql.TypeLonglong, uint64(math.Exp2(63))}, // special case use string to represent uint64 } for _, cs := range cases { ft := types.NewFieldType(cs.Type) From 8b0b4f7fe74336474157d107ff2593bbc04c7eeb Mon Sep 17 00:00:00 2001 From: lance6716 Date: Mon, 10 Aug 2020 11:50:01 +0800 Subject: [PATCH 3/5] add test --- tests/all_mode/data/db1.increment.sql | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/all_mode/data/db1.increment.sql b/tests/all_mode/data/db1.increment.sql index e154027721..1f0a6c37af 100644 --- a/tests/all_mode/data/db1.increment.sql +++ b/tests/all_mode/data/db1.increment.sql @@ -30,4 +30,10 @@ delete from t1 where gen_id > 124; -- test decimal type alter table t1 add column lat decimal(9,6) default '0.000000'; -insert into t1 (id, name, info, lat) values (8, 'gentest', '{"id":127}', '123.123') +insert into t1 (id, name, info, lat) values (8, 'gentest', '{"id":127}', '123.123'); + +-- test bit type +alter table t1 add column bin bit(1) default NULL; +insert into t1 (id, name, info, lat, bin) values (9, 'gentest', '{"id":128}', '123.123', b'0'); +insert into t1 (id, name, info, lat, bin) values (10, 'gentest', '{"id":129}', '123.123', b'1'); + From a2d9aa44f4faee08b1c25a470eecb3b994f04a26 Mon Sep 17 00:00:00 2001 From: lance6716 Date: Tue, 11 Aug 2020 16:19:26 +0800 Subject: [PATCH 4/5] remove comment --- syncer/dml_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syncer/dml_test.go b/syncer/dml_test.go index f4d7b7ea41..fa0c187fc5 100644 --- a/syncer/dml_test.go +++ b/syncer/dml_test.go @@ -44,7 +44,7 @@ func (s *testSyncerSuite) TestCastUnsigned(c *C) { {int32(-math.Exp2(31)), false, mysql.TypeLong, int32(-math.Exp2(31))}, // INT {int32(-math.Exp2(31)), true, mysql.TypeLong, uint32(math.Exp2(31))}, {int64(-math.Exp2(63)), false, mysql.TypeLonglong, int64(-math.Exp2(63))}, // BIGINT - {int64(-math.Exp2(63)), true, mysql.TypeLonglong, uint64(math.Exp2(63))}, // special case use string to represent uint64 + {int64(-math.Exp2(63)), true, mysql.TypeLonglong, uint64(math.Exp2(63))}, } for _, cs := range cases { ft := types.NewFieldType(cs.Type) From a91860dbd92180379440be3921b7ec2b7fc82389 Mon Sep 17 00:00:00 2001 From: lance6716 Date: Tue, 11 Aug 2020 16:57:57 +0800 Subject: [PATCH 5/5] address comment --- tests/all_mode/data/db1.increment.sql | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/all_mode/data/db1.increment.sql b/tests/all_mode/data/db1.increment.sql index 1f0a6c37af..a172eb5aa9 100644 --- a/tests/all_mode/data/db1.increment.sql +++ b/tests/all_mode/data/db1.increment.sql @@ -37,3 +37,9 @@ alter table t1 add column bin bit(1) default NULL; insert into t1 (id, name, info, lat, bin) values (9, 'gentest', '{"id":128}', '123.123', b'0'); insert into t1 (id, name, info, lat, bin) values (10, 'gentest', '{"id":129}', '123.123', b'1'); +-- test bigint, min and max value for bigint/bigint unsigned +alter table t1 add column big1 bigint; +alter table t1 add column big2 bigint unsigned; +insert into t1 (id, name, info, lat, big1, big2) values (11, 'gentest', '{"id":130}', '123.123', -9223372036854775808, 0); +insert into t1 (id, name, info, lat, big1, big2) values (12, 'gentest', '{"id":131}', '123.123', 9223372036854775807, 18446744073709551615); +