From d3fea6c53500907233428cded3336b16f9d23966 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Wed, 2 Sep 2015 11:34:14 +0800 Subject: [PATCH] Fix check HasIndex --- common_dialect.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/common_dialect.go b/common_dialect.go index 19708e50..7f08b04f 100644 --- a/common_dialect.go +++ b/common_dialect.go @@ -73,7 +73,7 @@ func (c commonDialect) HasTable(scope *Scope, tableName string) bool { count int databaseName = c.CurrentDatabase(scope) ) - c.RawScanInt(scope, &count, "SELECT count(*) FROM INFORMATION_SCHEMA.TABLES WHERE table_name = ? AND table_schema = ?", tableName, databaseName) + c.RawScanInt(scope, &count, "SELECT count(*) FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = ? AND table_name = ?", databaseName, tableName) return count > 0 } @@ -87,8 +87,11 @@ func (c commonDialect) HasColumn(scope *Scope, tableName string, columnName stri } func (c commonDialect) HasIndex(scope *Scope, tableName string, indexName string) bool { - var count int - c.RawScanInt(scope, &count, "SELECT count(*) FROM INFORMATION_SCHEMA.STATISTICS where table_name = ? AND index_name = ?", tableName, indexName) + var ( + count int + databaseName = c.CurrentDatabase(scope) + ) + c.RawScanInt(scope, &count, "SELECT count(*) FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema = ? AND table_name = ? AND index_name = ?", databaseName, tableName, indexName) return count > 0 }