From f70c1a93bc3a98a901eae322accbcc97beb0eacb Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Mon, 4 Jan 2021 15:10:16 -0500 Subject: [PATCH] import MySQL completion candidates from pygments * remove LEN and TOP, which are not MySQL reserved words * preserve completion candidates containing space, such as "ORDER BY" --- changelog.md | 1 + mycli/sqlcompleter.py | 38 +++++++++++--------------------------- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/changelog.md b/changelog.md index 6c54ef70..c6269a89 100644 --- a/changelog.md +++ b/changelog.md @@ -10,6 +10,7 @@ Features: * Allow customization of Pygments SQL syntax-highlighting styles. * Add a `\clip` special command to copy queries to the system clipboard. * Add a special command `\pipe_once` to pipe output to a subprocess. +* More complete and up-to-date set of MySQL reserved words for completions. Bug Fixes: diff --git a/mycli/sqlcompleter.py b/mycli/sqlcompleter.py index 20611be6..45378e75 100644 --- a/mycli/sqlcompleter.py +++ b/mycli/sqlcompleter.py @@ -1,8 +1,13 @@ +import itertools import logging from re import compile, escape from collections import Counter from prompt_toolkit.completion import Completer, Completion +from pygments.lexers._mysql_builtins import \ + MYSQL_DATATYPES, \ + MYSQL_FUNCTIONS, \ + MYSQL_KEYWORDS from .packages.completion_engine import suggest_type from .packages.parseutils import last_word @@ -13,33 +18,12 @@ class SQLCompleter(Completer): - keywords = ['ACCESS', 'ADD', 'ALL', 'ALTER TABLE', 'AND', 'ANY', 'AS', - 'ASC', 'AUTO_INCREMENT', 'BEFORE', 'BEGIN', 'BETWEEN', - 'BIGINT', 'BINARY', 'BY', 'CASE', 'CHANGE MASTER TO', 'CHAR', - 'CHARACTER SET', 'CHECK', 'COLLATE', 'COLUMN', 'COMMENT', - 'COMMIT', 'CONSTRAINT', 'CREATE', 'CURRENT', - 'CURRENT_TIMESTAMP', 'DATABASE', 'DATE', 'DECIMAL', 'DEFAULT', - 'DELETE FROM', 'DESC', 'DESCRIBE', 'DROP', - 'ELSE', 'END', 'ENGINE', 'ESCAPE', 'EXISTS', 'FILE', 'FLOAT', - 'FOR', 'FOREIGN KEY', 'FORMAT', 'FROM', 'FULL', 'FUNCTION', - 'GRANT', 'GROUP BY', 'HAVING', 'HOST', 'IDENTIFIED', 'IN', - 'INCREMENT', 'INDEX', 'INSERT INTO', 'INT', 'INTEGER', - 'INTERVAL', 'INTO', 'IS', 'JOIN', 'KEY', 'LEFT', 'LEVEL', - 'LIKE', 'LIMIT', 'LOCK', 'LOGS', 'LONG', 'MASTER', - 'MEDIUMINT', 'MODE', 'MODIFY', 'NOT', 'NULL', 'NUMBER', - 'OFFSET', 'ON', 'OPTION', 'OR', 'ORDER BY', 'OUTER', 'OWNER', - 'PASSWORD', 'PORT', 'PRIMARY', 'PRIVILEGES', 'PROCESSLIST', - 'PURGE', 'REFERENCES', 'REGEXP', 'RENAME', 'REPAIR', 'RESET', - 'REVOKE', 'RIGHT', 'ROLLBACK', 'ROW', 'ROWS', 'ROW_FORMAT', - 'SAVEPOINT', 'SELECT', 'SESSION', 'SET', 'SHARE', 'SHOW', - 'SLAVE', 'SMALLINT', 'SMALLINT', 'START', 'STOP', 'TABLE', - 'THEN', 'TINYINT', 'TO', 'TRANSACTION', 'TRIGGER', 'TRUNCATE', - 'UNION', 'UNIQUE', 'UNSIGNED', 'UPDATE', 'USE', 'USER', - 'USING', 'VALUES', 'VARCHAR', 'VIEW', 'WHEN', 'WHERE', 'WITH'] - - functions = ['AVG', 'CONCAT', 'COUNT', 'DISTINCT', 'FIRST', 'FORMAT', - 'FROM_UNIXTIME', 'LAST', 'LCASE', 'LEN', 'MAX', 'MID', - 'MIN', 'NOW', 'ROUND', 'SUM', 'TOP', 'UCASE', 'UNIX_TIMESTAMP'] + keywords = [x.upper() for x in itertools.chain.from_iterable([ + MYSQL_DATATYPES, MYSQL_KEYWORDS, + ['ALTER TABLE', 'CHANGE MASTER TO', 'CHARACTER SET', 'DELETE FROM', + 'FOREIGN KEY', 'GROUP BY', 'INSERT INTO', 'ORDER BY']])] + + functions = [x.upper() for x in MYSQL_FUNCTIONS] show_items = []