Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Commit

Permalink
syncer: fix wrong conversion for mysql BIT (#876) (#886)
Browse files Browse the repository at this point in the history
  • Loading branch information
lance6716 authored Aug 13, 2020
1 parent cd0ea4b commit e1c31e8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion syncer/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func castUnsigned(data interface{}, unsigned bool, tp string) interface{} {
}
return uint32(v)
case int64:
return strconv.FormatUint(uint64(v), 10)
return uint64(v)
}

return data
Expand Down
5 changes: 2 additions & 3 deletions syncer/dml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package syncer

import (
"math"
"strconv"

. "github.com/pingcap/check"
)
Expand All @@ -36,8 +35,8 @@ func (s *testSyncerSuite) TestCastUnsigned(c *C) {
{int32(-math.Exp2(23)), true, "mediumint(8) unsigned", uint32(math.Exp2(23))},
{int32(-math.Exp2(31)), false, "int(11)", int32(-math.Exp2(31))}, // INT
{int32(-math.Exp2(31)), true, "int(10) unsigned", uint32(math.Exp2(31))},
{int64(-math.Exp2(63)), false, "bigint(20)", int64(-math.Exp2(63))}, // BIGINT
{int64(-math.Exp2(63)), true, "bigint(20) unsigned", strconv.FormatUint(uint64(math.Exp2(63)), 10)}, // special case use string to represent uint64
{int64(-math.Exp2(63)), false, "bigint(20)", int64(-math.Exp2(63))}, // BIGINT
{int64(-math.Exp2(63)), true, "bigint(20) unsigned", uint64(math.Exp2(63))},
}
for _, cs := range cases {
obtained := castUnsigned(cs.data, cs.unsigned, cs.Type)
Expand Down
14 changes: 13 additions & 1 deletion tests/all_mode/data/db1.increment.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,16 @@ alter database all_mode CHARACTER SET = utf8mb4;

-- 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');

-- 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);

0 comments on commit e1c31e8

Please sign in to comment.