From e980a615eb736dac4ddd9fcb654093b1358f81ae Mon Sep 17 00:00:00 2001 From: wloosma2 Date: Fri, 3 Jun 2022 16:06:26 +0200 Subject: [PATCH] Strip last statement when it only contains comment --- sqlparse/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sqlparse/__init__.py b/sqlparse/__init__.py index 33be0eee..1f901405 100644 --- a/sqlparse/__init__.py +++ b/sqlparse/__init__.py @@ -67,4 +67,11 @@ def split(sql, encoding=None): :returns: A list of strings. """ stack = engine.FilterStack() - return [str(stmt).strip() for stmt in stack.run(sql, encoding)] + result = [str(stmt).strip() for stmt in stack.run(sql, encoding)] + + if len(result) > 0: + last_result = next(stack.run(result[-1], encoding)) + if last_result.tokens[-1].ttype[0] == 'Comment': + result = result[0:-1] + + return result