]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
gpgsql: Use a simple counter for statement names
authorChristian Hofstaedtler <christian.hofstaedtler@deduktiva.com>
Tue, 31 Jan 2017 11:02:56 +0000 (12:02 +0100)
committerPieter Lexis <pieter.lexis@powerdns.com>
Tue, 7 Nov 2017 20:25:06 +0000 (21:25 +0100)
(cherry picked from commit 46703164da40199245cee4d8720faa141221cf1b)

modules/gpgsqlbackend/spgsql.cc
modules/gpgsqlbackend/spgsql.hh

index 856a365a0859607ecf8107a94aa0b961dcc92815..00f19726d4fef6ff4ad6cc662f504bae83d30c56 100644 (file)
@@ -35,7 +35,7 @@
 class SPgSQLStatement: public SSqlStatement
 {
 public:
-  SPgSQLStatement(const string& query, bool dolog, int nparams, SPgSQL* db) {
+  SPgSQLStatement(const string& query, bool dolog, int nparams, SPgSQL* db, unsigned int nstatement) {
     d_query = query;
     d_dolog = dolog;
     d_parent = db;
@@ -51,6 +51,7 @@ public:
     d_resnum = 0;
     d_fnum = 0;
     d_cur_set = 0;
+    d_nstatement = nstatement;
   }
 
   SSqlStatement* bind(const string& name, bool value) { return bind(name, string(value ? "t" : "f")); }
@@ -219,8 +220,8 @@ private:
 
   void prepareStatement() {
     if (d_prepared) return;
-    // prepare a statement; name must be unique per session.
-    this->d_stmt = string("stmt") + std::to_string((uintptr_t)this);
+    // prepare a statement; name must be unique per session (using d_nstatement to ensure this).
+    this->d_stmt = string("stmt") + std::to_string(d_nstatement);
     PGresult* res = PQprepare(d_db(), d_stmt.c_str(), d_query.c_str(), d_nparams, NULL);
     ExecStatusType status = PQresultStatus(res);
     string errmsg(PQresultErrorMessage(res));
@@ -262,6 +263,7 @@ private:
   int d_fnum;
   int d_cur_set;
   bool d_do_commit;
+  unsigned int d_nstatement;
 };
 
 bool SPgSQL::s_dolog;
@@ -272,6 +274,7 @@ SPgSQL::SPgSQL(const string &database, const string &host, const string& port, c
   d_db=0;
   d_in_trx = false;
   d_connectstr="";
+  d_nstatement = 0;
 
   if (!database.empty())
     d_connectstr+="dbname="+database;
@@ -335,7 +338,8 @@ void SPgSQL::execute(const string& query)
 
 SSqlStatement* SPgSQL::prepare(const string& query, int nparams)
 {
-  return new SPgSQLStatement(query, s_dolog, nparams, this);
+  d_nstatement++;
+  return new SPgSQLStatement(query, s_dolog, nparams, this, d_nstatement);
 }
 
 void SPgSQL::startTransaction() {
index 8e9dd544feedc2fb60261b9f81891ddc8461664c..f06477b4b65f1cb6ac4d2c5456d3c37e81005d22 100644 (file)
@@ -51,6 +51,7 @@ private:
   string d_connectlogstr;
   static bool s_dolog;
   bool d_in_trx;
+  unsigned int d_nstatement;
 };
-      
+
 #endif /* SPGSQL_HH */