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:
parent
27a442b5ec
commit
2c7c6848c0
6
mysql.go
6
mysql.go
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user