From 9b895b6388d473fb82e42b067100ac92c0c0b26b Mon Sep 17 00:00:00 2001 From: kennytm Date: Fri, 26 Apr 2019 16:40:29 +0800 Subject: [PATCH] tests,restore: re-enable the exotic_filenames test (#172) --- lightning/restore/tidb.go | 13 +++++++++---- ...7\345\272\253\360\237\245\263-schema-create.sql" | 1 + ...\344\270\255\346\226\207\350\241\250-schema.sql" | 1 + ...45\263.\344\270\255\346\226\207\350\241\250.sql" | 1 + tests/exotic_filenames/run.sh | 6 ++++-- 5 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 "tests/exotic_filenames/data/\344\270\255\346\226\207\345\272\253\360\237\245\263-schema-create.sql" create mode 100644 "tests/exotic_filenames/data/\344\270\255\346\226\207\345\272\253\360\237\245\263.\344\270\255\346\226\207\350\241\250-schema.sql" create mode 100644 "tests/exotic_filenames/data/\344\270\255\346\226\207\345\272\253\360\237\245\263.\344\270\255\346\226\207\350\241\250.sql" diff --git a/lightning/restore/tidb.go b/lightning/restore/tidb.go index 3443f77d4..5a67248d6 100644 --- a/lightning/restore/tidb.go +++ b/lightning/restore/tidb.go @@ -20,6 +20,7 @@ import ( "net/http" "net/url" "regexp" + "strings" "github.com/pingcap/errors" "github.com/pingcap/parser/model" @@ -79,13 +80,17 @@ func (timgr *TiDBManager) InitSchema(ctx context.Context, database string, table Logger: log.With(zap.String("db", database)), } - createDatabase := fmt.Sprintf("CREATE DATABASE IF NOT EXISTS `%s`", database) - err := sql.Exec(ctx, "create database", createDatabase) + var createDatabase strings.Builder + createDatabase.WriteString("CREATE DATABASE IF NOT EXISTS ") + common.WriteMySQLIdentifier(&createDatabase, database) + err := sql.Exec(ctx, "create database", createDatabase.String()) if err != nil { return errors.Trace(err) } - useDB := fmt.Sprintf("USE `%s`", database) - err = sql.Exec(ctx, "use database", useDB) + var useDB strings.Builder + useDB.WriteString("USE ") + common.WriteMySQLIdentifier(&useDB, database) + err = sql.Exec(ctx, "use database", useDB.String()) if err != nil { return errors.Trace(err) } diff --git "a/tests/exotic_filenames/data/\344\270\255\346\226\207\345\272\253\360\237\245\263-schema-create.sql" "b/tests/exotic_filenames/data/\344\270\255\346\226\207\345\272\253\360\237\245\263-schema-create.sql" new file mode 100644 index 000000000..d18c9b3ff --- /dev/null +++ "b/tests/exotic_filenames/data/\344\270\255\346\226\207\345\272\253\360\237\245\263-schema-create.sql" @@ -0,0 +1 @@ +create database `中文庫🥳`; diff --git "a/tests/exotic_filenames/data/\344\270\255\346\226\207\345\272\253\360\237\245\263.\344\270\255\346\226\207\350\241\250-schema.sql" "b/tests/exotic_filenames/data/\344\270\255\346\226\207\345\272\253\360\237\245\263.\344\270\255\346\226\207\350\241\250-schema.sql" new file mode 100644 index 000000000..449584777 --- /dev/null +++ "b/tests/exotic_filenames/data/\344\270\255\346\226\207\345\272\253\360\237\245\263.\344\270\255\346\226\207\350\241\250-schema.sql" @@ -0,0 +1 @@ +create table 中文表(a int primary key); diff --git "a/tests/exotic_filenames/data/\344\270\255\346\226\207\345\272\253\360\237\245\263.\344\270\255\346\226\207\350\241\250.sql" "b/tests/exotic_filenames/data/\344\270\255\346\226\207\345\272\253\360\237\245\263.\344\270\255\346\226\207\350\241\250.sql" new file mode 100644 index 000000000..af77ea8c2 --- /dev/null +++ "b/tests/exotic_filenames/data/\344\270\255\346\226\207\345\272\253\360\237\245\263.\344\270\255\346\226\207\350\241\250.sql" @@ -0,0 +1 @@ +insert into 中文表 values (2345); diff --git a/tests/exotic_filenames/run.sh b/tests/exotic_filenames/run.sh index ba4d1b16b..cd58c36d5 100755 --- a/tests/exotic_filenames/run.sh +++ b/tests/exotic_filenames/run.sh @@ -16,11 +16,10 @@ # Confirm the behavior for some exotic filenames # Do not enable until https://github.com/pingcap/tidb/pull/8302 is merged. -exit 0 - set -eu run_sql 'DROP DATABASE IF EXISTS `x``f"n`;' +run_sql 'DROP DATABASE IF EXISTS `中文庫🥳`;' run_lightning echo 'Import finished' @@ -33,3 +32,6 @@ check_contains 'b > 80000: 1' run_sql 'SELECT _tidb_rowid > 80000, b > 80000 FROM `x``f"n`.`exotic``table````name` WHERE a = "gggggg"' check_contains '_tidb_rowid > 80000: 1' check_contains 'b > 80000: 1' + +run_sql 'SELECT * FROM `中文庫🥳`.中文表' +check_contains 'a: 2345'