From de0f7e6cb169a549bc3a735819961ea706b35286 Mon Sep 17 00:00:00 2001 From: Lars Nielsen Date: Tue, 26 Sep 2017 11:28:56 +0200 Subject: [PATCH 1/2] Update to preapare --- prepared.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/prepared.md b/prepared.md index e382940..9690ed7 100644 --- a/prepared.md +++ b/prepared.md @@ -89,23 +89,24 @@ transactions. Consider the following example:
 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!
 
From b1965dbaf449789f74e5d0bbf8263dcb2e9b287b Mon Sep 17 00:00:00 2001 From: Lars Nielsen Date: Wed, 5 Oct 2022 11:30:42 +0200 Subject: [PATCH 2/2] Update prepared.md Co-authored-by: xaprb --- prepared.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prepared.md b/prepared.md index 9690ed7..7c305d3 100644 --- a/prepared.md +++ b/prepared.md @@ -106,7 +106,7 @@ for i := 0; i < 10; i++ { err = tx.Commit() if err != nil { log.Error(err) - tx.Rollback() + tx.Rollback() } // stmt.Close() runs here!