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() {
if len(fieldTable.PrimaryKeys) == 1 { // !<winxxp>! 增加支持driver.Valuer接口的结构如sql.NullString
pkField := reflect.Indirect(fieldValue).FieldByName(fieldTable.PKColumns()[0].FieldName) if v, ok := fieldValue.Interface().(driver.Valuer); ok {
return pkField.Interface(), nil return v.Value()
} }
return 0, fmt.Errorf("no primary key for col %v", col.Name)
} fieldTable := session.Engine.autoMapType(fieldValue)
// !<winxxp>! 增加支持driver.Valuer接口的结构如sql.NullString //if fieldTable, ok := session.Engine.Tables[fieldValue.Type()]; ok {
if v, ok := fieldValue.Interface().(driver.Valuer); ok { if len(fieldTable.PrimaryKeys) == 1 {
return v.Value() pkField := reflect.Indirect(fieldValue).FieldByName(fieldTable.PKColumns()[0].FieldName)
return pkField.Interface(), nil
}
return 0, fmt.Errorf("no primary key for col %v", col.Name)
//}
} }
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 {