Skip to content

Commit

Permalink
rows.Close gets invoked only after checking an error for nil (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
blkmlk authored Feb 11, 2023
1 parent 1bc6967 commit a28278b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,14 @@ func (s SQL) Aggregate(ctx context.Context, query rel.Query, mode string, field
rows, err = s.DoQuery(ctx, statement, args)
)

if err != nil {
return 0, s.ErrorMapper(err)
}

defer rows.Close()
if err == nil && rows.Next() {
rows.Scan(&out)

if rows.Next() {
err = rows.Scan(&out)
}

return int(out.Int64), s.ErrorMapper(err)
Expand Down

0 comments on commit a28278b

Please sign in to comment.