Skip to content

Commit 573cf55

Browse files
committed
Refresh completions when a DDL statement starts with a comment
Fixes #2438
1 parent 679a28c commit 573cf55

4 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎changelog.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Upcoming (TBD)
22
==============
33

4+
Bug Fixes
5+
--------
6+
* Refresh completions after `CREATE`, `ALTER`, `DROP` or `RENAME` statements that start with a SQL comment.
7+
8+
49
Internal
510
--------
611
* Improve test coverage for `batch_utils.py`.

‎mycli/AUTHORS.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ Contributors:
126126
* Karim Masmoudi
127127
* Jay Hemnani
128128
* Alpenj
129+
* goranai
129130

130131

131132
Created by:

‎mycli/packages/utils/sql_utils.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,9 @@ def need_completion_refresh(queries: str) -> bool:
430430
for query in sqlparse.split(queries):
431431
try:
432432
first_token = query.split()[0]
433+
if first_token.startswith(("/*", "--", "#")):
434+
# skip leading comments, such as "/* note */ create table ..."
435+
first_token = sqlparse.format(query, strip_comments=True).split()[0]
433436
if first_token.lower() in (
434437
"alter",
435438
"create",

‎mycli_test/pytests/test_sql_utils.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,12 @@ def test_is_dropping_database_skips_statements_without_enough_keywords():
533533
('connect foo localhost root', True),
534534
('drop table foo;', True),
535535
('rename table foo to bar;', True),
536+
('/* note */ create table foo (id int);', True),
537+
('-- note\nalter table foo add column bar int;', True),
538+
('# note\ndrop table foo;', True),
539+
('select 1; /* note */ rename table foo to bar;', True),
540+
('/* note */ select 1;', False),
541+
('-- create table foo (id int)', False),
536542
],
537543
)
538544
def test_need_completion_refresh(queries, expected):

0 commit comments

Comments
 (0)