MCPcopy
hub / github.com/andialbrecht/sqlparse / StatementSplitter

Class StatementSplitter

sqlparse/engine/statement_splitter.py:11–144  ·  view source on GitHub ↗

Filter that split stream at individual statements

Source from the content-addressed store, hash-verified

9
10
11class StatementSplitter:
12 """Filter that split stream at individual statements"""
13
14 def __init__(self):
15 self._reset()
16
17 def _reset(self):
18 """Set the filter attributes to its default values"""
19 self._in_declare = False
20 self._in_case = False
21 self._is_create = False
22 self._begin_depth = 0
23 self._seen_begin = False
24
25 self.consume_ws = False
26 self.tokens = []
27 self.level = 0
28
29 def _change_splitlevel(self, ttype, value):
30 """Get the new split level (increase, decrease or remain equal)"""
31
32 # parenthesis increase/decrease a level
33 if ttype is T.Punctuation and value == '(':
34 return 1
35 elif ttype is T.Punctuation and value == ')':
36 return -1
37 elif ttype not in T.Keyword: # if normal token return
38 return 0
39
40 # Everything after here is ttype = T.Keyword
41 # Also to note, once entered an If statement you are done and basically
42 # returning
43 unified = value.upper()
44
45 # three keywords begin with CREATE, but only one of them is DDL
46 # DDL Create though can contain more words such as "or replace"
47 if ttype is T.Keyword.DDL and unified.startswith('CREATE'):
48 self._is_create = True
49 return 0
50
51 # can have nested declare inside of being...
52 if unified == 'DECLARE' and self._is_create and self._begin_depth == 0:
53 self._in_declare = True
54 return 1
55
56 if unified == 'BEGIN':
57 self._begin_depth += 1
58 self._seen_begin = True
59 if self._is_create:
60 # FIXME(andi): This makes no sense. ## this comment neither
61 return 1
62 return 0
63
64 # Issue826: If we see a transaction keyword after BEGIN,
65 # it's a transaction statement, not a block.
66 if self._seen_begin and \
67 (ttype is T.Keyword or ttype is T.Name) and \
68 unified in ('TRANSACTION', 'WORK', 'TRAN',

Callers 1

runMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…