[feat] 增加解决 converting NULL to string is unsupported 的类型
This commit is contained in:
+4
-1
@@ -77,7 +77,10 @@ func (s *scanner) ScanStruct(i interface{}) error {
|
|||||||
// 处理 converting NULL to string is unsupported
|
// 处理 converting NULL to string is unsupported
|
||||||
// 前面将 string 和 int 类型转为了 *string 和 *int
|
// 前面将 string 和 int 类型转为了 *string 和 *int
|
||||||
switch data.GoType.Kind() {
|
switch data.GoType.Kind() {
|
||||||
case reflect.String, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
case reflect.String,
|
||||||
|
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
||||||
|
reflect.Float32, reflect.Float64,
|
||||||
|
reflect.Bool:
|
||||||
scans = append(scans, reflect.New(reflect.PointerTo(data.GoType)).Interface())
|
scans = append(scans, reflect.New(reflect.PointerTo(data.GoType)).Interface())
|
||||||
default:
|
default:
|
||||||
scans = append(scans, reflect.New(data.GoType).Interface())
|
scans = append(scans, reflect.New(data.GoType).Interface())
|
||||||
|
|||||||
@@ -171,7 +171,9 @@ func SafeSetFieldByIndex(v reflect.Value, fieldIndex []int, src interface{}) (re
|
|||||||
// 处理 converting NULL to string is unsupported
|
// 处理 converting NULL to string is unsupported
|
||||||
// 前面将 string 和 int 类型转为了 *string 和 *int
|
// 前面将 string 和 int 类型转为了 *string 和 *int
|
||||||
// 这里做还原
|
// 这里做还原
|
||||||
if f.Type().ConvertibleTo(srcVal.Type().Elem()) {
|
if srcVal.IsNil() {
|
||||||
|
f.Set(reflect.Zero(f.Type()))
|
||||||
|
} else if f.Type().ConvertibleTo(srcVal.Type().Elem()) {
|
||||||
f.Set(srcVal.Elem())
|
f.Set(srcVal.Elem())
|
||||||
} else {
|
} else {
|
||||||
f.Set(srcVal)
|
f.Set(srcVal)
|
||||||
|
|||||||
Reference in New Issue
Block a user