diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2019-05-09 20:28:51 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2019-05-09 20:28:51 +0100 |
commit | 8ffab440619f5e520b2636ac212a0d7d1c627316 (patch) | |
tree | d859739184703612e5162b6087e5e120798c5f8e /libpqpp | |
parent | Tidy fixes for latest clang (diff) | |
download | libdbpp-postgresql-8ffab440619f5e520b2636ac212a0d7d1c627316.tar.bz2 libdbpp-postgresql-8ffab440619f5e520b2636ac212a0d7d1c627316.tar.xz libdbpp-postgresql-8ffab440619f5e520b2636ac212a0d7d1c627316.zip |
Get server version into a const local on construction
Diffstat (limited to 'libpqpp')
-rw-r--r-- | libpqpp/pq-mock.cpp | 11 | ||||
-rw-r--r-- | libpqpp/pq-mock.h | 1 |
2 files changed, 7 insertions, 5 deletions
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<std::filesystem::path> & ss) : - MockServerDatabase(masterdb, name, "postgresql") + MockServerDatabase(masterdb, name, "postgresql"), + serverVersion(std::static_pointer_cast<Connection>(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<Connection>(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<std::string, std::string>()) { - c->execute(MockSetUnlogged::get(nspname, relname)); + master->execute(MockSetUnlogged::get(nspname, relname)); n += 1; } } while(n); diff --git a/libpqpp/pq-mock.h b/libpqpp/pq-mock.h index 685b75c..c802080 100644 --- a/libpqpp/pq-mock.h +++ b/libpqpp/pq-mock.h @@ -17,6 +17,7 @@ namespace PQ { protected: void DropDatabase() const override; void SetTablesToUnlogged() const; + const int serverVersion; }; } |