From e31752757a46b92728d63112714fa52b813a7546 Mon Sep 17 00:00:00 2001 From: Jay Taylor Date: Mon, 29 Jun 2015 15:35:50 -0700 Subject: [PATCH] Added missing field name quoting for `ALTER TABLE' and `CREATE INDEX' statements. --- scope_private.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scope_private.go b/scope_private.go index 5faebe2e..85f07e99 100644 --- a/scope_private.go +++ b/scope_private.go @@ -530,7 +530,7 @@ func (scope *Scope) addForeignKey(field string, dest string, onDelete string, on var table = scope.TableName() var keyName = fmt.Sprintf("%s_%s_foreign", table, field) var query = `ALTER TABLE %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s ON DELETE %s ON UPDATE %s;` - scope.Raw(fmt.Sprintf(query, scope.QuotedTableName(), keyName, field, dest, onDelete, onUpdate)).Exec() + scope.Raw(fmt.Sprintf(query, scope.QuotedTableName(), scope.Quote(keyName), scope.Quote(field), scope.Quote(dest), onDelete, onUpdate)).Exec() } func (scope *Scope) removeIndex(indexName string) { @@ -548,7 +548,7 @@ func (scope *Scope) autoMigrate() *Scope { if !scope.Dialect().HasColumn(scope, tableName, field.DBName) { if field.IsNormal { sqlTag := scope.generateSqlTag(field) - scope.Raw(fmt.Sprintf("ALTER TABLE %v ADD %v %v;", quotedTableName, field.DBName, sqlTag)).Exec() + scope.Raw(fmt.Sprintf("ALTER TABLE %v ADD %v %v;", quotedTableName, scope.Quote(field.DBName), sqlTag)).Exec() } } scope.createJoinTable(field)