database/sql: fix case where Stmt.Close discards error

Fixes a case where the Stmt.Close() function in database/sql discards any error generated by the Close() function of the contained driverStmt.

Fixes #12798

Change-Id: I40384d6165856665b062d15a643e4ecc09d63fda
Reviewed-on: https://go-review.googlesource.com/15178
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Ian Gudger 2015-10-01 03:29:27 -07:00 committed by Brad Fitzpatrick
parent f80ff56a7d
commit 73fe61233b
2 changed files with 40 additions and 2 deletions

View file

@ -356,6 +356,44 @@ func TestStatementQueryRow(t *testing.T) {
}
}
type stubDriverStmt struct {
err error
}
func (s stubDriverStmt) Close() error {
return s.err
}
func (s stubDriverStmt) NumInput() int {
return -1
}
func (s stubDriverStmt) Exec(args []driver.Value) (driver.Result, error) {
return nil, nil
}
func (s stubDriverStmt) Query(args []driver.Value) (driver.Rows, error) {
return nil, nil
}
// golang.org/issue/12798
func TestStatementClose(t *testing.T) {
want := errors.New("STMT ERROR")
tests := []struct {
stmt *Stmt
msg string
}{
{&Stmt{stickyErr: want}, "stickyErr not propagated"},
{&Stmt{tx: &Tx{}, txsi: &driverStmt{&sync.Mutex{}, stubDriverStmt{want}}}, "driverStmt.Close() error not propagated"},
}
for _, test := range tests {
if err := test.stmt.Close(); err != want {
t.Errorf("%s. Got stmt.Close() = %v, want = %v", test.msg, err, want)
}
}
}
// golang.org/issue/3734
func TestStatementQueryRowConcurrent(t *testing.T) {
db := newTestDB(t, "people")