summaryrefslogtreecommitdiff
path: root/lib/output/pq
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-07-05 19:55:05 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-07-05 19:55:05 +0100
commitda88fd8c6702e587dac6dc9298348123cceacde1 (patch)
tree3885ef258cde94dd40e1de401f1faf043913a8f7 /lib/output/pq
parentExplicit PqConnDB test class constructor (diff)
downloadmygrate-da88fd8c6702e587dac6dc9298348123cceacde1.tar.bz2
mygrate-da88fd8c6702e587dac6dc9298348123cceacde1.tar.xz
mygrate-da88fd8c6702e587dac6dc9298348123cceacde1.zip
Tidy selecting source data a bit
Fixes variable shadowing.
Diffstat (limited to 'lib/output/pq')
-rw-r--r--lib/output/pq/updateDatabase.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/output/pq/updateDatabase.cpp b/lib/output/pq/updateDatabase.cpp
index 457f744..907ee60 100644
--- a/lib/output/pq/updateDatabase.cpp
+++ b/lib/output/pq/updateDatabase.cpp
@@ -185,13 +185,16 @@ namespace MyGrate::Output::Pq {
UpdateDatabase::copyTableContent(Input::MySQLConn * conn, const char * table)
{
auto out = beginBulkUpload(schema.c_str(), table);
- std::stringstream sf;
- unsigned int ordinal {0};
- for (const auto & col : tables.at(table)->columns) {
- scprintf<"%? %?">(sf, !ordinal++ ? "SELECT " : ", ", col->name);
- }
- sf << " FROM " << table;
- auto stmt {conn->prepare(sf.str().c_str(), 0)};
+ auto sourceSelect = [this](auto table) {
+ std::stringstream sf;
+ unsigned int ordinal {0};
+ for (const auto & col : tables.at(table)->columns) {
+ scprintf<"%? %?">(sf, !ordinal++ ? "SELECT " : ", ", col->name);
+ }
+ sf << " FROM " << table;
+ return sf.str();
+ };
+ auto stmt {conn->prepare(sourceSelect(table).c_str(), 0)};
stmt->execute({});
auto sourceCursor {stmt->cursor()};