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

Changes to Prepare.md to compensate for unintended behaviour #85

Open
wants to merge 2 commits into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions prepared.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,24 @@ transactions. Consider the following example:
<pre class="prettyprint lang-go">
tx, err := db.Begin()
if err != nil {
log.Fatal(err)
log.Error(err)
}
defer tx.Rollback()

stmt, err := tx.Prepare("INSERT INTO foo VALUES (?)")
if err != nil {
log.Fatal(err)
log.Error(err)
}
defer stmt.Close() // danger!
for i := 0; i < 10; i++ {
_, err = stmt.Exec(i)
if err != nil {
log.Fatal(err)
log.Error(err)
}
}
err = tx.Commit()
if err != nil {
log.Fatal(err)
log.Error(err)
tx.Rollback()
}
// stmt.Close() runs here!
</pre>
Expand Down