From 2c7c6848c0e5a3cbd66ba07ffcd39460bf810e4e Mon Sep 17 00:00:00 2001 From: Yan-Fa Li Date: Thu, 2 Jul 2015 11:16:57 -0700 Subject: [PATCH] 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. --- mysql.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mysql.go b/mysql.go index a5e4a459..cfb1b839 100644 --- a/mysql.go +++ b/mysql.go @@ -3,6 +3,7 @@ package gorm import ( "fmt" "reflect" + "strings" "time" ) @@ -57,6 +58,11 @@ func (mysql) SqlTag(value reflect.Value, size int, autoIncrease bool) 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) }