Skip to content

Commit

Permalink
Add more logging in Completions code
Browse files Browse the repository at this point in the history
  • Loading branch information
tkopets committed Feb 27, 2018
1 parent 9d17d19 commit 201356a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
9 changes: 4 additions & 5 deletions SQLTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ def startPlugin():
try:
settings = Settings(SETTINGS_FILENAME, default=SETTINGS_FILENAME_DEFAULT)
except Exception as e:
msg = __package__ + ": Failed to parse " + SQLTOOLS_SETTINGS_FILE + " file"
print(msg + "\nError: " + str(e))
msg = '{0}: Failed to parse {1} file'.format(__package__, SQLTOOLS_SETTINGS_FILE)
logging.error(msg + "\nError: " + str(e))
Window().status_message(msg)

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

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



def getConnections():
connectionsObj = {}

Expand Down
26 changes: 15 additions & 11 deletions SQLToolsAPI/Completion.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import re
import logging
from collections import namedtuple

from .ParseUtils import extractTables

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

keywords_list = [
'SELECT', 'UPDATE', 'DELETE', 'INSERT', 'INTO', 'FROM',
Expand All @@ -13,6 +14,8 @@
'LIMIT', 'DISTINCT', 'SET'
]

logger = logging.getLogger(__name__)


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


def _startsWithQuote(ident):
# str.startswith can be matched against a tuple
# ident is matched against any of the possible ident quotes
quotes = ('`', '"')
return ident.startswith(quotes)

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


class CompletionItem(namedtuple('CompletionItem', ['type', 'ident'])):
"""
Represents a potential or actual completion item.
* type - Type of item e.g. (Table, Function, Column)
* ident - identifier e.g. ("tablename.column", "database.table", "alias")
"""Represents a potential or actual completion item.
* type - type of item (Table, Function, Column)
* ident - identifier (table.column, schema.table, alias)
"""
__slots__ = ()

# parent of identifier, e.g. "table" from "table.column"
@property
def parent(self):
"""Parent of identifier, e.g. "table" from "table.column" """
if self.ident.count('.') == 0:
return None
else:
return self.ident.partition('.')[0]

# name of identifier, e.g. "column" from "table.column"
@property
def name(self):
"""Name of identifier, e.g. "column" from "table.column" """
return self.ident.split('.').pop()

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

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

autocompleteList = []
inhibit = False
Expand Down

0 comments on commit 201356a

Please sign in to comment.