-
Notifications
You must be signed in to change notification settings - Fork 84
Description
When executing SQL queries that begin with comments(both block(/* comment */) and line comments(--)),
the query execution handler misclassifies them as non-query statements (EXEC) instead of query statements (SELECT).
This results in a response of "Query OK, 0 row affected" rather than returning the actual result set.
To Reproduce
Steps to reproduce the behavior:
Execute a SELECT query with a leading comment:
/* With Comment */
SELECT * FROM users;And Without the comment:
SELECT * FROM users;Tried with local/remote MySQL and PostgreSQL servers.
Expected behavior
Queries with leading comments should be correctly identified as SELECT statements and return the result set, just like queries without comments.
Versions (please complete the following information):
- OS Version: WSL2 Ubuntu 24.04
- sqls Version: 0.2.28
Additional context
The issue seems to stem from the way the SQL command is parsed in the executeCommand function.
Which uses QueryExecType function to determine the type of SQL command.
Current Implementation checks for first word after basic whitespace trimming, which fails when comments are present at the start of the query.
Maybe a function like stripLeadingComments could be implemented to remove comments before type detection?