Skip to content
This repository was archived by the owner on May 24, 2023. It is now read-only.

Commit 0eccd0a

Browse files
committed
Merge pull request #21 from julienschmidt/statements
Statements do not reserve connections
2 parents a0f36c1 + 713187a commit 0eccd0a

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

retrieving.md

+4-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
layout: page
33
permalink: /retrieving/
44
title: Retrieving Result Sets
5-
tags:
5+
tags:
66
image:
77
feature: abstract-5.jpg
88
share: false
@@ -26,7 +26,7 @@ Fetching Data from the Database
2626
Let's take a look at an example of how to query the database, working with
2727
results. We'll query the `users` table for a user whose `id` is 1, and print out
2828
the user's `id` and `name`. We will assign results to variables, a row at a
29-
time, with `rows.Scan()`.
29+
time, with `rows.Scan()`.
3030

3131
var (
3232
id int
@@ -120,12 +120,8 @@ can triple the number of database interactions your application makes! Some
120120
drivers can avoid this in specific cases with an addition to `database/sql` in
121121
Go 1.1, but not all drivers are smart enough to do that. Caveat Emptor.
122122

123-
Statements are like results: they claim a connection and should be closed. It's
124-
idiomatic to `defer stmt.Close()` if the prepared statement `stmt` should not
125-
have a lifetime beyond the scope of the function. If you don't, it'll reserve a
126-
connection from the pool, and can cause resource exhaustion. (Note that for
127-
efficiency you should always close statements, rows, transactions, etc as soon
128-
as you can.)
123+
Naturally prepared statements and the managment of prepared statements cost
124+
resources. You should take care to close statements when they are not used again.
129125

130126
Single-Row Queries
131127
==================

surprises.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
layout: page
33
permalink: /surprises/
44
title: Surprises, Antipatterns and Limitations
5-
tags:
5+
tags:
66
image:
77
feature: abstract-5.jpg
88
share: false
@@ -20,7 +20,7 @@ you can certainly cause trouble for yourself, usually by consuming some
2020
resources or preventing them from being reused effectively:
2121

2222
* Opening and closing databases can cause exhaustion of resources.
23-
* Failing to use `rows.Close()` or `stmt.Close()` reserves connections from the pool.
23+
* Failing to read all rows or use `rows.Close()` reserves connections from the pool.
2424
* Using `Query()` for a statement that doesn't return rows will reserve a connection from the pool.
2525
* Failing to use prepared statements can lead to a lot of extra database activity.
2626

0 commit comments

Comments
 (0)