PgDB: add possibility to provide query parameters on doSelect()

This commit is contained in:
Benjamin Renard 2021-07-12 12:16:42 +02:00
parent 198d6021b4
commit 8dbb067996

21
PgDB.py
View file

@ -70,15 +70,18 @@ class PgDB(object):
self.con.rollback() self.con.rollback()
return False return False
def doSelect(self,sql): def doSelect(self,sql,params):
cursor = self.con.cursor() cursor = self.con.cursor()
try: try:
cursor.execute(sql) if params is None:
results = cursor.fetchall() cursor.execute(sql)
return results else:
except Exception: cursor.execute(sql,params)
logging.error(u'Error during SQL request "%s"', sql.decode('utf-8', 'ignore'), exc_info=1) results = cursor.fetchall()
return False return results
except Exception:
logging.error(u'Error during SQL request "%s"', sql.decode('utf-8', 'ignore'), exc_info=1)
return False
# #
# SQL helpers # SQL helpers