mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
database/sql: add "defer rows.Close()" to the example code.
Strictly speaking, it's not necessary in example_test.go, as the Rows.Close docs say that "If Next returns false, the Rows are closed automatically". However, if the for loop breaks or returns early, it's not obvious that you'll leak unless you explicitly call Rows.Close. LGTM=bradfitz R=bradfitz CC=golang-codereviews, rsc https://golang.org/cl/79330043
This commit is contained in:
parent
3750904a7e
commit
50ca1a52ca
2 changed files with 2 additions and 0 deletions
|
|
@ -1494,6 +1494,7 @@ func (s *Stmt) finalClose() error {
|
|||
//
|
||||
// rows, err := db.Query("SELECT ...")
|
||||
// ...
|
||||
// defer rows.Close()
|
||||
// for rows.Next() {
|
||||
// var id int
|
||||
// var name string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue