Skip to content

Commit be2b75c

Browse files
authored
Merge pull request #1004 from roelvandergoot/roel/empty-query
Roel/empty-query
2 parents fbd2a9a + 999f18f commit be2b75c

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

conn.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,11 @@ func (cn *conn) simpleQuery(q string) (res *rows, err error) {
663663
// Set the result and tag to the last command complete if there wasn't a
664664
// query already run. Although queries usually return from here and cede
665665
// control to Next, a query with zero results does not.
666-
if t == 'C' && res.colNames == nil {
666+
if t == 'C' {
667667
res.result, res.tag = cn.parseComplete(r.string())
668+
if res.colNames != nil {
669+
return
670+
}
668671
}
669672
res.done = true
670673
case 'Z':

conn_test.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,10 +1640,6 @@ func TestRowsResultTag(t *testing.T) {
16401640
{
16411641
query: "CREATE TEMP TABLE t (a int); DROP TABLE t; SELECT 1",
16421642
},
1643-
// Verify that an no-results query doesn't set the tag.
1644-
{
1645-
query: "CREATE TEMP TABLE t (a int); SELECT 1 WHERE FALSE; DROP TABLE t;",
1646-
},
16471643
}
16481644

16491645
// If this is the only test run, this will correct the connection string.
@@ -1748,6 +1744,36 @@ func TestMultipleResult(t *testing.T) {
17481744
}
17491745
}
17501746

1747+
func TestMultipleEmptyResult(t *testing.T) {
1748+
db := openTestConn(t)
1749+
defer db.Close()
1750+
1751+
rows, err := db.Query("select 1 where false; select 2")
1752+
if err != nil {
1753+
t.Fatal(err)
1754+
}
1755+
defer rows.Close()
1756+
1757+
for rows.Next() {
1758+
t.Fatal("unexpected row")
1759+
}
1760+
if !rows.NextResultSet() {
1761+
t.Fatal("expected more result sets", rows.Err())
1762+
}
1763+
for rows.Next() {
1764+
var i int
1765+
if err := rows.Scan(&i); err != nil {
1766+
t.Fatal(err)
1767+
}
1768+
if i != 2 {
1769+
t.Fatalf("expected 2, got %d", i)
1770+
}
1771+
}
1772+
if rows.NextResultSet() {
1773+
t.Fatal("unexpected result set")
1774+
}
1775+
}
1776+
17511777
func TestCopyInStmtAffectedRows(t *testing.T) {
17521778
db := openTestConn(t)
17531779
defer db.Close()

0 commit comments

Comments
 (0)