fix a bug: when use xorm reverse tool for sqlite3 , if table have a
struct like this UNIQUE(xx, xx) , reverse will fail.
This commit is contained in:
parent
90c454a96a
commit
83c043ea5a
|
@ -8,6 +8,7 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/go-xorm/core"
|
"github.com/go-xorm/core"
|
||||||
|
@ -306,10 +307,13 @@ func (db *sqlite3) GetColumns(tableName string) ([]string, map[string]*core.Colu
|
||||||
|
|
||||||
nStart := strings.Index(name, "(")
|
nStart := strings.Index(name, "(")
|
||||||
nEnd := strings.LastIndex(name, ")")
|
nEnd := strings.LastIndex(name, ")")
|
||||||
colCreates := strings.Split(name[nStart+1:nEnd], ",")
|
reg := regexp.MustCompile(`\w[\w\s]*(\([^\(]*\))?`)
|
||||||
|
colCreates := reg.FindAllString(name[nStart+1:nEnd], -1)
|
||||||
cols := make(map[string]*core.Column)
|
cols := make(map[string]*core.Column)
|
||||||
colSeq := make([]string, 0)
|
colSeq := make([]string, 0)
|
||||||
for _, colStr := range colCreates {
|
for _, colStr := range colCreates {
|
||||||
|
reg = regexp.MustCompile(`,\s`)
|
||||||
|
colStr = reg.ReplaceAllString(colStr, ",")
|
||||||
fields := strings.Fields(strings.TrimSpace(colStr))
|
fields := strings.Fields(strings.TrimSpace(colStr))
|
||||||
col := new(core.Column)
|
col := new(core.Column)
|
||||||
col.Indexes = make(map[string]bool)
|
col.Indexes = make(map[string]bool)
|
||||||
|
|
Loading…
Reference in New Issue