Commit 5e4241fc authored by zav8's avatar zav8

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

parent 8152ade1
......@@ -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))
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment