mirror of https://github.com/go-gorm/gorm.git
Hide method QuoteIfPossible
This commit is contained in:
parent
317e1a9a48
commit
4f84bf0d94
|
@ -39,9 +39,9 @@ func updateTimeStampForCreateCallback(scope *Scope) {
|
||||||
|
|
||||||
// createCallback the callback used to insert data into database
|
// createCallback the callback used to insert data into database
|
||||||
func createCallback(scope *Scope) {
|
func createCallback(scope *Scope) {
|
||||||
|
if !scope.HasError() {
|
||||||
defer scope.trace(NowFunc())
|
defer scope.trace(NowFunc())
|
||||||
|
|
||||||
if !scope.HasError() {
|
|
||||||
// set create sql
|
// set create sql
|
||||||
var sqls, columns []string
|
var sqls, columns []string
|
||||||
fields := scope.Fields()
|
fields := scope.Fields()
|
||||||
|
|
2
scope.go
2
scope.go
|
@ -88,7 +88,7 @@ func (scope *Scope) Quote(str string) string {
|
||||||
return scope.Dialect().Quote(str)
|
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) {
|
if regexp.MustCompile("^[a-zA-Z]+(.[a-zA-Z]+)*$").MatchString(str) {
|
||||||
return scope.Quote(str)
|
return scope.Quote(str)
|
||||||
}
|
}
|
||||||
|
|
|
@ -663,7 +663,7 @@ func (scope *Scope) addIndex(unique bool, indexName string, column ...string) {
|
||||||
|
|
||||||
var columns []string
|
var columns []string
|
||||||
for _, name := range column {
|
for _, name := range column {
|
||||||
columns = append(columns, scope.QuoteIfPossible(name))
|
columns = append(columns, scope.quoteIfPossible(name))
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlCreate := "CREATE INDEX"
|
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)
|
var keyName = fmt.Sprintf("%s_%s_%s_foreign", scope.TableName(), field, dest)
|
||||||
keyName = regexp.MustCompile("(_*[^a-zA-Z]+_*|_+)").ReplaceAllString(keyName, "_")
|
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;`
|
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) {
|
func (scope *Scope) removeIndex(indexName string) {
|
||||||
|
|
Loading…
Reference in New Issue