summaryrefslogtreecommitdiff
path: root/libpqpp/pq-mock.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2016-12-31 04:59:00 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2016-12-31 04:59:00 +0000
commit4013f18f0e9f257e6c0d7ffecdec3cfc9bf0db0d (patch)
treed8e89ed8329c9367bf32c59584f6b659b81584ec /libpqpp/pq-mock.cpp
parentMore complex approach to setting tables to unlogged to handle foreign key dep... (diff)
downloadlibdbpp-postgresql-4013f18f0e9f257e6c0d7ffecdec3cfc9bf0db0d.tar.bz2
libdbpp-postgresql-4013f18f0e9f257e6c0d7ffecdec3cfc9bf0db0d.tar.xz
libdbpp-postgresql-4013f18f0e9f257e6c0d7ffecdec3cfc9bf0db0d.zip
Do lots more work with compile time formatter instead runtime formatters
Diffstat (limited to 'libpqpp/pq-mock.cpp')
-rw-r--r--libpqpp/pq-mock.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/libpqpp/pq-mock.cpp b/libpqpp/pq-mock.cpp
index c90f84c..44c8cc9 100644
--- a/libpqpp/pq-mock.cpp
+++ b/libpqpp/pq-mock.cpp
@@ -1,6 +1,7 @@
#include "pq-mock.h"
#include "pq-connection.h"
-#include <buffer.h>
+#include <compileTimeFormatter.h>
+#include <modifycommand.h>
#include <selectcommand.h>
#include <selectcommandUtil.impl.h>
@@ -14,12 +15,14 @@ Mock::Mock(const std::string & masterdb, const std::string & name, const std::ve
SetTablesToUnlogged();
}
+AdHocFormatter(MockConnStr, "user=postgres dbname=%?");
DB::Connection *
Mock::openConnection() const
{
- return new Connection(stringbf("user=postgres dbname=%s", testDbName));
+ return new Connection(MockConnStr::get(testDbName));
}
+AdHocFormatter(MockSetUnlogged, "ALTER TABLE %?.%? SET UNLOGGED");
void
Mock::SetTablesToUnlogged() const
{
@@ -45,7 +48,7 @@ ORDER BY 1, 2)SQL");
do {
n = 0;
for (const auto & t : s->as<std::string, std::string>()) {
- c->execute("ALTER TABLE " + t.value<0>() + "." + t.value<1>() + " SET UNLOGGED");
+ c->execute(MockSetUnlogged::get(t.value<0>(), t.value<1>()));
n += 1;
}
} while(n);
@@ -59,7 +62,9 @@ Mock::~Mock()
void
Mock::DropDatabase() const
{
- master->execute("SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '" + testDbName + "'");
+ auto t = master->modify("SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = ?");
+ t->bindParamS(0, testDbName);
+ t->execute();
MockServerDatabase::DropDatabase();
}