1
1
import re
2
+ import logging
2
3
from collections import namedtuple
3
4
4
5
from .ParseUtils import extractTables
5
6
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 )
8
9
9
10
keywords_list = [
10
11
'SELECT' , 'UPDATE' , 'DELETE' , 'INSERT' , 'INTO' , 'FROM' ,
13
14
'LIMIT' , 'DISTINCT' , 'SET'
14
15
]
15
16
17
+ logger = logging .getLogger (__name__ )
18
+
16
19
17
20
# this function is generously used in completions code to get rid
18
21
# of all sorts of leading and trailing quotes in RDBMS identifiers
@@ -28,7 +31,7 @@ def _stripQuotesOnDemand(ident, doStrip=True):
28
31
29
32
30
33
def _startsWithQuote (ident ):
31
- # str.startswith can be matched against a tuple
34
+ # ident is matched against any of the possible ident quotes
32
35
quotes = ('`' , '"' )
33
36
return ident .startswith (quotes )
34
37
@@ -45,24 +48,23 @@ def _escapeDollarSign(ident):
45
48
46
49
47
50
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)
52
54
"""
53
55
__slots__ = ()
54
56
55
- # parent of identifier, e.g. "table" from "table.column"
56
57
@property
57
58
def parent (self ):
59
+ """Parent of identifier, e.g. "table" from "table.column" """
58
60
if self .ident .count ('.' ) == 0 :
59
61
return None
60
62
else :
61
63
return self .ident .partition ('.' )[0 ]
62
64
63
- # name of identifier, e.g. "column" from "table.column"
64
65
@property
65
66
def name (self ):
67
+ """Name of identifier, e.g. "column" from "table.column" """
66
68
return self .ident .split ('.' ).pop ()
67
69
68
70
# for functions - strip open bracket "(" and everything after that
@@ -281,7 +283,8 @@ def _getAutoCompleteListSmart(self, prefix, sql, sqlToCursor):
281
283
try :
282
284
identifiers = extractTables (sql )
283
285
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 )
285
288
286
289
# joinAlias is set only if user is editing join condition with alias. E.g.
287
290
# SELECT a.* from tbl_a a inner join tbl_b b ON |
@@ -292,7 +295,8 @@ def _getAutoCompleteListSmart(self, prefix, sql, sqlToCursor):
292
295
if joinCondMatch :
293
296
joinAlias = joinCondMatch .group (1 )
294
297
except Exception as e :
295
- print (e )
298
+ logger .debug ('Failed search of join condition, SQL:\n {}' .format (sqlToCursor ),
299
+ exc_info = True )
296
300
297
301
autocompleteList = []
298
302
inhibit = False
0 commit comments