This commit is contained in:
Lunny Xiao 2016-01-02 22:58:49 +08:00
parent 069f551119
commit 8700152b6c
5 changed files with 45 additions and 3 deletions

View File

@ -1 +1 @@
xorm v0.4.4.1230 xorm v0.4.5.0102

View File

@ -759,7 +759,7 @@ func (engine *Engine) mapType(v reflect.Value) *core.Table {
if ormTagStr != "" { if ormTagStr != "" {
col = &core.Column{FieldName: t.Field(i).Name, Nullable: true, IsPrimaryKey: false, col = &core.Column{FieldName: t.Field(i).Name, Nullable: true, IsPrimaryKey: false,
IsAutoIncrement: false, MapType: core.TWOSIDES, Indexes: make(map[string]bool)} IsAutoIncrement: false, MapType: core.TWOSIDES, Indexes: make(map[string]bool)}
tags := strings.Split(ormTagStr, " ") tags := splitTag(ormTagStr)
if len(tags) > 0 { if len(tags) > 0 {
if tags[0] == "-" { if tags[0] == "-" {

View File

@ -15,6 +15,26 @@ import (
"github.com/go-xorm/core" "github.com/go-xorm/core"
) )
func splitTag(tag string) (tags []string) {
tag = strings.TrimSpace(tag)
var hasQuote = false
var lastIdx = 0
for i, t := range tag {
if t == '\'' {
hasQuote = !hasQuote
} else if t == ' ' {
if lastIdx < i && !hasQuote {
tags = append(tags, strings.TrimSpace(tag[lastIdx:i]))
lastIdx = i + 1
}
}
}
if lastIdx < len(tag) {
tags = append(tags, strings.TrimSpace(tag[lastIdx:len(tag)]))
}
return
}
type zeroable interface { type zeroable interface {
IsZero() bool IsZero() bool
} }

22
helpers_test.go Normal file
View File

@ -0,0 +1,22 @@
package xorm
import "testing"
func TestSplitTag(t *testing.T) {
var cases = []struct {
tag string
tags []string
}{
{"not null default '2000-01-01 00:00:00' TIMESTAMP", []string{"not", "null", "default", "'2000-01-01 00:00:00'", "TIMESTAMP"}},
{"TEXT", []string{"TEXT"}},
{"default('2000-01-01 00:00:00')", []string{"default('2000-01-01 00:00:00')"}},
{"json binary", []string{"json", "binary"}},
}
for _, kase := range cases {
tags := splitTag(kase.tag)
if !sliceEq(tags, kase.tags) {
t.Fatalf("[%d]%v is not equal [%d]%v", len(tags), tags, len(kase.tags), kase.tags)
}
}
}

View File

@ -17,7 +17,7 @@ import (
) )
const ( const (
Version string = "0.4.4.1230" Version string = "0.4.5.0102"
) )
func regDrvsNDialects() bool { func regDrvsNDialects() bool {