From 4f84bf0d94988d4b9f0b4f26386d825d5268703b Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Sun, 17 Jan 2016 16:37:17 +0800 Subject: [PATCH] Hide method QuoteIfPossible --- callback_create.go | 4 ++-- scope.go | 2 +- scope_private.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/callback_create.go b/callback_create.go index 11082f8a..7e04d67d 100644 --- a/callback_create.go +++ b/callback_create.go @@ -39,9 +39,9 @@ func updateTimeStampForCreateCallback(scope *Scope) { // createCallback the callback used to insert data into database func createCallback(scope *Scope) { - defer scope.trace(NowFunc()) - if !scope.HasError() { + defer scope.trace(NowFunc()) + // set create sql var sqls, columns []string fields := scope.Fields() diff --git a/scope.go b/scope.go index b2a2852b..0abfa132 100644 --- a/scope.go +++ b/scope.go @@ -88,7 +88,7 @@ func (scope *Scope) Quote(str string) string { return scope.Dialect().Quote(str) } -func (scope *Scope) QuoteIfPossible(str string) string { +func (scope *Scope) quoteIfPossible(str string) string { if regexp.MustCompile("^[a-zA-Z]+(.[a-zA-Z]+)*$").MatchString(str) { return scope.Quote(str) } diff --git a/scope_private.go b/scope_private.go index 769d4c64..e0a98c1c 100644 --- a/scope_private.go +++ b/scope_private.go @@ -663,7 +663,7 @@ func (scope *Scope) addIndex(unique bool, indexName string, column ...string) { var columns []string for _, name := range column { - columns = append(columns, scope.QuoteIfPossible(name)) + columns = append(columns, scope.quoteIfPossible(name)) } sqlCreate := "CREATE INDEX" @@ -678,7 +678,7 @@ func (scope *Scope) addForeignKey(field string, dest string, onDelete string, on var keyName = fmt.Sprintf("%s_%s_%s_foreign", scope.TableName(), field, dest) keyName = regexp.MustCompile("(_*[^a-zA-Z]+_*|_+)").ReplaceAllString(keyName, "_") 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(), scope.QuoteIfPossible(keyName), scope.QuoteIfPossible(field), dest, onDelete, onUpdate)).Exec() + scope.Raw(fmt.Sprintf(query, scope.QuotedTableName(), scope.quoteIfPossible(keyName), scope.quoteIfPossible(field), dest, onDelete, onUpdate)).Exec() } func (scope *Scope) removeIndex(indexName string) {