Issue #553 quoting breaks mariadb/mysql

The new quoting behavior during table creation is generating
incompatible sql code for mariadb and likely mysql. Make the Quote
function a little bit smarter in mysql.go so it doesn't quote parens.
This commit is contained in:
Yan-Fa Li 2015-07-02 11:16:57 -07:00
parent 27a442b5ec
commit 2c7c6848c0

View File

@ -3,6 +3,7 @@ package gorm
import ( import (
"fmt" "fmt"
"reflect" "reflect"
"strings"
"time" "time"
) )
@ -57,6 +58,11 @@ func (mysql) SqlTag(value reflect.Value, size int, autoIncrease bool) string {
} }
func (mysql) Quote(key string) string { func (mysql) Quote(key string) string {
if strings.Contains(key, "(") {
pos1 := strings.Index(key, "(")
pos2 := strings.Index(key, ")")
return fmt.Sprintf("`%s`(`%s`)", key[0:pos1], key[pos1+1:pos2])
}
return fmt.Sprintf("`%s`", key) return fmt.Sprintf("`%s`", key)
} }