f'The error is: {exp}')
+class CannotRollbackError(Error):
+ def __init__(self, exp):
+ super().__init__(
+ 'Cannot roll back the current transaction',
+ 'The transaction has failed and must roll back before '
+ 'the database can again be queried about relations and '
+ 'their columns',
+ f'The error from psycopg2 is: ({exp})')
+
+
class BadMapFileError(Error):
pass
quotecols = self.quote_columns()
column_quoter = self.get_column_quoter(quotecols)
+ in_trans = True
i_map = dict()
errors = []
for fileinfo in self.data.filedata():
map_description(fileinfo.filepath, fileinfo.relation),
fileinfo.filepath, fileinfo.relation)
errors.append(exp)
+ if in_trans:
+ # In order to continue to query the db after a db error
+ # the current transaction must be rolled back.
+ # Because we know we're going to abort, don't start a
+ # new transaction.
+ try:
+ self.cur.execute('ROLLBACK;')
+ except psycopg2.DatabaseError as exp:
+ err = ex.CannotRollbackError(exp)
+ err.color(map_description(fileinfo.filepath,
+ fileinfo.relation),
+ fileinfo.filepath, fileinfo.relation)
+ errors.append(err)
+ in_trans = False
finally:
# Limit number of open files, close the file handle until it
# is time to read the file