From 9c35ead28e3bfd98eaf4b43288cfa9527f96d4f1 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Fri, 19 Nov 2021 11:53:30 +0100 Subject: [PATCH] PgDB: add debug of SQL query in doSQL & doSelect methods --- mylib/pgsql.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/mylib/pgsql.py b/mylib/pgsql.py index b6e6864..f2fb2d0 100644 --- a/mylib/pgsql.py +++ b/mylib/pgsql.py @@ -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)