]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Merge pull request #9190 from zeha/psql-prep
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Tue, 9 Jun 2020 18:15:39 +0000 (20:15 +0200)
committerGitHub <noreply@github.com>
Tue, 9 Jun 2020 18:15:39 +0000 (20:15 +0200)
gpgsql: Reintroduce prepared statements

1  2 
modules/gpgsqlbackend/spgsql.cc

index b7e0c4a247038a7409d06e7d0dcb6cdf5ce0dd1b,aeab4470b6d0e44eb0e7060f2efdb3feceb1d9d9..fe6e06517aeb54b0dcb372b8e35f941eafc47146
@@@ -77,22 -68,14 +68,26 @@@ 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);
+     if (!d_stmt.empty()) {
+       d_res_set = PQexecPrepared(d_db(), d_stmt.c_str(), d_nparams, paramValues, paramLengths, nullptr, 0);
+     } else {
+       d_res_set = PQexecParams(d_db(), d_query.c_str(), d_nparams, nullptr, paramValues, paramLengths, nullptr, 0);
+     }
      ExecStatusType status = PQresultStatus(d_res_set);
      if (status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK && status != PGRES_NONFATAL_ERROR) {
        string errmsg(PQresultErrorMessage(d_res_set));