PgDB: add debug of SQL query in doSQL & doSelect methods

This commit is contained in:
Benjamin Renard 2021-11-19 11:53:30 +01:00
parent ef510a36ee
commit 9c35ead28e

View file

@ -133,6 +133,14 @@ class PgDB:
cursor = self._conn.cursor()
try:
log.debug(
'Run SQL query "%s" %s',
sql,
"with params = %s" % ', '.join([
"%s = %s" % (key, value)
for key, value in params.items()
]) if params else "without params"
)
if params is None:
cursor.execute(sql)
else:
@ -141,7 +149,7 @@ class PgDB:
return True
except Exception:
log.error(
'Error during SQL request "%s" %s',
'Error during SQL query "%s" %s',
sql,
"with params = %s" % ', '.join([
"%s = %s" % (key, value)
@ -164,12 +172,20 @@ class PgDB:
"""
cursor = self._conn.cursor()
try:
log.debug(
'Run SQL SELECT query "%s" %s',
sql,
"with params = %s" % ', '.join([
"%s = %s" % (key, value)
for key, value in params.items()
]) if params else "without params"
)
cursor.execute(sql, params)
results = cursor.fetchall()
return results
except Exception:
log.error(
'Error during SQL request "%s" %s',
'Error during SQL query "%s" %s',
sql,
"with params = %s" % ', '.join([
"%s = %s" % (key, value)