From 41c5c95a6c8cbe2b82b0afdbe96d982435b36cfd Mon Sep 17 00:00:00 2001 From: mattn Date: Sun, 13 Nov 2011 03:20:52 +0900 Subject: [PATCH] transaction. --- example/main.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/example/main.go b/example/main.go index 2fb4515..a17fa8b 100644 --- a/example/main.go +++ b/example/main.go @@ -28,7 +28,12 @@ func main() { } } - stmt, err := db.Prepare("insert into foo(id, name) values(?, ?)") + tx, err := db.Begin() + if err != nil { + fmt.Println(err) + return + } + stmt, err := tx.Prepare("insert into foo(id, name) values(?, ?)") if err != nil { fmt.Println(err) return @@ -42,6 +47,7 @@ func main() { return } } + tx.Commit() rows, err := db.Query("select id, name from foo") if err != nil { @@ -56,5 +62,4 @@ func main() { rows.Scan(&id, &name) println(id, name) } - }