You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
full_statement=re.subn(self.where_clean_up, '', ' '.join(elements))[0] # removes messy contents of WHERE statements? Note sure why this is needed or why it is run on the whole SQL statement
63
67
full_statement=re.subn(self.whitespace_regex, '', full_statement)[0] # flattens pretty print SQL to a single line by removing whitespace
64
68
iffull_statement:
@@ -100,7 +104,7 @@ def __str__(self):
100
104
# This section could be better implemented using a call to sqlpars
101
105
# https://github.com/andialbrecht/sqlparse
102
106
# But doing it this way keeps the dependancies low, which is important
103
-
query=self.statement# This is the single line query gotten from the statement function
107
+
query=self.statement# This is the single line query gotten from the statement function
104
108
query=re.subn(self.fmt, '\n ', query)[0]
105
109
query=re.subn(self.fmt_after, '\n ', query)[0]
106
110
query=re.subn(self.fmt_join, '\n ', query)[0]
@@ -146,8 +150,6 @@ def replace_and(match):
146
150
147
151
148
152
149
-
150
-
151
153
classQueryComponent(object):
152
154
#This is the base class that everything else will be added to..
153
155
# this is where the magic of += is handled, which makes it easy
@@ -179,6 +181,8 @@ def clear(self):
179
181
self.components=list()
180
182
181
183
def__call__(self):
184
+
# This is the function that converts the list of items in the querycomponent into a long string
185
+
# it is always prefixed by the header..
182
186
ifself.components:
183
187
returnself.header+self.sep.join(self.components)
184
188
return''
@@ -197,6 +201,30 @@ def __str__(self):
197
201
198
202
__repr__=__str__
199
203
204
+
classCreateInsertComponent(QueryComponent):
205
+
# Implements the very first part of a CREATE TABLE db.table AS or INSERT INTO db.table
206
+
# depending on whether the is_first_data_add setting has been set
207
+
208
+
209
+
is_first_data_add=True
210
+
211
+
def__iadd__(self, item):
212
+
#we only have the one item..
213
+
self.components=list() # overwrites whatever was there
214
+
ifself.is_first_data_add:
215
+
#Then this is a CREATE TABLE AS clause
216
+
self.header='CREATE TABLE '+item+" AS \n"
217
+
else:
218
+
self.header='INSERT INTO '+item+" \n"
219
+
returnself
220
+
221
+
def__init__(self):
222
+
self.header=''# by default, this is not used.
223
+
self.components=list()
224
+
225
+
def__call__(self):
226
+
returnself.header
227
+
200
228
201
229
classSelectComponent(QueryComponent):
202
230
# This models the SELECT component, and sends great energy ensuring that the "DISTINCT" and "TOP" syntax are supported
0 commit comments