summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-07-19 23:40:15 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-07-19 23:40:15 +0100
commitb2e4bd857ec0cca7ef474519c8d1a0ef77abfda2 (patch)
tree7ef6f4590731a506fd68de5efc5cd2341335ddba /lib
parentMove constructable PqConn (diff)
downloadmygrate-b2e4bd857ec0cca7ef474519c8d1a0ef77abfda2.tar.bz2
mygrate-b2e4bd857ec0cca7ef474519c8d1a0ef77abfda2.tar.xz
mygrate-b2e4bd857ec0cca7ef474519c8d1a0ef77abfda2.zip
Get source database name into UpdateDatabase on configure
Diffstat (limited to 'lib')
-rw-r--r--lib/output/pq/sql/selectSourceSchema.sql2
-rw-r--r--lib/output/pq/updateDatabase.cpp11
-rw-r--r--lib/output/pq/updateDatabase.h3
3 files changed, 13 insertions, 3 deletions
diff --git a/lib/output/pq/sql/selectSourceSchema.sql b/lib/output/pq/sql/selectSourceSchema.sql
index a583c4f..99cafac 100644
--- a/lib/output/pq/sql/selectSourceSchema.sql
+++ b/lib/output/pq/sql/selectSourceSchema.sql
@@ -1,3 +1,3 @@
-SELECT table_schema
+SELECT table_schema, database
FROM mygrate.source s
WHERE s.source_id = $1
diff --git a/lib/output/pq/updateDatabase.cpp b/lib/output/pq/updateDatabase.cpp
index 55ef561..6a0f419 100644
--- a/lib/output/pq/updateDatabase.cpp
+++ b/lib/output/pq/updateDatabase.cpp
@@ -25,8 +25,15 @@
namespace MyGrate::Output::Pq {
ColumnDef::ColumnDef(std::string n, std::size_t o, bool p) : name {std::move(n)}, ordinal(o), is_pk(p) { }
- UpdateDatabase::UpdateDatabase(const char * const str, uint64_t s) :
- PqConn {str}, source {s}, schema(**output::pq::sql::selectSourceSchema::execute(this, s))
+ UpdateDatabase::UpdateDatabase(const char * const str, uint64_t s) : UpdateDatabase {PqConn {str}, s} { }
+
+ UpdateDatabase::UpdateDatabase(PqConn && conn, uint64_t s) :
+ UpdateDatabase {std::forward<PqConn>(conn), s, output::pq::sql::selectSourceSchema::execute(&conn, s)}
+ {
+ }
+
+ UpdateDatabase::UpdateDatabase(PqConn && conn, uint64_t s, RecordSetPtr cfg) :
+ PqConn {std::move(conn)}, source {s}, schema(cfg->at(0, 0)), database(cfg->at(0, 1))
{
auto trecs = output::pq::sql::selectTables::execute(this, source);
auto crecs = output::pq::sql::selectColumns::execute(this, source);
diff --git a/lib/output/pq/updateDatabase.h b/lib/output/pq/updateDatabase.h
index 0355a47..79df9a9 100644
--- a/lib/output/pq/updateDatabase.h
+++ b/lib/output/pq/updateDatabase.h
@@ -46,8 +46,11 @@ namespace MyGrate::Output::Pq {
const uint64_t source;
const std::string schema;
+ const std::string database;
private:
+ UpdateDatabase(PqConn &&, uint64_t source);
+ UpdateDatabase(PqConn &&, uint64_t source, RecordSetPtr cfg);
std::map<std::string, TableDefPtr, std::less<>> tables;
};
}