From f9ca4a49ce63d2e658bb3b8160849f465790de04 Mon Sep 17 00:00:00 2001 From: what Date: Sat, 22 Mar 2025 23:30:23 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=20=E5=A2=9E=E5=8A=A0=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=20converting=20NULL=20to=20string=20is=20unsupported=20?= =?UTF-8?q?=E7=9A=84=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exec/scanner.go | 5 ++++- internal/util/reflect.go | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/exec/scanner.go b/exec/scanner.go index 8955aa3..4489a45 100644 --- a/exec/scanner.go +++ b/exec/scanner.go @@ -77,7 +77,10 @@ func (s *scanner) ScanStruct(i interface{}) error { // 处理 converting NULL to string is unsupported // 前面将 string 和 int 类型转为了 *string 和 *int 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()) default: scans = append(scans, reflect.New(data.GoType).Interface()) diff --git a/internal/util/reflect.go b/internal/util/reflect.go index 66e8c70..f29d646 100644 --- a/internal/util/reflect.go +++ b/internal/util/reflect.go @@ -171,7 +171,9 @@ func SafeSetFieldByIndex(v reflect.Value, fieldIndex []int, src interface{}) (re // 处理 converting NULL to string is unsupported // 前面将 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()) } else { f.Set(srcVal)