summaryrefslogtreecommitdiff
path: root/lib/output
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-07-22 23:34:21 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-07-22 23:34:21 +0100
commitaaf95b4bab0261af42acf5eeaf77891ffa5ae46b (patch)
treea34d1dbd706c080e8f5bd2140dd54621dabe1011 /lib/output
parentFirst cut replicating row updates (diff)
downloadmygrate-aaf95b4bab0261af42acf5eeaf77891ffa5ae46b.tar.bz2
mygrate-aaf95b4bab0261af42acf5eeaf77891ffa5ae46b.tar.xz
mygrate-aaf95b4bab0261af42acf5eeaf77891ffa5ae46b.zip
Store key count
Diffstat (limited to 'lib/output')
-rw-r--r--lib/output/pq/updateDatabase.cpp11
-rw-r--r--lib/output/pq/updateDatabase.h1
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>;