Skip to content

Commit f70c1a9

Browse files
committed
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"
1 parent 4517f49 commit f70c1a9

File tree

2 files changed

+12
-27
lines changed

2 files changed

+12
-27
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Features:
1010
* Allow customization of Pygments SQL syntax-highlighting styles.
1111
* Add a `\clip` special command to copy queries to the system clipboard.
1212
* Add a special command `\pipe_once` to pipe output to a subprocess.
13+
* More complete and up-to-date set of MySQL reserved words for completions.
1314

1415

1516
Bug Fixes:

mycli/sqlcompleter.py

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
import itertools
12
import logging
23
from re import compile, escape
34
from collections import Counter
45

56
from prompt_toolkit.completion import Completer, Completion
7+
from pygments.lexers._mysql_builtins import \
8+
MYSQL_DATATYPES, \
9+
MYSQL_FUNCTIONS, \
10+
MYSQL_KEYWORDS
611

712
from .packages.completion_engine import suggest_type
813
from .packages.parseutils import last_word
@@ -13,33 +18,12 @@
1318

1419

1520
class SQLCompleter(Completer):
16-
keywords = ['ACCESS', 'ADD', 'ALL', 'ALTER TABLE', 'AND', 'ANY', 'AS',
17-
'ASC', 'AUTO_INCREMENT', 'BEFORE', 'BEGIN', 'BETWEEN',
18-
'BIGINT', 'BINARY', 'BY', 'CASE', 'CHANGE MASTER TO', 'CHAR',
19-
'CHARACTER SET', 'CHECK', 'COLLATE', 'COLUMN', 'COMMENT',
20-
'COMMIT', 'CONSTRAINT', 'CREATE', 'CURRENT',
21-
'CURRENT_TIMESTAMP', 'DATABASE', 'DATE', 'DECIMAL', 'DEFAULT',
22-
'DELETE FROM', 'DESC', 'DESCRIBE', 'DROP',
23-
'ELSE', 'END', 'ENGINE', 'ESCAPE', 'EXISTS', 'FILE', 'FLOAT',
24-
'FOR', 'FOREIGN KEY', 'FORMAT', 'FROM', 'FULL', 'FUNCTION',
25-
'GRANT', 'GROUP BY', 'HAVING', 'HOST', 'IDENTIFIED', 'IN',
26-
'INCREMENT', 'INDEX', 'INSERT INTO', 'INT', 'INTEGER',
27-
'INTERVAL', 'INTO', 'IS', 'JOIN', 'KEY', 'LEFT', 'LEVEL',
28-
'LIKE', 'LIMIT', 'LOCK', 'LOGS', 'LONG', 'MASTER',
29-
'MEDIUMINT', 'MODE', 'MODIFY', 'NOT', 'NULL', 'NUMBER',
30-
'OFFSET', 'ON', 'OPTION', 'OR', 'ORDER BY', 'OUTER', 'OWNER',
31-
'PASSWORD', 'PORT', 'PRIMARY', 'PRIVILEGES', 'PROCESSLIST',
32-
'PURGE', 'REFERENCES', 'REGEXP', 'RENAME', 'REPAIR', 'RESET',
33-
'REVOKE', 'RIGHT', 'ROLLBACK', 'ROW', 'ROWS', 'ROW_FORMAT',
34-
'SAVEPOINT', 'SELECT', 'SESSION', 'SET', 'SHARE', 'SHOW',
35-
'SLAVE', 'SMALLINT', 'SMALLINT', 'START', 'STOP', 'TABLE',
36-
'THEN', 'TINYINT', 'TO', 'TRANSACTION', 'TRIGGER', 'TRUNCATE',
37-
'UNION', 'UNIQUE', 'UNSIGNED', 'UPDATE', 'USE', 'USER',
38-
'USING', 'VALUES', 'VARCHAR', 'VIEW', 'WHEN', 'WHERE', 'WITH']
39-
40-
functions = ['AVG', 'CONCAT', 'COUNT', 'DISTINCT', 'FIRST', 'FORMAT',
41-
'FROM_UNIXTIME', 'LAST', 'LCASE', 'LEN', 'MAX', 'MID',
42-
'MIN', 'NOW', 'ROUND', 'SUM', 'TOP', 'UCASE', 'UNIX_TIMESTAMP']
21+
keywords = [x.upper() for x in itertools.chain.from_iterable([
22+
MYSQL_DATATYPES, MYSQL_KEYWORDS,
23+
['ALTER TABLE', 'CHANGE MASTER TO', 'CHARACTER SET', 'DELETE FROM',
24+
'FOREIGN KEY', 'GROUP BY', 'INSERT INTO', 'ORDER BY']])]
25+
26+
functions = [x.upper() for x in MYSQL_FUNCTIONS]
4327

4428
show_items = []
4529

0 commit comments

Comments
 (0)