1
0
mirror of https://github.com/astaxie/beego.git synced 2024-12-23 03:30:49 +00:00

add support for field of type sql.NullXxx in rawSet.setFieldValue()

This commit is contained in:
zav8 2018-12-06 16:07:07 +08:00
parent 8152ade1b6
commit 5e4241fc87

View File

@ -150,8 +150,10 @@ func (o *rawSet) setFieldValue(ind reflect.Value, value interface{}) {
case reflect.Struct:
if value == nil {
ind.Set(reflect.Zero(ind.Type()))
} else if _, ok := ind.Interface().(time.Time); ok {
return
}
switch indi := ind.Interface().(type) {
case time.Time:
var str string
switch d := value.(type) {
case time.Time:
@ -178,6 +180,26 @@ func (o *rawSet) setFieldValue(ind reflect.Value, value interface{}) {
}
}
}
case sql.NullString:
err := indi.Scan(value)
if err == nil {
ind.Set(reflect.ValueOf(indi))
}
case sql.NullInt64:
err := indi.Scan(value)
if err == nil {
ind.Set(reflect.ValueOf(indi))
}
case sql.NullFloat64:
err := indi.Scan(value)
if err == nil {
ind.Set(reflect.ValueOf(indi))
}
case sql.NullBool:
err := indi.Scan(value)
if err == nil {
ind.Set(reflect.ValueOf(indi))
}
}
}
}