Skip to content

Commit

Permalink
Don't return row descriptions when executing SET queries
Browse files Browse the repository at this point in the history
  • Loading branch information
exAspArk committed Jan 3, 2025
1 parent c0e8d69 commit 8d7c4eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
12 changes: 11 additions & 1 deletion src/query_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,12 @@ func (queryHandler *QueryHandler) rowsToDescriptionMessages(rows *sql.Rows, quer
}

var messages []pgproto3.Message
messages = append(messages, queryHandler.generateRowDescription(cols))

rowDescription := queryHandler.generateRowDescription(cols)
if len(rowDescription.Fields) > 0 {
messages = append(messages, rowDescription)
}

return messages, nil
}

Expand Down Expand Up @@ -383,6 +388,11 @@ func (queryHandler *QueryHandler) generateRowDescription(cols []*sql.ColumnType)
description := pgproto3.RowDescription{Fields: []pgproto3.FieldDescription{}}

for _, col := range cols {
if col.Name() == "Success" && col.ScanType().String() == "bool" && len(cols) == 1 {
// Skip the "Success" DuckDB column returned from SET ... commands
continue
}

description.Fields = append(description.Fields, pgproto3.FieldDescription{
Name: []byte(col.Name()),
TableOID: 0,
Expand Down
17 changes: 11 additions & 6 deletions src/query_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,6 @@ func TestHandleQuery(t *testing.T) {
"description": {"table_catalog", "table_schema", "table"},
"values": {"memory", "public", "test_table"},
},
// SET
"SET client_encoding TO 'UTF8'": {
"description": {"Success"},
"values": {},
},
// Empty query
"-- ping": {
"description": {"1"},
Expand Down Expand Up @@ -658,6 +653,17 @@ func TestHandleQuery(t *testing.T) {
t.Errorf("Expected the error to be '"+expectedErrorMessage+"', got %v", err.Error())
}
})

t.Run("Returns a result without a row description for SET queries", func(t *testing.T) {
queryHandler := initQueryHandler()

messages, err := queryHandler.HandleQuery("SET client_encoding TO 'UTF8'")

testNoError(t, err)
testMessageTypes(t, messages, []pgproto3.Message{
&pgproto3.CommandComplete{},
})
})
}

func TestHandleParseQuery(t *testing.T) {
Expand Down Expand Up @@ -796,7 +802,6 @@ SET standard_conforming_strings = on;`

testNoError(t, err)
testMessageTypes(t, messages, []pgproto3.Message{
&pgproto3.RowDescription{},
&pgproto3.CommandComplete{},
})
})
Expand Down

0 comments on commit 8d7c4eb

Please sign in to comment.