txdb.Register("txdb", "driver", "dsn")
db, _ := sql.Open("txdb", "identifier") // Called db.Begin()
db.Close() // tx left open
This bug would block code from locking the entire underlying database after txdb grabbed its connection. For example, if TestMain created a temporary test database and opened it with txdb, it would be impossible to drop this database after the test was over.
This patch defers beginning a transaction until it is actually needed, which is when the connection will be opened.
When the number of txDriver.conns drops to zero, it closes the root txDriver.db. Since database/sql maintains a free pool of connections, this practically happens only when DB.Close is called.
Code that used to make database calls after DB.Close will now get a "sql: database is closed" error. They should either hoist the DB.Close call to where the txdb was opened, or reopen it again.
database/sql.DB.Close
closes all connections, but txdb did not actually do this:This bug would block code from locking the entire underlying database after txdb grabbed its connection. For example, if
TestMain
created a temporary test database and opened it with txdb, it would be impossible to drop this database after the test was over.This patch defers beginning a transaction until it is actually needed, which is when the connection will be opened.
When the number of
txDriver.conns
drops to zero, it closes the roottxDriver.db
. Since database/sql maintains a free pool of connections, this practically happens only whenDB.Close
is called.Code that used to make database calls after
DB.Close
will now get a"sql: database is closed"
error. They should either hoist theDB.Close
call to where the txdb was opened, or reopen it again.Closes: #28