Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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