Skip to content

Commit

Permalink
Multi-Results: fix hanging rows.Close()
Browse files Browse the repository at this point in the history
* rows.Close() would hang on readUntilEOF if some results were ignored before calling NextResultSet()
  • Loading branch information
jszwec committed Jan 15, 2017
1 parent 0ac9483 commit 8b062e7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions driver_go18_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,24 @@ func TestMultiResultSetNoSelect(t *testing.T) {
}
})
}

// tests if rows are set in a proper state if some results were ignored before
// calling rows.NextResultSet.
func TestSkipResults(t *testing.T) {
runTests(t, dsn, func(dbt *DBTest) {
rows := dbt.mustQuery("SELECT 1, 2")
defer rows.Close()

if !rows.Next() {
dbt.Error("expected row")
}

if rows.NextResultSet() {
dbt.Error("unexpected next result set")
}

if err := rows.Err(); err != nil {
dbt.Error("expected nil; got ", err)
}
})
}
2 changes: 2 additions & 0 deletions rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ func (rows *mysqlRows) nextResultSet() (int, error) {
if err := rows.mc.readUntilEOF(); err != nil {
return 0, err
}
rows.rs.done = true
}

if !rows.HasNextResultSet() {
rows.mc = nil
return 0, io.EOF
}
rows.rs = resultSet{}
Expand Down

0 comments on commit 8b062e7

Please sign in to comment.