]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
gpgsqlbackend: add parameters to query logging 9189/head
authorChris Hofstaedtler <chris.hofstaedtler@deduktiva.com>
Tue, 2 Jun 2020 17:27:24 +0000 (19:27 +0200)
committerChris Hofstaedtler <chris.hofstaedtler@deduktiva.com>
Tue, 2 Jun 2020 17:27:42 +0000 (19:27 +0200)
Addresses #5292 (for postgres only).

modules/gpgsqlbackend/spgsql.cc

index 68e5be885fc7cf88d576a52ed39185d3481c27c0..b7e0c4a247038a7409d06e7d0dcb6cdf5ce0dd1b 100644 (file)
@@ -77,7 +77,19 @@ public:
   SSqlStatement* execute() {
     prepareStatement();
     if (d_dolog) {
-      g_log<<Logger::Warning<< "Query "<<((long)(void*)this)<<": " << d_query << endl;
+      g_log<<Logger::Warning<< "Query "<<((long)(void*)this)<<": Statement: " << d_query << endl;
+      if (d_paridx) {
+        // Log message is similar, bot not exactly the same as the postgres server log.
+        std::stringstream log_message;
+        log_message<< "Query "<<((long)(void*)this)<<": Parameters: ";
+        for (int i = 0; i < d_paridx; i++) {
+          if (i != 0) {
+            log_message << ", ";
+          }
+          log_message << "$" << (i + 1) << " = '" << paramValues[i] << "'";
+        }
+        g_log<<Logger::Warning<< log_message.str() << endl;
+      }
       d_dtime.set();
     }
     d_res_set = PQexecParams(d_db(), d_query.c_str(), d_nparams, NULL, paramValues, paramLengths, NULL, 0);