aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/database/sql/example_test.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/example_test.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/example_test.go')
-rw-r--r--src/pkg/database/sql/example_test.go1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/pkg/database/sql/example_test.go b/src/pkg/database/sql/example_test.go
index d47eed50c0..dcb74e0699 100644
--- a/src/pkg/database/sql/example_test.go
+++ b/src/pkg/database/sql/example_test.go
@@ -18,6 +18,7 @@ func ExampleDB_Query() {
if err != nil {
log.Fatal(err)
}
+ defer rows.Close()
for rows.Next() {
var name string
if err := rows.Scan(&name); err != nil {