diff options
Diffstat (limited to 'lib/output')
-rw-r--r-- | lib/output/pq/sql/selectSourceSchema.sql | 2 | ||||
-rw-r--r-- | lib/output/pq/updateDatabase.cpp | 11 | ||||
-rw-r--r-- | lib/output/pq/updateDatabase.h | 3 |
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; }; } |