aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/database/sql/sql.go
diff options
context:
space:
mode:
authorNigel Tao <nigeltao@golang.org>2014-03-25 13:32:18 +1100
committerNigel Tao <nigeltao@golang.org>2014-03-25 13:32:18 +1100
commit50ca1a52ca39bdd76bb5f999a67450f5984ebba2 (patch)
treef7cde716ca6b27395b444b64f4ae3b2374e9ad50 /src/pkg/database/sql/sql.go
parent3750904a7efc36aa4f604497b53a9dc1ea67492b (diff)
downloadgo-50ca1a52ca39bdd76bb5f999a67450f5984ebba2.tar.xz
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
Diffstat (limited to 'src/pkg/database/sql/sql.go')
-rw-r--r--src/pkg/database/sql/sql.go1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/pkg/database/sql/sql.go b/src/pkg/database/sql/sql.go
index 4f86d24b2e..e891d4f4c4 100644
--- a/src/pkg/database/sql/sql.go
+++ b/src/pkg/database/sql/sql.go
@@ -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