Skip to content

Commit 05fe5f8

Browse files
committed
Explain seemingly redundant rows.Close() in CollectOneRow
fixes #2282
1 parent 70c9a14 commit 05fe5f8

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

rows.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,8 @@ func CollectOneRow[T any](rows Rows, fn RowToFunc[T]) (T, error) {
473473
return value, err
474474
}
475475

476+
// The defer rows.Close() won't have executed yet. If the query returned more than one row, rows would still be open.
477+
// rows.Close() must be called before rows.Err() so we explicitly call it here.
476478
rows.Close()
477479
return value, rows.Err()
478480
}

0 commit comments

Comments
 (0)