summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2019-05-09 20:28:51 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2019-05-09 20:28:51 +0100
commit8ffab440619f5e520b2636ac212a0d7d1c627316 (patch)
treed859739184703612e5162b6087e5e120798c5f8e
parentTidy fixes for latest clang (diff)
downloadlibdbpp-postgresql-8ffab440619f5e520b2636ac212a0d7d1c627316.tar.bz2
libdbpp-postgresql-8ffab440619f5e520b2636ac212a0d7d1c627316.tar.xz
libdbpp-postgresql-8ffab440619f5e520b2636ac212a0d7d1c627316.zip
Get server version into a const local on construction
-rw-r--r--libpqpp/pq-mock.cpp11
-rw-r--r--libpqpp/pq-mock.h1
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;
};
}