This repository was archived by the owner on May 24, 2023. It is now read-only.
File tree 2 files changed +6
-10
lines changed
2 files changed +6
-10
lines changed Original file line number Diff line number Diff line change 2
2
layout : page
3
3
permalink : /retrieving/
4
4
title : Retrieving Result Sets
5
- tags :
5
+ tags :
6
6
image :
7
7
feature : abstract-5.jpg
8
8
share : false
@@ -26,7 +26,7 @@ Fetching Data from the Database
26
26
Let's take a look at an example of how to query the database, working with
27
27
results. We'll query the ` users ` table for a user whose ` id ` is 1, and print out
28
28
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() ` .
30
30
31
31
var (
32
32
id int
@@ -120,12 +120,8 @@ can triple the number of database interactions your application makes! Some
120
120
drivers can avoid this in specific cases with an addition to ` database/sql ` in
121
121
Go 1.1, but not all drivers are smart enough to do that. Caveat Emptor.
122
122
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.
129
125
130
126
Single-Row Queries
131
127
==================
Original file line number Diff line number Diff line change 2
2
layout : page
3
3
permalink : /surprises/
4
4
title : Surprises, Antipatterns and Limitations
5
- tags :
5
+ tags :
6
6
image :
7
7
feature : abstract-5.jpg
8
8
share : false
@@ -20,7 +20,7 @@ you can certainly cause trouble for yourself, usually by consuming some
20
20
resources or preventing them from being reused effectively:
21
21
22
22
* 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.
24
24
* Using ` Query() ` for a statement that doesn't return rows will reserve a connection from the pool.
25
25
* Failing to use prepared statements can lead to a lot of extra database activity.
26
26
You can’t perform that action at this time.
0 commit comments