diff --git a/driver/transaction_test.go b/driver/transaction_test.go index 01d6e5b..40b6c30 100644 --- a/driver/transaction_test.go +++ b/driver/transaction_test.go @@ -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") + } +}