From aaf95b4bab0261af42acf5eeaf77891ffa5ae46b Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 22 Jul 2021 23:34:21 +0100 Subject: Store key count --- lib/output/pq/updateDatabase.cpp | 11 ++++++----- lib/output/pq/updateDatabase.h | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/output/pq/updateDatabase.cpp b/lib/output/pq/updateDatabase.cpp index 9659cc0..7036f67 100644 --- a/lib/output/pq/updateDatabase.cpp +++ b/lib/output/pq/updateDatabase.cpp @@ -56,7 +56,10 @@ namespace MyGrate::Output::Pq { { for (auto c {0U}; c < crecs.rows(); c++) { if (crecs.at(c, 0) == name) { - columns.emplace_back(crecs[c].create()); + const auto & cd = columns.emplace_back(crecs[c].create()); + if (cd->is_pk) { + keys += 1; + } } } } @@ -97,6 +100,7 @@ namespace MyGrate::Output::Pq { } if (col[3]) { ct << " primary key"; + tableDef->keys += 1; } tableDef->columns.push_back(std::make_unique(col[0], tableDef->columns.size() + 1, col[3])); } @@ -270,10 +274,7 @@ namespace MyGrate::Output::Pq { out->update = prepare(ou.str().c_str(), kordinal); } std::vector updateValues; - updateValues.reserve( - out->columns.size() + std::count_if(out->columns.begin(), out->columns.end(), [](auto && c) { - return c->is_pk; - })); + updateValues.reserve(out->columns.size() + out->keys); RowPair rp {e->event.rows, table_map->event.table_map}; std::copy(rp.second.begin(), rp.second.end(), std::back_inserter(updateValues)); std::copy_if(rp.first.begin(), rp.first.end(), std::back_inserter(updateValues), diff --git a/lib/output/pq/updateDatabase.h b/lib/output/pq/updateDatabase.h index aa50e90..e56852b 100644 --- a/lib/output/pq/updateDatabase.h +++ b/lib/output/pq/updateDatabase.h @@ -26,6 +26,7 @@ namespace MyGrate::Output::Pq { TableOutput(const RecordSet &, std::string_view name); std::vector columns; + std::size_t keys; DbPrepStmtPtr update; }; using TableDefPtr = std::unique_ptr; -- cgit v1.2.3