Skip to content

Commit

Permalink
Fix processing empty or comment-only queries
Browse files Browse the repository at this point in the history
  • Loading branch information
exAspArk committed Nov 22, 2024
1 parent 4b55496 commit a96c6db
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

VERSION="0.13.1"
VERSION="0.13.2"

# Detect OS and architecture
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
Expand Down
2 changes: 1 addition & 1 deletion src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"
)

const VERSION = "0.13.1"
const VERSION = "0.13.2"

func main() {
flag.Parse()
Expand Down
4 changes: 3 additions & 1 deletion src/query_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ func (queryHandler *QueryHandler) remapQuery(query string) (string, error) {
var statementNode *pgQuery.Node
if len(queryTree.Stmts) > 0 {
statementNode = queryTree.Stmts[0].Stmt
} else {
return FALLBACK_SQL_QUERY, nil
}

if statementNode != nil && statementNode.GetSelectStmt() != nil {
Expand All @@ -373,7 +375,7 @@ func (queryHandler *QueryHandler) remapQuery(query string) (string, error) {
return FALLBACK_SQL_QUERY, nil
}

LogDebug(queryHandler.config, queryTree)
LogDebug(queryHandler.config, "Query tree:", queryTree)
return "", errors.New("Unsupported query type")
}

Expand Down
5 changes: 5 additions & 0 deletions src/query_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ func TestHandleQuery(t *testing.T) {
"description": {"Success"},
"values": {},
},
// Empty query
"-- ping": {
"description": {"1"},
"values": {"1"},
},
// DISCARD
"DISCARD ALL": {
"description": {"1"},
Expand Down

0 comments on commit a96c6db

Please sign in to comment.