From: Karl O. Pinc Date: Mon, 18 Jan 2021 20:51:20 +0000 (-0600) Subject: Class to test for too few columns in param substition X-Git-Url: https://papio.biology.duke.edu/gitweb/?a=commitdiff_plain;h=f0277a802a9b7a6fcb944e78ab90e32578bebae7;p=pgwui_core Class to test for too few columns in param substition --- diff --git a/src/pgwui_core/core.py b/src/pgwui_core/core.py index 6779c76..32c9510 100644 --- a/src/pgwui_core/core.py +++ b/src/pgwui_core/core.py @@ -980,6 +980,22 @@ class UploadData(DBData): return seq + ['' for i in range(len(seq) + 1, self.cols)] +@attr.s +class ParameterExecutor(): + '''Execute a parameterized pscopg2 statement + ''' + def param_execute(self, insert_stmt, udl): + try: + self.cur.execute(insert_stmt, udl.tuples) + except IndexError as exp: + raise core_ex.TooFewColsError( + udl.lineno, + 'Line has too few columns', + 'Fewer columns than column headings', + f'The IndexError from psycopg2 is: ({exp})', + data=udl.raw) + + class DataLineProcessor(object): ''' A processor supplied uploaded lines (UploadDataLine instances) diff --git a/src/pgwui_core/exceptions.py b/src/pgwui_core/exceptions.py index 22cb2a6..25b564b 100644 --- a/src/pgwui_core/exceptions.py +++ b/src/pgwui_core/exceptions.py @@ -238,3 +238,8 @@ class DataLineError(UploadError): class TooManyColsError(DataLineError): def __init__(self, lineno, e, descr='', detail='', data=''): super(TooManyColsError, self).__init__(lineno, e, descr, detail, data) + + +class TooFewColsError(DataLineError): + def __init__(self, lineno, e, descr='', detail='', data=''): + super().__init__(lineno, e, descr, detail, data)