return self
-class ExecuteSQL(pgwui_core.core.DataLineProcessor):
- '''
- Attributes:
- request A pyramid request instance
- uf A GCUploadForm instance
- session A pyramid session instance
- ue
- uh UploadHandler instance
- cur
- '''
- def eat(self, udl):
- '''
- Execute a series of SQL statements.
- The result goes into the upload handler (uh.sql_results),
- interleaving errors with output.
-
- udl An UploadDataLine instance, contains all the sql statements
- '''
- cur = self.cur
- cur.execute(self.uf.data)
-
- sql_results = self.uh.sql_results
- nextset = True
- while nextset is True:
- first = True
- while (row := cur.fetchone()) is not None:
- if first:
- sql_results.append(SQLResult().build_header_row(cur))
- first = False
- sql_results.append(SQLResult().build_data_row(row))
- sql_results.append(SQLResult().build_statusmessage_row(cur))
- sql_results.append(SQLResult().build_rowcount_row(cur))
- nextset = cur.nextset()
-
-
@attrs.define(slots=False)
class SQLHandler(pgwui_core.core.SessionDBHandler):
'''
+ Deliver no data to the upload engine, instead do all the SQL
+ execution here, in the cleanup method.
+
Attributes:
request A pyramid request instance
uf A SQLForm instance
'''
return SQLForm().build(self, ip=SQLInitialPost(), fc=SQLWTForm)
- def deliver_sql(self):
- return self.uf['sql']
-
def get_data(self):
- '''Return thunks that delivers data, but we only need one thunk
- because processing is done by the DataLineProcessor (SQLExecute
+ '''Return no data. Data is in lines and we have no lines.
'''
- return (self.deliver_sql(),)
+ self.data = tuple()
def write(self, result, errors):
'''
return response
+ def cleanup(self):
+ '''
+ Execute a series of SQL statements.
+ The result goes into the upload handler (uh.sql_results),
+ interleaving errors with output.
+ '''
+ cur = self.cur
+ cur.execute(self.uf['sql'])
+
+ sql_results = self.sql_results
+ nextset = True
+ while nextset is True:
+ first = True
+ while (row := cur.fetchone()) is not None:
+ if first:
+ sql_results.append(SQLResult().build_header_row(cur))
+ first = False
+ sql_results.append(SQLResult().build_data_row(row))
+ sql_results.append(SQLResult().build_statusmessage_row(cur))
+ sql_results.append(SQLResult().build_rowcount_row(cur))
+ nextset = cur.nextset()
+
def factory(self, ue):
'''Make a db loader function from an UploadEngine.
Assigns: self.ue, self.cur
And, lots of changes to the db
'''
-
- super().factory(ue)
-
- return ExecuteSQL(ue, self)
+ self.ue = ue
+ self.cur = ue.cur
+ return pgwui_core.core.DataLineProcessor(ue, self)
@view_config(route_name='pgwui_sql',