This commit is contained in:
Lunny Xiao 2014-01-16 23:03:56 +08:00
parent 6147651a6e
commit 346681289d
3 changed files with 54 additions and 3 deletions

View File

@ -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{}
func update(engine *Engine, t *testing.T) {
@ -314,6 +324,44 @@ func update(engine *Engine, t *testing.T) {
panic(err)
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) {

View File

@ -482,6 +482,7 @@ func (engine *Engine) mapType(t reflect.Type) *Table {
}
var indexType int
var indexName string
var preKey string
for j, key := range tags {
k := strings.ToUpper(key)
switch {
@ -520,12 +521,13 @@ func (engine *Engine) mapType(t reflect.Type) *Table {
case k == "NOT":
default:
if strings.HasPrefix(k, "'") && strings.HasSuffix(k, "'") {
if key != col.Default {
if preKey != "DEFAULT" {
col.Name = key[1 : len(key)-1]
}
} else if strings.Contains(k, "(") && strings.HasSuffix(k, ")") {
fs := strings.Split(k, "(")
if _, ok := sqlTypes[fs[0]]; !ok {
preKey = k
continue
}
col.SQLType = SQLType{fs[0], 0, 0}
@ -539,12 +541,13 @@ func (engine *Engine) mapType(t reflect.Type) *Table {
} else {
if _, ok := sqlTypes[k]; ok {
col.SQLType = SQLType{k, 0, 0}
} else if key != col.Default {
} else if preKey != "DEFAULT" {
col.Name = key
}
}
engine.SqlType(col)
}
preKey = k
}
if col.SQLType.Name == "" {
col.SQLType = Type2SQLType(fieldType)

View File

@ -67,7 +67,7 @@ func (db *postgres) SqlType(c *Column) string {
switch t := c.SQLType.Name; t {
case TinyInt:
res = SmallInt
return res
case MediumInt, Int, Integer:
if c.IsAutoIncrement {
return Serial