Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions sqlparse/engine/statement_splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,13 @@ def _change_splitlevel(self, ttype, value):

def process(self, stream):
"""Process the stream"""
EOS_TTYPE = T.Whitespace, T.Comment.Single
EOS_TTYPE = T.Whitespace, T.Comment.Single, T.Comment.Multiline

# Run over all stream tokens
for ttype, value in stream:
# Yield token if we finished a statement and there's no whitespaces
# It will count newline token as a non whitespace. In this context
# whitespace ignores newlines.
# why don't multi line comments also count?
if self.consume_ws and ttype not in EOS_TTYPE:
yield sql.Statement(self.tokens)

Expand Down
18 changes: 18 additions & 0 deletions tests/test_split_trailing_comments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sqlparse


def test_split_keeps_trailing_block_comment_with_statement():
sql = "SELECT 1; /* trailing */\nSELECT 2;"

assert sqlparse.split(sql) == [
"SELECT 1; /* trailing */",
"SELECT 2;",
]


def test_split_trailing_comments_are_consistent():
block = "SELECT 1; /* trailing */\nSELECT 2;"
line = "SELECT 1; -- trailing\nSELECT 2;"

assert sqlparse.split(block)[0] == "SELECT 1; /* trailing */"
assert sqlparse.split(line)[0] == "SELECT 1; -- trailing"