From f0277a802a9b7a6fcb944e78ab90e32578bebae7 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Mon, 18 Jan 2021 14:51:20 -0600 Subject: [PATCH] Class to test for too few columns in param substition --- src/pgwui_core/core.py | 16 ++++++++++++++++ src/pgwui_core/exceptions.py | 5 +++++ 2 files changed, 21 insertions(+) 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) -- 2.34.1