bug fixed #51
This commit is contained in:
parent
6147651a6e
commit
346681289d
48
base_test.go
48
base_test.go
|
@ -267,6 +267,16 @@ func insertTwoTable(engine *Engine, t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Article struct {
|
||||||
|
Id int32 `xorm:"pk INT autoincr"`
|
||||||
|
Name string `xorm:"VARCHAR(45)"`
|
||||||
|
Img string `xorm:"VARCHAR(100)"`
|
||||||
|
Aside string `xorm:"VARCHAR(200)"`
|
||||||
|
Desc string `xorm:"VARCHAR(200)"`
|
||||||
|
Content string `xorm:"TEXT"`
|
||||||
|
Status int8 `xorm:"TINYINT(4)"`
|
||||||
|
}
|
||||||
|
|
||||||
type Condi map[string]interface{}
|
type Condi map[string]interface{}
|
||||||
|
|
||||||
func update(engine *Engine, t *testing.T) {
|
func update(engine *Engine, t *testing.T) {
|
||||||
|
@ -314,6 +324,44 @@ func update(engine *Engine, t *testing.T) {
|
||||||
panic(err)
|
panic(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = engine.Sync(&Article{})
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cnt, err = engine.Insert(&Article{0, "1", "2", "3", "4", "5", 2})
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cnt != 1 {
|
||||||
|
err = errors.New("insert not returned 1")
|
||||||
|
t.Error(err)
|
||||||
|
panic(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cnt, err = engine.Id(1).Update(&Article{Name: "6"})
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cnt != 1 {
|
||||||
|
err = errors.New("update not returned 1")
|
||||||
|
t.Error(err)
|
||||||
|
panic(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = engine.DropTables(&Article{})
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateSameMapper(engine *Engine, t *testing.T) {
|
func updateSameMapper(engine *Engine, t *testing.T) {
|
||||||
|
|
|
@ -482,6 +482,7 @@ func (engine *Engine) mapType(t reflect.Type) *Table {
|
||||||
}
|
}
|
||||||
var indexType int
|
var indexType int
|
||||||
var indexName string
|
var indexName string
|
||||||
|
var preKey string
|
||||||
for j, key := range tags {
|
for j, key := range tags {
|
||||||
k := strings.ToUpper(key)
|
k := strings.ToUpper(key)
|
||||||
switch {
|
switch {
|
||||||
|
@ -520,12 +521,13 @@ func (engine *Engine) mapType(t reflect.Type) *Table {
|
||||||
case k == "NOT":
|
case k == "NOT":
|
||||||
default:
|
default:
|
||||||
if strings.HasPrefix(k, "'") && strings.HasSuffix(k, "'") {
|
if strings.HasPrefix(k, "'") && strings.HasSuffix(k, "'") {
|
||||||
if key != col.Default {
|
if preKey != "DEFAULT" {
|
||||||
col.Name = key[1 : len(key)-1]
|
col.Name = key[1 : len(key)-1]
|
||||||
}
|
}
|
||||||
} else if strings.Contains(k, "(") && strings.HasSuffix(k, ")") {
|
} else if strings.Contains(k, "(") && strings.HasSuffix(k, ")") {
|
||||||
fs := strings.Split(k, "(")
|
fs := strings.Split(k, "(")
|
||||||
if _, ok := sqlTypes[fs[0]]; !ok {
|
if _, ok := sqlTypes[fs[0]]; !ok {
|
||||||
|
preKey = k
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
col.SQLType = SQLType{fs[0], 0, 0}
|
col.SQLType = SQLType{fs[0], 0, 0}
|
||||||
|
@ -539,12 +541,13 @@ func (engine *Engine) mapType(t reflect.Type) *Table {
|
||||||
} else {
|
} else {
|
||||||
if _, ok := sqlTypes[k]; ok {
|
if _, ok := sqlTypes[k]; ok {
|
||||||
col.SQLType = SQLType{k, 0, 0}
|
col.SQLType = SQLType{k, 0, 0}
|
||||||
} else if key != col.Default {
|
} else if preKey != "DEFAULT" {
|
||||||
col.Name = key
|
col.Name = key
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
engine.SqlType(col)
|
engine.SqlType(col)
|
||||||
}
|
}
|
||||||
|
preKey = k
|
||||||
}
|
}
|
||||||
if col.SQLType.Name == "" {
|
if col.SQLType.Name == "" {
|
||||||
col.SQLType = Type2SQLType(fieldType)
|
col.SQLType = Type2SQLType(fieldType)
|
||||||
|
|
|
@ -67,7 +67,7 @@ func (db *postgres) SqlType(c *Column) string {
|
||||||
switch t := c.SQLType.Name; t {
|
switch t := c.SQLType.Name; t {
|
||||||
case TinyInt:
|
case TinyInt:
|
||||||
res = SmallInt
|
res = SmallInt
|
||||||
|
return res
|
||||||
case MediumInt, Int, Integer:
|
case MediumInt, Int, Integer:
|
||||||
if c.IsAutoIncrement {
|
if c.IsAutoIncrement {
|
||||||
return Serial
|
return Serial
|
||||||
|
|
Loading…
Reference in New Issue