bug fixed for update which includes json struct fields

This commit is contained in:
Lunny Xiao 2015-10-29 13:30:22 +08:00
parent a0e63df407
commit 8bf440560e
3 changed files with 26 additions and 14 deletions

View File

@ -1 +1 @@
xorm v0.4.4.1027
xorm v0.4.4.1029

View File

@ -332,23 +332,35 @@ func buildUpdates(engine *Engine, table *core.Table, bean interface{},
} else if nulType, ok := fieldValue.Interface().(driver.Valuer); ok {
val, _ = nulType.Value()
} else {
engine.autoMapType(fieldValue)
if table, ok := engine.Tables[fieldValue.Type()]; ok {
if len(table.PrimaryKeys) == 1 {
pkField := reflect.Indirect(fieldValue).FieldByName(table.PKColumns()[0].FieldName)
// fix non-int pk issues
//if pkField.Int() != 0 {
if pkField.IsValid() && !isZero(pkField.Interface()) {
val = pkField.Interface()
if !col.SQLType.IsJson() {
engine.autoMapType(fieldValue)
if table, ok := engine.Tables[fieldValue.Type()]; ok {
if len(table.PrimaryKeys) == 1 {
pkField := reflect.Indirect(fieldValue).FieldByName(table.PKColumns()[0].FieldName)
// fix non-int pk issues
//if pkField.Int() != 0 {
if pkField.IsValid() && !isZero(pkField.Interface()) {
val = pkField.Interface()
} else {
continue
}
} else {
continue
//TODO: how to handler?
panic("not supported")
}
} else {
//TODO: how to handler?
panic("not supported")
val = fieldValue.Interface()
}
} else {
val = fieldValue.Interface()
bytes, err := json.Marshal(fieldValue.Interface())
if err != nil {
panic(fmt.Sprintf("mashal %v failed", fieldValue.Interface()))
}
if col.SQLType.IsText() {
val = string(bytes)
} else if col.SQLType.IsBlob() {
val = bytes
}
}
}
case reflect.Array, reflect.Slice, reflect.Map:

View File

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