You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Completions are not refreshed when a CREATE, ALTER, DROP or RENAME starts with a comment #2438
mycli refreshes its completions after CREATE, ALTER, DROP and RENAME. It does not do that when the statement starts with a SQL comment. For example:
/* add audit table */ create table audit (id int);
-- drop the old onedroptable audit_old;
select1; /* rename */ rename table a to b;
The statements run fine on the server. But the new table does not show up in completions, and the dropped table is still offered, until the next refresh (\# or another DDL without a comment).
Why
need_completion_refresh() in mycli/packages/utils/sql_utils.py looks at query.split()[0]. When the statement starts with a comment, that first word is /*, -- or #, so it never matches create, alter, drop or rename.
sqlparse.split() also keeps a comment that follows ; with the next statement. So select 1; /* x */ drop table t hits the same problem.
Other helpers in the same file already skip comments. query_starts_with() uses sqlparse.format(query, strip_comments=True).
frommycli.packages.utils.sql_utilsimportneed_completion_refreshneed_completion_refresh("create table t (a int)") # Trueneed_completion_refresh("/* c */ create table t (a int)") # Falseneed_completion_refresh("-- c\ncreate table t (a int)") # Falseneed_completion_refresh("# c\ndrop table t") # Falseneed_completion_refresh("select 1; /* c */ drop table t") # False
I also ran _one_iteration() in repl.py with the test harness from test_main_modes_repl.py, the real need_completion_refresh() and a fake executor that returns success. refresh_completions() is called for create table t2 (a int) and is not called for the four commented versions.
I did not run this against a live MySQL server.
Related, not fixed here
/* c */ use foo has a bigger problem. It does not match the use special command, so it goes to the server as plain SQL. The server switches the database, but sql_execute.dbname keeps the old name. A completion refresh alone cannot fix that, so I left it out.
Activity