forked from mirror/go-sqlite3
parent
283f0f8809
commit
ded182737b
|
@ -9,6 +9,7 @@ package sqlite3
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
@ -71,3 +72,38 @@ func TestTransaction(t *testing.T) {
|
|||
t.Fatal("Expected failure to query")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTransactionConn(t *testing.T) {
|
||||
tempFilename := TempFilename(t)
|
||||
defer os.Remove(tempFilename)
|
||||
|
||||
driverName := fmt.Sprintf("sqlite3.%s", t.Name())
|
||||
|
||||
// The driver's connection will be needed in order to perform the backup.
|
||||
var dbConn *SQLiteConn
|
||||
sql.Register(driverName, &SQLiteDriver{
|
||||
ConnectHook: func(conn *SQLiteConn) error {
|
||||
dbConn = conn
|
||||
return nil
|
||||
},
|
||||
})
|
||||
|
||||
db, err := sql.Open(driverName, tempFilename)
|
||||
if err != nil {
|
||||
t.Fatal("Failed to open database:", err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
_, err = db.Exec("CREATE TABLE foo(id INTEGER)")
|
||||
if err != nil {
|
||||
t.Fatal("Failed to create table:", err)
|
||||
}
|
||||
|
||||
tx, err := dbConn.Begin()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if tx == nil {
|
||||
t.Fatal("Failed to create Transaction")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue