From da88fd8c6702e587dac6dc9298348123cceacde1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 5 Jul 2021 19:55:05 +0100 Subject: Tidy selecting source data a bit Fixes variable shadowing. --- lib/output/pq/updateDatabase.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'lib') 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()}; -- cgit v1.2.3