Skip to content

Commit 5bbafc6

Browse files
committed
Fixed comments token overhwhelming issue
1 parent 799b74a commit 5bbafc6

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/models/sql.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,15 @@ def load_table_stats(self, cur, tables):
276276

277277
@staticmethod
278278
def get_comments(full_query):
279-
for token in sqlparse.parse(full_query)[0].tokens:
280-
if isinstance(token, Comment):
281-
return token.value
279+
lines = full_query.strip().split('\n')
280+
comment_lines = []
281+
for line in lines:
282+
stripped = line.strip()
283+
if stripped.startswith('--'):
284+
comment_lines.append(stripped)
285+
elif stripped:
286+
break
287+
return '\n'.join(comment_lines) if comment_lines else None
282288

283289
def get_query_hint_tips(self, full_query):
284290
tips = QueryTips()

0 commit comments

Comments
 (0)