1
0
mirror of https://github.com/golang/go synced 2024-11-22 22:30:02 -07:00

database/sql: close statement before connection

Fixes #5936

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/11620046
This commit is contained in:
Alex Brainman 2013-07-23 14:09:53 +10:00
parent abe384f68a
commit a293065a39
2 changed files with 15 additions and 1 deletions

View File

@ -759,10 +759,10 @@ func (db *DB) queryConn(dc *driverConn, releaseConn func(error), query string, a
ds := driverStmt{dc, si}
rowsi, err := rowsiFromStatement(ds, args...)
if err != nil {
releaseConn(err)
dc.Lock()
si.Close()
dc.Unlock()
releaseConn(err)
return nil, err
}

View File

@ -1046,6 +1046,20 @@ func TestRowsCloseOrder(t *testing.T) {
}
}
func TestStmtCloseOrder(t *testing.T) {
db := newTestDB(t, "people")
defer closeDB(t, db)
db.SetMaxIdleConns(0)
setStrictFakeConnClose(t)
defer setStrictFakeConnClose(nil)
_, err := db.Query("SELECT|non_existent|name|")
if err == nil {
t.Fatal("Quering non-existent table should fail")
}
}
func manyConcurrentQueries(t testOrBench) {
maxProcs, numReqs := 16, 500
if testing.Short() {