runquery.py
changeset 92 8816c917979c
parent 91 fba99a54ec49
child 93 b72591087495
--- a/runquery.py	Mon Dec 09 11:39:28 2013 +0100
+++ b/runquery.py	Mon Dec 09 13:57:31 2013 +0100
@@ -12,6 +12,8 @@
 import time
 from datetime import datetime, timedelta
 
+from psycopg2 import ProgrammingError
+
 
 class RunQueryTool(toolbase.ToolBase):
 
@@ -66,13 +68,17 @@
     def main(self):
         """Execute the queries."""
         for q in self.queries:
-            q = q.format(**self.parameters)
+            if self.parameters:
+                q = q.format(**self.parameters)
             self.log.info('%s', q if len(q) < 100 else q[:100]+'...')
             with self.pgm.cursor('target') as curs:
                 curs.execute(q)
                 self.log.info('Rows affected: %d', curs.rowcount)
-                rows = curs.fetchall_dict()
-                self._write_output_file(rows)
+                try:
+                    rows = curs.fetchall_dict()
+                    self._write_output_file(rows)
+                except ProgrammingError:
+                    pass
         self.log.info('Done')
 
     def _write_output_file(self, rows):