File tree 2 files changed +35
-1
lines changed
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -1339,7 +1339,12 @@ func (rs *rows) Close() error {
1339
1339
switch err {
1340
1340
case nil :
1341
1341
case io .EOF :
1342
- return nil
1342
+ // rs.Next can return io.EOF on both 'Z' (ready for query) and 'T' (row
1343
+ // description, used with HasNextResultSet). We need to fetch messages until
1344
+ // we hit a 'Z', which is done by waiting for done to be set.
1345
+ if rs .done {
1346
+ return nil
1347
+ }
1343
1348
default :
1344
1349
return err
1345
1350
}
Original file line number Diff line number Diff line change @@ -1583,3 +1583,32 @@ func TestRowsResultTag(t *testing.T) {
1583
1583
}
1584
1584
}
1585
1585
}
1586
+
1587
+ // TestQuickClose tests that closing a query early allows a subsequent query to work.
1588
+ func TestQuickClose (t * testing.T ) {
1589
+ db := openTestConn (t )
1590
+ defer db .Close ()
1591
+
1592
+ tx , err := db .Begin ()
1593
+ if err != nil {
1594
+ t .Fatal (err )
1595
+ }
1596
+ rows , err := tx .Query ("SELECT 1; SELECT 2;" )
1597
+ if err != nil {
1598
+ t .Fatal (err )
1599
+ }
1600
+ if err := rows .Close (); err != nil {
1601
+ t .Fatal (err )
1602
+ }
1603
+
1604
+ var id int
1605
+ if err := tx .QueryRow ("SELECT 3" ).Scan (& id ); err != nil {
1606
+ t .Fatal (err )
1607
+ }
1608
+ if id != 3 {
1609
+ t .Fatalf ("unexpected %d" , id )
1610
+ }
1611
+ if err := tx .Commit (); err != nil {
1612
+ t .Fatal (err )
1613
+ }
1614
+ }
You can’t perform that action at this time.
0 commit comments