bug fixed for #283

This commit is contained in:
Lunny Xiao 2015-08-24 16:43:58 +08:00
parent 97e7703766
commit a01186e3cd
3 changed files with 15 additions and 11 deletions

View File

@ -1 +1 @@
xorm v0.4.3.0812 xorm v0.4.3.0824

View File

@ -2998,16 +2998,20 @@ func (session *Session) value2Interface(col *core.Column, fieldValue reflect.Val
return tf, nil return tf, nil
} }
if fieldTable, ok := session.Engine.Tables[fieldValue.Type()]; ok { if !col.SQLType.IsJson() {
// !<winxxp>! 增加支持driver.Valuer接口的结构如sql.NullString
if v, ok := fieldValue.Interface().(driver.Valuer); ok {
return v.Value()
}
fieldTable := session.Engine.autoMapType(fieldValue)
//if fieldTable, ok := session.Engine.Tables[fieldValue.Type()]; ok {
if len(fieldTable.PrimaryKeys) == 1 { if len(fieldTable.PrimaryKeys) == 1 {
pkField := reflect.Indirect(fieldValue).FieldByName(fieldTable.PKColumns()[0].FieldName) pkField := reflect.Indirect(fieldValue).FieldByName(fieldTable.PKColumns()[0].FieldName)
return pkField.Interface(), nil return pkField.Interface(), nil
} }
return 0, fmt.Errorf("no primary key for col %v", col.Name) return 0, fmt.Errorf("no primary key for col %v", col.Name)
} //}
// !<winxxp>! 增加支持driver.Valuer接口的结构如sql.NullString
if v, ok := fieldValue.Interface().(driver.Valuer); ok {
return v.Value()
} }
if col.SQLType.IsText() { if col.SQLType.IsText() {

View File

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