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() cursor = self._conn.cursor()
try: 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: if params is None:
cursor.execute(sql) cursor.execute(sql)
else: else:
@ -141,7 +149,7 @@ class PgDB:
return True return True
except Exception: except Exception:
log.error( log.error(
'Error during SQL request "%s" %s', 'Error during SQL query "%s" %s',
sql, sql,
"with params = %s" % ', '.join([ "with params = %s" % ', '.join([
"%s = %s" % (key, value) "%s = %s" % (key, value)
@ -164,12 +172,20 @@ class PgDB:
""" """
cursor = self._conn.cursor() cursor = self._conn.cursor()
try: 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) cursor.execute(sql, params)
results = cursor.fetchall() results = cursor.fetchall()
return results return results
except Exception: except Exception:
log.error( log.error(
'Error during SQL request "%s" %s', 'Error during SQL query "%s" %s',
sql, sql,
"with params = %s" % ', '.join([ "with params = %s" % ', '.join([
"%s = %s" % (key, value) "%s = %s" % (key, value)