diff --git a/sq/scanner.go b/sq/scanner.go index 00833a6..e77a64f 100644 --- a/sq/scanner.go +++ b/sq/scanner.go @@ -50,7 +50,6 @@ func ScanSingle[TData any](rows *sqlx.Rows, mode StructScanMode, sec StructScanS return *new(TData), err } } else if mode == SModeExtended { - var data TData err := strscan.StructScanExt(&data) if err != nil { return *new(TData), err diff --git a/sq/structscanner.go b/sq/structscanner.go index f834692..758eb94 100644 --- a/sq/structscanner.go +++ b/sq/structscanner.go @@ -113,7 +113,7 @@ func (r *StructScanner) StructScanExt(dest any) error { if _, ok := forcenulled[k]; !ok { f := reflectx.FieldByIndexes(v, traversal[0:i]) - f.Set(reflect.New(f.Type().Elem())) // set to nil + f.Set(reflect.Zero(f.Type())) // set to nil forcenulled[k] = true } @@ -138,7 +138,7 @@ func (r *StructScanner) StructScanExt(dest any) error { return errors.New(fmt.Sprintf("Cannot set field %v to NULL value from column '%s' (type: %s)", traversal, r.columns[i], f.Type().String())) } - f.Set(reflect.New(f.Type().Elem())) // set to nil + f.Set(reflect.Zero(f.Type())) // set to nil } else { f.Set(val3) }