TAB,
)
+from pgwui_core import exceptions as core_ex
from pgwui_upload_core import exceptions as upload_ex
self.write_double_key(response)
return response
+ def _execute(self, stmt, tupl):
+ '''Execute a statement and express encoding errors
+ '''
+ try:
+ self.cur.execute(stmt, tupl)
+ except UnicodeEncodeError as err:
+ raise core_ex.SQLEncodingError(
+ err,
+ ("Data cannot be represented in the database"
+ " connection's client-side character encoding"),
+ (f'The SQL statement is ({stmt}) and the data supplied'
+ f' is ({tupl})'))
+ except psycopg.errors.UntranslatableCharacter as err:
+ raise core_ex.SQLEncodingError(
+ err,
+ ("Data cannot be represented in the"
+ " character encoding of the database"),
+ (f'The SQL statement is ({stmt}) and the data supplied'
+ f' is ({tupl})'))
+
def resolve_normalized_table(self, qualified_table):
'''Return (schema, table) tuple of table name, or raise exception
if not resolvable.
'''
try:
- self.cur.execute(
+ self._execute(
('SELECT nspname, relname'
' FROM pg_class'
' JOIN pg_namespace'
# tables.is_insertable_into does not reflect whether
# there's an insert trigger on the table.
" OR tables.table_type = 'VIEW')")
- self.cur.execute(sql, (table, schema))
+ self._execute(sql, (table, schema))
return self.cur.fetchone() is not None
def quote_columns(self, settings):
bad_cols = []
for col_name in data.headers.tuples:
# Check that colum name exists
- self.cur.execute(column_sql, (table, schema, col_name))
+ self._execute(column_sql, (table, schema, col_name))
if self.cur.fetchone() is None:
bad_cols.append(col_name)
else: