Skip to content

Commit dcc8175

Browse files
committed
Python: Automatically assign error to statement if there is only one statement.
1 parent c5aac78 commit dcc8175

File tree

1 file changed

+12
-4
lines changed
  • cratedb_sqlparse_py/cratedb_sqlparse

1 file changed

+12
-4
lines changed

cratedb_sqlparse_py/cratedb_sqlparse/parser.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,16 @@ def sqlparse(query: str, raise_exception: bool = False) -> List[Statement]:
204204
)
205205

206206
statements = []
207+
207208
for statement_context in statements_context:
208209
stmt = Statement(statement_context)
209-
find_suitable_error(stmt, error_listener.errors)
210+
if len(statements_context) == 1 and error_listener.errors:
211+
# There is only one statement parsed, no need to get fancy to match.
212+
stmt.exception = error_listener.errors.pop()
213+
214+
else:
215+
find_suitable_error(stmt, error_listener.errors)
216+
210217
statements.append(stmt)
211218

212219
else:
@@ -229,9 +236,10 @@ def sqlparse(query: str, raise_exception: bool = False) -> List[Statement]:
229236
break
230237

231238
if len(error_listener.errors) > 1:
232-
logging.error(
233-
"Could not match errors to queries, too much ambiguity, open an issue with this " "error and the query."
234-
)
239+
# We might have too much ambiguity to match errors, but also one statement can
240+
# generate several exceptions, and we only support one per statement so this could be
241+
# triggered and not be an actual error.
242+
pass
235243

236244
# We extract the metadata and enrich every Statement's `metadata`.
237245
stmt_enricher = AstBuilder()

0 commit comments

Comments
 (0)