fix(HasTable): database name (#2717)

* fix(HasTable): database name
allow mysql database name with '-' character

* docs: add comment
This commit is contained in:
FWangZil 2019-10-21 20:45:38 +08:00 committed by Jinzhu
parent 5fe32d593f
commit 795328fedc
1 changed files with 1 additions and 0 deletions

View File

@ -165,6 +165,7 @@ func (s mysql) HasForeignKey(tableName string, foreignKeyName string) bool {
func (s mysql) HasTable(tableName string) bool { func (s mysql) HasTable(tableName string) bool {
currentDatabase, tableName := currentDatabaseAndTable(&s, tableName) currentDatabase, tableName := currentDatabaseAndTable(&s, tableName)
var name string var name string
// allow mysql database name with '-' character
if err := s.db.QueryRow(fmt.Sprintf("SHOW TABLES FROM `%s` WHERE `Tables_in_%s` = ?", currentDatabase, currentDatabase), tableName).Scan(&name); err != nil { if err := s.db.QueryRow(fmt.Sprintf("SHOW TABLES FROM `%s` WHERE `Tables_in_%s` = ?", currentDatabase, currentDatabase), tableName).Scan(&name); err != nil {
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
return false return false