-
Notifications
You must be signed in to change notification settings - Fork 6
Exception message for multiple statements in single query #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| from textwrap import dedent | ||
|
|
||
| import pytest | ||
|
|
||
| from mindsdb_sql_parser import parse_sql | ||
| from mindsdb_sql_parser.exceptions import ParsingException | ||
|
|
||
| from mindsdb_sql_parser.ast import * | ||
|
|
||
|
|
@@ -86,3 +90,45 @@ def test_quotes_identifier(self): | |
|
|
||
| assert str(ast).lower() == str(expected_ast).lower() | ||
| assert ast.to_tree() == expected_ast.to_tree() | ||
|
|
||
| def test_multy_statement(self): | ||
| sql = """ | ||
| select 1; | ||
| select 2 | ||
| """ | ||
|
|
||
| with pytest.raises(ParsingException) as excinfo: | ||
| parse_sql(sql) | ||
|
|
||
| assert "Only a single sql statement is expected" in str(excinfo.value) | ||
|
|
||
| def test_trailing_semicolon(self): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate Code: This function 📍 Original Location: Function: 💡 Recommendation: Consider importing and reusing the existing function instead of duplicating the logic. |
||
| query = parse_sql("select 1;") | ||
| assert query == Select(targets=[Constant(1)]) | ||
|
|
||
| def test_comment_after_semicolon(self): | ||
| sql = """ | ||
| select 1; -- my query | ||
| """ | ||
|
|
||
| query = parse_sql(sql) | ||
| assert query == Select(targets=[Constant(1)]) | ||
|
|
||
| def test_comment_symbols_in_string(self): | ||
| expected_query = Select(targets=[Constant('--x')]) | ||
|
|
||
| query = parse_sql("select '--x'") | ||
| assert query == expected_query | ||
|
|
||
| query = parse_sql('select "--x"') | ||
| assert query == expected_query | ||
|
|
||
| # multiline | ||
| expected_query = Select(targets=[Constant('/* x */')]) | ||
|
|
||
| query = parse_sql("select '/* x */'") | ||
| assert query == expected_query | ||
|
|
||
| query = parse_sql('select "/* x */"') | ||
| assert query == expected_query | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate Code:⚠️ Duplicate Code Detected (Similarity: 85%)
This function
semicolon_checkerduplicates existing code.📍 Original Location:
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.