Skip to content
This repository was archived by the owner on Mar 12, 2020. It is now read-only.

Commit 201356a

Browse files
committed
Add more logging in Completions code
1 parent 9d17d19 commit 201356a

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

SQLTools.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ def startPlugin():
7373
try:
7474
settings = Settings(SETTINGS_FILENAME, default=SETTINGS_FILENAME_DEFAULT)
7575
except Exception as e:
76-
msg = __package__ + ": Failed to parse " + SQLTOOLS_SETTINGS_FILE + " file"
77-
print(msg + "\nError: " + str(e))
76+
msg = '{0}: Failed to parse {1} file'.format(__package__, SQLTOOLS_SETTINGS_FILE)
77+
logging.error(msg + "\nError: " + str(e))
7878
Window().status_message(msg)
7979

8080
try:
8181
connections = Settings(CONNECTIONS_FILENAME, default=CONNECTIONS_FILENAME_DEFAULT)
8282
except Exception as e:
83-
msg = __package__ + ": Failed to parse " + SQLTOOLS_CONNECTIONS_FILE + " file"
84-
print(msg + "\nError: " + str(e))
83+
msg = '{0}: Failed to parse {1} file'.format(__package__, SQLTOOLS_CONNECTIONS_FILE)
84+
logging.error(msg + "\nError: " + str(e))
8585
Window().status_message(msg)
8686

8787
queries = Storage(QUERIES_FILENAME, default=QUERIES_FILENAME_DEFAULT)
@@ -99,7 +99,6 @@ def startPlugin():
9999
logger.info('version %s', __version__)
100100

101101

102-
103102
def getConnections():
104103
connectionsObj = {}
105104

SQLToolsAPI/Completion.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import re
2+
import logging
23
from collections import namedtuple
34

45
from .ParseUtils import extractTables
56

6-
_join_cond_regex_pattern = r"\s+?JOIN\s+?[\w\.`\"]+\s+?(?:AS\s+)?(\w+)\s+?ON\s+?(?:[\w\.]+)?$"
7-
JOIN_COND_REGEX = re.compile(_join_cond_regex_pattern, re.IGNORECASE)
7+
JOIN_COND_PATTERN = r"\s+?JOIN\s+?[\w\.`\"]+\s+?(?:AS\s+)?(\w+)\s+?ON\s+?(?:[\w\.]+)?$"
8+
JOIN_COND_REGEX = re.compile(JOIN_COND_PATTERN, re.IGNORECASE)
89

910
keywords_list = [
1011
'SELECT', 'UPDATE', 'DELETE', 'INSERT', 'INTO', 'FROM',
@@ -13,6 +14,8 @@
1314
'LIMIT', 'DISTINCT', 'SET'
1415
]
1516

17+
logger = logging.getLogger(__name__)
18+
1619

1720
# this function is generously used in completions code to get rid
1821
# of all sorts of leading and trailing quotes in RDBMS identifiers
@@ -28,7 +31,7 @@ def _stripQuotesOnDemand(ident, doStrip=True):
2831

2932

3033
def _startsWithQuote(ident):
31-
# str.startswith can be matched against a tuple
34+
# ident is matched against any of the possible ident quotes
3235
quotes = ('`', '"')
3336
return ident.startswith(quotes)
3437

@@ -45,24 +48,23 @@ def _escapeDollarSign(ident):
4548

4649

4750
class CompletionItem(namedtuple('CompletionItem', ['type', 'ident'])):
48-
"""
49-
Represents a potential or actual completion item.
50-
* type - Type of item e.g. (Table, Function, Column)
51-
* ident - identifier e.g. ("tablename.column", "database.table", "alias")
51+
"""Represents a potential or actual completion item.
52+
* type - type of item (Table, Function, Column)
53+
* ident - identifier (table.column, schema.table, alias)
5254
"""
5355
__slots__ = ()
5456

55-
# parent of identifier, e.g. "table" from "table.column"
5657
@property
5758
def parent(self):
59+
"""Parent of identifier, e.g. "table" from "table.column" """
5860
if self.ident.count('.') == 0:
5961
return None
6062
else:
6163
return self.ident.partition('.')[0]
6264

63-
# name of identifier, e.g. "column" from "table.column"
6465
@property
6566
def name(self):
67+
"""Name of identifier, e.g. "column" from "table.column" """
6668
return self.ident.split('.').pop()
6769

6870
# for functions - strip open bracket "(" and everything after that
@@ -281,7 +283,8 @@ def _getAutoCompleteListSmart(self, prefix, sql, sqlToCursor):
281283
try:
282284
identifiers = extractTables(sql)
283285
except Exception as e:
284-
print(e)
286+
logger.debug('Failed to extact the list identifiers from SQL:\n {}'.format(sql),
287+
exc_info=True)
285288

286289
# joinAlias is set only if user is editing join condition with alias. E.g.
287290
# SELECT a.* from tbl_a a inner join tbl_b b ON |
@@ -292,7 +295,8 @@ def _getAutoCompleteListSmart(self, prefix, sql, sqlToCursor):
292295
if joinCondMatch:
293296
joinAlias = joinCondMatch.group(1)
294297
except Exception as e:
295-
print(e)
298+
logger.debug('Failed search of join condition, SQL:\n {}'.format(sqlToCursor),
299+
exc_info=True)
296300

297301
autocompleteList = []
298302
inhibit = False

0 commit comments

Comments
 (0)