mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
sql: add Tx.Stmt to use an existing prepared stmt in a transaction
R=rsc CC=golang-dev https://golang.org/cl/5433059
This commit is contained in:
parent
23227f3d63
commit
e77099daa2
2 changed files with 83 additions and 20 deletions
|
|
@ -166,7 +166,7 @@ func TestBogusPreboundParameters(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestDb(t *testing.T) {
|
||||
func TestExec(t *testing.T) {
|
||||
db := newTestDB(t, "foo")
|
||||
defer closeDB(t, db)
|
||||
exec(t, db, "CREATE|t1|name=string,age=int32,dead=bool")
|
||||
|
|
@ -206,3 +206,25 @@ func TestDb(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTxStmt(t *testing.T) {
|
||||
db := newTestDB(t, "")
|
||||
defer closeDB(t, db)
|
||||
exec(t, db, "CREATE|t1|name=string,age=int32,dead=bool")
|
||||
stmt, err := db.Prepare("INSERT|t1|name=?,age=?")
|
||||
if err != nil {
|
||||
t.Fatalf("Stmt, err = %v, %v", stmt, err)
|
||||
}
|
||||
tx, err := db.Begin()
|
||||
if err != nil {
|
||||
t.Fatalf("Begin = %v", err)
|
||||
}
|
||||
_, err = tx.Stmt(stmt).Exec("Bobby", 7)
|
||||
if err != nil {
|
||||
t.Fatalf("Exec = %v", err)
|
||||
}
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
t.Fatalf("Commit = %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue