Skip to content

Commit

Permalink
Merge pull request #1004 from roelvandergoot/roel/empty-query
Browse files Browse the repository at this point in the history
Roel/empty-query
  • Loading branch information
maddyblue authored Nov 23, 2020
2 parents fbd2a9a + 999f18f commit be2b75c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
5 changes: 4 additions & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,11 @@ func (cn *conn) simpleQuery(q string) (res *rows, err error) {
// Set the result and tag to the last command complete if there wasn't a
// query already run. Although queries usually return from here and cede
// control to Next, a query with zero results does not.
if t == 'C' && res.colNames == nil {
if t == 'C' {
res.result, res.tag = cn.parseComplete(r.string())
if res.colNames != nil {
return
}
}
res.done = true
case 'Z':
Expand Down
34 changes: 30 additions & 4 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1640,10 +1640,6 @@ func TestRowsResultTag(t *testing.T) {
{
query: "CREATE TEMP TABLE t (a int); DROP TABLE t; SELECT 1",
},
// Verify that an no-results query doesn't set the tag.
{
query: "CREATE TEMP TABLE t (a int); SELECT 1 WHERE FALSE; DROP TABLE t;",
},
}

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

func TestMultipleEmptyResult(t *testing.T) {
db := openTestConn(t)
defer db.Close()

rows, err := db.Query("select 1 where false; select 2")
if err != nil {
t.Fatal(err)
}
defer rows.Close()

for rows.Next() {
t.Fatal("unexpected row")
}
if !rows.NextResultSet() {
t.Fatal("expected more result sets", rows.Err())
}
for rows.Next() {
var i int
if err := rows.Scan(&i); err != nil {
t.Fatal(err)
}
if i != 2 {
t.Fatalf("expected 2, got %d", i)
}
}
if rows.NextResultSet() {
t.Fatal("unexpected result set")
}
}

func TestCopyInStmtAffectedRows(t *testing.T) {
db := openTestConn(t)
defer db.Close()
Expand Down

0 comments on commit be2b75c

Please sign in to comment.