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

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: 5kbpers <tangminghua@pingcap.com>
  • Loading branch information
5kbpers committed Jan 10, 2020
1 parent 807c840 commit 477614b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/restore/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ func (db *DB) CreateTable(ctx context.Context, table *utils.Table) error {
zap.Error(err))
return errors.Trace(err)
}
alterAutoIncIDSQL := fmt.Sprintf("alter table %s auto_increment = %d", schema.Name, schema.AutoIncID)
alterAutoIncIDSQL := fmt.Sprintf(
"alter table %s auto_increment = %d",
escapeTableName(schema.Name),
schema.AutoIncID)
_, err = db.se.Execute(ctx, alterAutoIncIDSQL)
if err != nil {
log.Error("alter AutoIncID failed",
Expand Down
9 changes: 9 additions & 0 deletions pkg/restore/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,12 @@ func encodeKeyPrefix(key []byte) []byte {
encodedPrefix = append(encodedPrefix, codec.EncodeBytes([]byte{}, key[:len(key)-ungroupedLen])...)
return append(encodedPrefix[:len(encodedPrefix)-9], key[len(key)-ungroupedLen:]...)
}

// escape the identifier for pretty-printing.
// For instance, the identifier "foo `bar`" will become "`foo ``bar```".
// The sqlMode controls whether to escape with backquotes (`) or double quotes
// (`"`) depending on whether mysql.ModeANSIQuotes is enabled.
func escapeTableName(cis model.CIStr) string {
quote := `"`
return quote + strings.Replace(cis.O, quote, quote+quote, -1) + quote
}

0 comments on commit 477614b

Please sign in to comment.