From 8ffab440619f5e520b2636ac212a0d7d1c627316 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 9 May 2019 20:28:51 +0100 Subject: Get server version into a const local on construction --- libpqpp/pq-mock.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'libpqpp/pq-mock.cpp') diff --git a/libpqpp/pq-mock.cpp b/libpqpp/pq-mock.cpp index 414e02b..99128c3 100644 --- a/libpqpp/pq-mock.cpp +++ b/libpqpp/pq-mock.cpp @@ -11,7 +11,8 @@ NAMEDFACTORY("postgresql", PQ::Mock, DB::MockDatabaseFactory); namespace PQ { Mock::Mock(const std::string & masterdb, const std::string & name, const std::vector & ss) : - MockServerDatabase(masterdb, name, "postgresql") + MockServerDatabase(masterdb, name, "postgresql"), + serverVersion(std::static_pointer_cast(master)->serverVersion()) { CreateNewDatabase(); PlaySchemaScripts(ss); @@ -29,11 +30,11 @@ AdHocFormatter(MockSetUnlogged, "ALTER TABLE %?.%? SET UNLOGGED"); void Mock::SetTablesToUnlogged() const { - auto c = std::static_pointer_cast(Mock::openConnection()); - if (c->serverVersion() < 90500) { + // v9.5 server required for unlogged tables + if (serverVersion < 90500) { return; } - auto s = c->select(R"SQL( + auto s = master->select(R"SQL( SELECT n.nspname, c.relname FROM pg_class c, pg_namespace n WHERE c.relkind = 'r' @@ -54,7 +55,7 @@ ORDER BY 1, 2)SQL"); do { n = 0; for (const auto [ nspname, relname ] : s->as()) { - c->execute(MockSetUnlogged::get(nspname, relname)); + master->execute(MockSetUnlogged::get(nspname, relname)); n += 1; } } while(n); -- cgit v1.2.3