File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22layout : page
33permalink : /retrieving/
44title : Retrieving Result Sets
5- tags :
5+ tags :
66image :
77 feature : abstract-5.jpg
88share : false
@@ -26,7 +26,7 @@ Fetching Data from the Database
2626Let's take a look at an example of how to query the database, working with
2727results. We'll query the ` users ` table for a user whose ` id ` is 1, and print out
2828the 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
120120drivers can avoid this in specific cases with an addition to ` database/sql ` in
121121Go 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
130126Single-Row Queries
131127==================
Original file line number Diff line number Diff line change 22layout : page
33permalink : /surprises/
44title : Surprises, Antipatterns and Limitations
5- tags :
5+ tags :
66image :
77 feature : abstract-5.jpg
88share : false
@@ -20,7 +20,7 @@ you can certainly cause trouble for yourself, usually by consuming some
2020resources 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
You can’t perform that action at this time.
0 commit comments