ec(ex) Produces the exception to raise an instance of on failure
Input:
ex The exception raised by psycopg3
+ fetcher(cur) Function to return the result(s) of the statement(s),
+ or None (the default) when the statement(s) produce
+ no results.
+ When SQL statements return results, the usual libpq
+ rules must be followed; all results must be retrieved
+ from the cursor before it can be reused and more statements
+ executed.
+ Input:
+ cur A psycopg3 cursor object.
+ result If a fetcher() is supplied, its return value is saved
+ in this attribute. Defaults to None.
'''
stmt = attrs.field()
args = attrs.field()
ec = attrs.field(default=None)
+ fetcher = attrs.field(default=None)
+ result = attrs.field(default=None)
def _explain_encoding_error(self, ex):
'''Return a SQLEncodingError instance
Side effects:
Does something in the db.
Can raise a psycopg3 error
+ Can call the "fetcher" attribute to set the "results" attribute
'''
try:
cur.execute(self.stmt, self.args)
raise ex
raise self.ec(ex)
+ if self.fetcher:
+ self.result = self.fetcher(cur)
+
@attrs.define(slots=False)
class LogSQLCommand(SQLCommand):
ec(ex) Produces the exception to raise an instance of on failure
Input:
ex The exception raised by psycopg3
+ fetcher(cur) Function to return the result(s) of the statement(s),
+ or None (the default) when the statement(s) produce
+ no results.
+ When SQL statements return results, the usual libpq
+ rules must be followed; all results must be retrieved
+ from the cursor before it can be reused and more statements
+ executed.
+ Input:
+ cur A psycopg3 cursor object.
+ result If a fetcher() is supplied, its return value is saved
+ in this attribute. Defaults to None.
log_success
Logs success
log_failure(ex)
Side effects:
Does something in the db.
Can raise a psycopg3 error
+ Can call the "fetcher" attribute to set the "results" attribute
'''
try:
super().execute(cur)
class SQLData(core.DBData):
'''
- SQL statements returning no data that execute in the db.
+ SQL statements that execute in the db.
Attributes:
stmts List of SQLCommand instances