refactor(scan.go): array index is out of bounds exits the for loop
This commit is contained in:
parent
f7ebf049da
commit
4c7c8f596d
9
scan.go
9
scan.go
@ -311,13 +311,16 @@ func Scan(rows Rows, db *DB, mode ScanMode) {
|
|||||||
db.scanIntoStruct(rows, elem, values, fields, joinFields)
|
db.scanIntoStruct(rows, elem, values, fields, joinFields)
|
||||||
|
|
||||||
if !update {
|
if !update {
|
||||||
|
// array index is out of bounds, exits the for loop
|
||||||
|
if isArrayKind && reflectValue.Len() < int(db.RowsAffected) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
if !isPtr {
|
if !isPtr {
|
||||||
elem = elem.Elem()
|
elem = elem.Elem()
|
||||||
}
|
}
|
||||||
if isArrayKind {
|
if isArrayKind {
|
||||||
if reflectValue.Len() >= int(db.RowsAffected) {
|
reflectValue.Index(int(db.RowsAffected - 1)).Set(elem)
|
||||||
reflectValue.Index(int(db.RowsAffected - 1)).Set(elem)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
reflectValue = reflect.Append(reflectValue, elem)
|
reflectValue = reflect.Append(reflectValue, elem)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user