From adf114a7fc699e3553741f85c96405f7a2d5c804 Mon Sep 17 00:00:00 2001 From: demoManito <1430482733@qq.com> Date: Sun, 17 Mar 2024 23:13:01 +0800 Subject: [PATCH] optimization logic --- scan.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scan.go b/scan.go index 9c91d2af..ba4a6964 100644 --- a/scan.go +++ b/scan.go @@ -311,9 +311,8 @@ func Scan(rows Rows, db *DB, mode ScanMode) { db.scanIntoStruct(rows, elem, values, fields, joinFields) if !update { - rows := int(db.RowsAffected) // array index is out of bounds, exits the for loop - if isArrayKind && reflectValue.Len() < rows { + if isArrayKind && reflectValue.Len() < int(db.RowsAffected) { break } @@ -321,7 +320,7 @@ func Scan(rows Rows, db *DB, mode ScanMode) { elem = elem.Elem() } if isArrayKind { - reflectValue.Index(rows - 1).Set(elem) + reflectValue.Index(int(db.RowsAffected - 1)).Set(elem) } else { reflectValue = reflect.Append(reflectValue, elem) }