fix(scan): array element is set to a zero value

This commit is contained in:
demoManito 2024-03-11 12:05:02 +08:00
parent e4e23d26d2
commit f6d9ee7959

View File

@ -274,7 +274,11 @@ func Scan(rows Rows, db *DB, mode ScanMode) {
if !update || reflectValue.Len() == 0 { if !update || reflectValue.Len() == 0 {
update = false update = false
if !isArrayKind { if isArrayKind {
for i := 0; i < reflectValue.Len(); i++ {
reflectValue.Index(i).Set(reflect.Zero(reflectValue.Index(i).Type()))
}
} else {
// if the slice cap is externally initialized, the externally initialized slice is directly used here // if the slice cap is externally initialized, the externally initialized slice is directly used here
if reflectValue.Cap() == 0 { if reflectValue.Cap() == 0 {
db.Statement.ReflectValue.Set(reflect.MakeSlice(reflectValue.Type(), 0, 20)) db.Statement.ReflectValue.Set(reflect.MakeSlice(reflectValue.Type(), 0, 20))