11import re
2+ import logging
23from collections import namedtuple
34
45from .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
910keywords_list = [
1011 'SELECT' , 'UPDATE' , 'DELETE' , 'INSERT' , 'INTO' , 'FROM' ,
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
3033def _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
4750class 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