Skip to content

Commit

Permalink
reparo: add `` for column (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
WangXiangUSTC authored Feb 22, 2019
1 parent 1a2a892 commit 8cf485a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
12 changes: 11 additions & 1 deletion reparo/translator/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,17 @@ func (p *mysqlTranslator) TransDDL(binlog *pb.Binlog) (string, []interface{}, er
}

func (p *mysqlTranslator) genColumnList(columns []string) string {
return strings.Join(columns, ",")
var columnList strings.Builder
for i, column := range columns {
name := fmt.Sprintf("`%s`", column)
columnList.WriteString(name)

if i != len(columns)-1 {
columnList.WriteString(",")
}
}

return columnList.String()
}

func genWhere(columns []string, args []interface{}) (string, []interface{}) {
Expand Down
20 changes: 10 additions & 10 deletions tests/reparo/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ cd "$(dirname "$0")"

run_drainer &

run_sql "DROP DATABASE IF EXISTS reparo_test;"
run_sql "CREATE DATABASE reparo_test"
run_sql "CREATE TABLE reparo_test.test(id int, name varchar(10), PRIMARY KEY(id))"
run_sql "DROP DATABASE IF EXISTS \`reparo_test\`;"
run_sql "CREATE DATABASE \`reparo_test\`"
run_sql "CREATE TABLE \`reparo_test\`.\`test\`(\`id\` int, \`name\` varchar(10), \`all\` varchar(10), PRIMARY KEY(\`id\`))"

run_sql "INSERT INTO reparo_test.test VALUES(1, 'a'), (2, 'b')"
run_sql "INSERT INTO reparo_test.test VALUES(3, 'c'), (4, 'd')"
run_sql "UPDATE reparo_test.test SET name = 'bb' where id = 2"
run_sql "DELETE FROM reparo_test.test WHERE name = 'bb'"
run_sql "INSERT INTO reparo_test.test VALUES(5, 'e')"
run_sql "INSERT INTO \`reparo_test\`.\`test\` VALUES(1, 'a', 'a'), (2, 'b', 'b')"
run_sql "INSERT INTO \`reparo_test\`.\`test\` VALUES(3, 'c', 'c'), (4, 'd', 'c')"
run_sql "UPDATE \`reparo_test\`.\`test\` SET \`name\` = 'bb' where \`id\` = 2"
run_sql "DELETE FROM \`reparo_test\`.\`test\` WHERE \`name\` = 'bb'"
run_sql "INSERT INTO \`reparo_test\`.\`test\` VALUES(5, 'e', 'e')"

sleep 5

run_reparo &

sleep 5

down_run_sql "SELECT count(*) FROM reparo_test.test"
down_run_sql "SELECT count(*) FROM \`reparo_test\`.\`test\`"
check_contains "count(*): 4"

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

killall drainer

0 comments on commit 8cf485a

Please sign in to comment.