Exception message for multiple statements in single query#83
Conversation
exception message for multiple queries
StpMax
left a comment
There was a problem hiding this comment.
fail in new version:
sql = 'select "--x"'
ast = parse_sql(sql)
sql = "select '--x'"
ast = parse_sql(sql)|
updated code, the trialed semicolon is omitted in different way (as a token after lexer parsed input string) |
|
|
||
| # remove ending semicolon and spaces | ||
| sql = re.sub(r'[\s;]+$', '', sql) | ||
| def semicolon_checker(generator): |
There was a problem hiding this comment.
Duplicate Code:
This function semicolon_checker duplicates existing code.
📍 Original Location:
mindsdb_sql_parser/__init__.py:169-187 (specifically line 175)
Function: parse_sql (semicolon removal logic)
💡 Recommendation:
Keep the existing regex approach as it's more concise (1 line vs 10 lines), more performant (no token iteration overhead), and easier to maintain. Unless there's a specific requirement for token-level semicolon handling (e.g., distinguishing between statement-separating semicolons vs trailing semicolons), the simpler regex approach should be preferred.
Consider importing and reusing the existing function instead of duplicating the logic.
|
|
||
| assert "Only a single sql statement is expected" in str(excinfo.value) | ||
|
|
||
| def test_trailing_semicolon(self): |
There was a problem hiding this comment.
Duplicate Code:
This function test_trailing_semicolon duplicates existing code.
📍 Original Location:
tests/test_base_sql/test_base_sql.py:8-13
Function: test_ending
💡 Recommendation:
Consolidate into a single comprehensive test. Either enhance the existing test_ending to also validate AST structure, or replace it with the PR's test_trailing_semicolon which has a clearer name. Do NOT keep both tests as they provide redundant coverage.
Consider importing and reusing the existing function instead of duplicating the logic.
If string contain several statement it returns message about it:
response will be
Also queries with leading comments used to raise before, fixed in this PR
Fixes: https://linear.app/mindsdb/issue/FQE-2076/agents-agent-streaming-failed-problem-with-final-query-syntax-error