diff options
Diffstat (limited to 'libpqpp')
-rw-r--r-- | libpqpp/pq-mock.cpp | 15 | ||||
-rw-r--r-- | libpqpp/pq-mock.h | 1 |
2 files changed, 16 insertions, 0 deletions
diff --git a/libpqpp/pq-mock.cpp b/libpqpp/pq-mock.cpp index db7eafb..30f14aa 100644 --- a/libpqpp/pq-mock.cpp +++ b/libpqpp/pq-mock.cpp @@ -1,6 +1,8 @@ #include "pq-mock.h" #include "pq-connection.h" #include <buffer.h> +#include <selectcommand.h> +#include <selectcommandUtil.impl.h> namespace PQ { @@ -9,6 +11,7 @@ Mock::Mock(const std::string & masterdb, const std::string & name, const std::ve { CreateNewDatabase(); PlaySchemaScripts(ss); + SetTablesToUnlogged(); } DB::Connection * @@ -17,6 +20,18 @@ Mock::openConnection() const return new Connection(stringbf("user=postgres dbname=%s", testDbName)); } +void +Mock::SetTablesToUnlogged() const +{ + auto c = DB::ConnectionPtr(openConnection()); + auto s = c->select("SELECT schemaname, tablename FROM pg_catalog.pg_tables WHERE schemaname NOT IN (?, ?)"); + s->bindParamS(0, "pg_catalog"); + s->bindParamS(1, "information_schema"); + for (const auto & t : s->as<std::string, std::string>()) { + c->execute("ALTER TABLE " + t.value<0>() + "." + t.value<1>() + " SET UNLOGGED"); + } +} + Mock::~Mock() { DropDatabase(); diff --git a/libpqpp/pq-mock.h b/libpqpp/pq-mock.h index e8b7366..0081c5a 100644 --- a/libpqpp/pq-mock.h +++ b/libpqpp/pq-mock.h @@ -15,6 +15,7 @@ namespace PQ { protected: void DropDatabase() const override; + void SetTablesToUnlogged() const; }; } |