declare variables

This commit is contained in:
demoManito 2024-03-07 16:37:02 +08:00
parent 4c7c8f596d
commit a458bbb6a1

View File

@ -311,8 +311,9 @@ 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() < int(db.RowsAffected) {
if isArrayKind && reflectValue.Len() < rows {
break
}
@ -320,7 +321,7 @@ func Scan(rows Rows, db *DB, mode ScanMode) {
elem = elem.Elem()
}
if isArrayKind {
reflectValue.Index(int(db.RowsAffected - 1)).Set(elem)
reflectValue.Index(rows - 1).Set(elem)
} else {
reflectValue = reflect.Append(reflectValue, elem)
}