From bc1a38d2ddaf75796f2a7d522289387fb5d2db4f Mon Sep 17 00:00:00 2001 From: Fred Wu Date: Thu, 21 Jan 2016 15:30:43 +0800 Subject: [PATCH] =?UTF-8?q?fix=20a=20bug:=20when=20use=20xorm=20reverse=20?= =?UTF-8?q?tool=20for=20sqlite3=20,=20if=20table=20have=20a=20=E2=80=A6=20?= =?UTF-8?q?struct=20like=20this=20UNIQUE(xx,=20xx)=20,=20reverse=20will=20?= =?UTF-8?q?fail.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sqlite3_dialect.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sqlite3_dialect.go b/sqlite3_dialect.go index 80873dbd..9f29d587 100644 --- a/sqlite3_dialect.go +++ b/sqlite3_dialect.go @@ -8,6 +8,7 @@ import ( "database/sql" "errors" "fmt" + "regexp" "strings" "github.com/go-xorm/core" @@ -306,10 +307,13 @@ func (db *sqlite3) GetColumns(tableName string) ([]string, map[string]*core.Colu nStart := strings.Index(name, "(") nEnd := strings.LastIndex(name, ")") - colCreates := strings.Split(name[nStart+1:nEnd], ",") + reg := regexp.MustCompile(`[^\(,\)]*(\([^\(]*\))?`) + colCreates := reg.FindAllString(name[nStart+1:nEnd], -1) cols := make(map[string]*core.Column) colSeq := make([]string, 0) for _, colStr := range colCreates { + reg = regexp.MustCompile(`,\s`) + colStr = reg.ReplaceAllString(colStr, ",") fields := strings.Fields(strings.TrimSpace(colStr)) col := new(core.Column) col.Indexes = make(map[string]bool)