exp/sql: close Rows on EOF

Fixes #2624

R=rsc
CC=golang-dev
https://golang.org/cl/5530068
This commit is contained in:
Brad Fitzpatrick 2012-01-10 12:51:27 -08:00
parent 25cf9bdea6
commit 4435c8bf2a
3 changed files with 31 additions and 11 deletions

View file

@ -549,8 +549,8 @@ func (s *Stmt) Exec(args ...interface{}) (Result, error) {
// statement, a function to call to release the connection, and a
// statement bound to that connection.
func (s *Stmt) connStmt() (ci driver.Conn, releaseConn func(), si driver.Stmt, err error) {
if s.stickyErr != nil {
return nil, nil, nil, s.stickyErr
if err = s.stickyErr; err != nil {
return
}
s.mu.Lock()
if s.closed {
@ -726,6 +726,9 @@ func (rs *Rows) Next() bool {
rs.lastcols = make([]interface{}, len(rs.rowsi.Columns()))
}
rs.lasterr = rs.rowsi.Next(rs.lastcols)
if rs.lasterr == io.EOF {
rs.Close()
}
return rs.lasterr == nil
}