Class to test for too few columns in param substition
authorKarl O. Pinc <kop@karlpinc.com>
Mon, 18 Jan 2021 20:51:20 +0000 (14:51 -0600)
committerKarl O. Pinc <kop@karlpinc.com>
Mon, 18 Jan 2021 20:51:20 +0000 (14:51 -0600)
src/pgwui_core/core.py
src/pgwui_core/exceptions.py

index 6779c76bcfd96d352165f2ac4a819a19de7c81ff..32c95107a88201b068d8a0c61d9a8f7f960d4b98 100644 (file)
@@ -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)
index 22cb2a6d47d80be0ff73ba927de272e0bffce413..25b564b463b8dc4a907af8cec2903835c9a14197 100644 (file)
@@ -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)