Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

backend/tidb: fix handling of empty binary literals #357

Merged
merged 3 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions lightning/backend/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ func (enc tidbEncoder) appendSQL(sb *strings.Builder, datum *types.Datum) error

case types.KindBinaryLiteral:
value := datum.GetBinaryLiteral()
sb.Grow(2 + 2*len(value))
sb.WriteString("0x")
sb.Grow(3 + 2*len(value))
sb.WriteString("x'")
hex.NewEncoder(sb).Write(value)
sb.WriteByte('\'')

case types.KindMysqlBit:
var buffer [20]byte
Expand Down
2 changes: 1 addition & 1 deletion lightning/backend/tidb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (s *mysqlSuite) TearDownTest(c *C) {

func (s *mysqlSuite) TestWriteRowsReplaceOnDup(c *C) {
s.mockDB.
ExpectExec("\\QREPLACE INTO `foo`.`bar`(`a`,`b`,`c`,`d`,`e`,`f`,`g`,`h`,`i`,`j`,`k`,`l`,`m`,`n`,`o`) VALUES(18446744073709551615,-9223372036854775808,0,NULL,7.5,5e-324,1.7976931348623157e+308,0,'甲乙丙\\r\\n\\0\\Z''\"\\\\`',0x000000abcdef,2557891634,'12.5',51)\\E").
ExpectExec("\\QREPLACE INTO `foo`.`bar`(`a`,`b`,`c`,`d`,`e`,`f`,`g`,`h`,`i`,`j`,`k`,`l`,`m`,`n`,`o`) VALUES(18446744073709551615,-9223372036854775808,0,NULL,7.5,5e-324,1.7976931348623157e+308,0,'甲乙丙\\r\\n\\0\\Z''\"\\\\`',x'000000abcdef',2557891634,'12.5',51)\\E").
WillReturnResult(sqlmock.NewResult(1, 1))

ctx := context.Background()
Expand Down
3 changes: 2 additions & 1 deletion tests/various_types/data/vt.binary.sql
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ INSERT INTO `binary` VALUES
(46, x'747B4c36678948a8921763afbee2dd15'),
(47, x'a5e015d13d76447eaf8fb834007481e9'),
(48, x'b75264a7e7074df187a2b9052ad4e36d'),
(49, x'45cD65089a064ab781406a84a109faef');
(49, x'45cD65089a064ab781406a84a109faef'),
(50, x'');
4 changes: 2 additions & 2 deletions tests/various_types/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ for BACKEND in importer tidb local; do
check_contains 'ref: 41'

run_sql 'SELECT count(pk), hex(min(pk)), hex(max(pk)) FROM vt.binary'
check_contains 'count(pk): 50'
check_contains 'hex(min(pk)): 090ABBB2F22E4F97A4FEA52EB1A80A0B'
check_contains 'count(pk): 51'
check_contains 'hex(min(pk)): '
check_contains 'hex(max(pk)): FDE1328C409C43A8B1B08C35C8000F92'
run_sql "SELECT ref FROM vt.binary WHERE pk = x'55dc0343db6a420898729096305b8c07'"
check_contains 'ref: 41'
Expand Down