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 not quote db name in file data ddl #961

Merged
merged 3 commits into from
May 12, 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
11 changes: 10 additions & 1 deletion drainer/translator/pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package translator
import (
"fmt"
"io"
"strings"
"time"

"github.com/golang/protobuf/proto"
Expand Down Expand Up @@ -48,7 +49,7 @@ func TiBinlogToPbBinlog(infoGetter TableInfoGetter, schema string, table string,
if isCreateDatabase {
sql += ";"
} else {
sql = fmt.Sprintf("use %s; %s;", schema, sql)
sql = fmt.Sprintf("use %s; %s;", quoteName(schema), sql)
}

pbBinlog.Tp = pb.BinlogType_DDL
Expand Down Expand Up @@ -303,3 +304,11 @@ func packEvent(schemaName, tableName string, tp pb.EventType, rowData [][]byte)

return event
}

func escapeName(name string) string {
return strings.Replace(name, "`", "``", -1)
}

func quoteName(name string) string {
return "`" + escapeName(name) + "`"
}
2 changes: 1 addition & 1 deletion drainer/translator/pb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (t *testPbSuite) TestDDL(c *check.C) {
c.Assert(err, check.IsNil)

c.Log("get ddl: ", string(pbBinog.GetDdlQuery()))
expected := fmt.Sprintf("use %s; %s;", t.Schema, string(t.TiBinlog.GetDdlQuery()))
expected := fmt.Sprintf("use `%s`; %s;", t.Schema, string(t.TiBinlog.GetDdlQuery()))
c.Assert(pbBinog, check.DeepEquals, &pb.Binlog{
Tp: pb.BinlogType_DDL,
CommitTs: t.TiBinlog.GetCommitTs(),
Expand Down
2 changes: 1 addition & 1 deletion tests/reparo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ batch = 10
host = "127.0.0.1"
user = "root"
password = ""
name = "reparo_test"
name = "reparo-test"
port = 4000
6 changes: 4 additions & 2 deletions tests/reparo/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ run_drainer "$args" &

GO111MODULE=on go build -o out

run_sql "CREATE DATABASE IF NOT EXISTS \`reparo_test\`"
sleep 5

run_sql "CREATE DATABASE IF NOT EXISTS \`reparo-test\`"

./out -config ./config.toml > ${OUT_DIR-/tmp}/$TEST_NAME.out 2>&1

Expand All @@ -27,6 +29,6 @@ sleep 15
check_data ./sync_diff_inspector.toml

# clean up
run_sql "DROP DATABASE IF EXISTS \`reparo_test\`"
run_sql "DROP DATABASE IF EXISTS \`reparo-test\`"

killall drainer
2 changes: 1 addition & 1 deletion tests/reparo/sync_diff_inspector.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tidb-instance-id = "source-1"
use-checksum=true

[[check-tables]]
schema = "reparo_test"
schema = "reparo-test"
tables = ["~.*"]

[target-db]
Expand Down