database/sql: fix typo bug resulting in double-Prepare

Bug reported by Blake Mizerany found while writing
his new Postgres driver.

R=golang-dev, blake.mizerany
CC=golang-dev
https://golang.org/cl/5754057
This commit is contained in:
Brad Fitzpatrick 2012-03-06 14:10:58 -08:00
parent 97b13acb67
commit 48eacd90a8
3 changed files with 17 additions and 2 deletions

View file

@ -82,6 +82,7 @@ type fakeConn struct {
mu sync.Mutex
stmtsMade int
stmtsClosed int
numPrepare int
}
func (c *fakeConn) incrStat(v *int) {
@ -339,6 +340,7 @@ func (c *fakeConn) prepareInsert(stmt *fakeStmt, parts []string) (driver.Stmt, e
}
func (c *fakeConn) Prepare(query string) (driver.Stmt, error) {
c.numPrepare++
if c.db == nil {
panic("nil c.db; conn = " + fmt.Sprintf("%#v", c))
}