transaction.

This commit is contained in:
mattn 2011-11-13 03:20:52 +09:00
parent 0b35f58e9d
commit 41c5c95a6c
1 changed files with 7 additions and 2 deletions

View File

@ -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 { if err != nil {
fmt.Println(err) fmt.Println(err)
return return
@ -42,6 +47,7 @@ func main() {
return return
} }
} }
tx.Commit()
rows, err := db.Query("select id, name from foo") rows, err := db.Query("select id, name from foo")
if err != nil { if err != nil {
@ -56,5 +62,4 @@ func main() {
rows.Scan(&id, &name) rows.Scan(&id, &name)
println(id, name) println(id, name)
} }
} }