diff options
Diffstat (limited to 'lib/output/pq')
-rw-r--r-- | lib/output/pq/updateDatabase.cpp | 11 | ||||
-rw-r--r-- | 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<ColumnDef, 3, 1>()); + const auto & cd = columns.emplace_back(crecs[c].create<ColumnDef, 3, 1>()); + 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<ColumnDef>(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<DbValue> 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<ColumnDefPtr> columns; + std::size_t keys; DbPrepStmtPtr update; }; using TableDefPtr = std::unique_ptr<TableOutput>; |