summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-07-24 14:07:02 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-07-24 14:07:02 +0100
commit206d33d0962128b10d1630b4e1f5511d952172b3 (patch)
treecb3e74c4664694c1047c1788c244a2bc27cf05b1 /lib
parentAdd missing keys initializer (diff)
downloadmygrate-206d33d0962128b10d1630b4e1f5511d952172b3.tar.bz2
mygrate-206d33d0962128b10d1630b4e1f5511d952172b3.tar.xz
mygrate-206d33d0962128b10d1630b4e1f5511d952172b3.zip
Fix up insert/delete SQL generation
Diffstat (limited to 'lib')
-rw-r--r--lib/output/pq/updateDatabase.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/output/pq/updateDatabase.cpp b/lib/output/pq/updateDatabase.cpp
index 22ae346..4830fd5 100644
--- a/lib/output/pq/updateDatabase.cpp
+++ b/lib/output/pq/updateDatabase.cpp
@@ -300,8 +300,7 @@ namespace MyGrate::Output::Pq {
scprintf<"DELETE FROM %?.%? ">(ou, schema, selected->first);
for (const auto & col : out->columns) {
if (col->is_pk) {
- scprintf<"%? %? = $%?">(
- ou, kordinal == out->columns.size() ? " WHERE " : " AND ", col->name, kordinal + 1);
+ scprintf<"%? %? = $%?">(ou, !kordinal ? " WHERE " : " AND ", col->name, kordinal + 1);
kordinal++;
}
}
@@ -329,19 +328,20 @@ namespace MyGrate::Output::Pq {
e->event.rows.column_count == out->columns.size(), "Incorrect number of columns in row data");
if (!out->insertInto) {
std::stringstream ou;
- std::size_t ordinal {0}, kordinal {out->columns.size()};
+ std::size_t ordinal {0}, vordinal {0};
scprintf<"INSERT INTO %?.%? ">(ou, schema, selected->first);
for (const auto & col : out->columns) {
- scprintf<"%? %?">(ou, !ordinal ? "(" : ", ", col->name);
+ scprintf<"%? %?">(ou, !ordinal++ ? "(" : ", ", col->name);
}
ou << ") VALUES";
for (const auto & col : out->columns) {
- scprintf<"%? $%?">(ou, !ordinal ? "(" : ", ", col->name);
+ scprintf<"%? $%?">(ou, !vordinal++ ? "(" : ", ", vordinal);
+ (void)col;
}
ou << ")";
- out->insertInto = prepare(ou.str().c_str(), kordinal);
+ out->insertInto = prepare(ou.str().c_str(), out->columns.size());
}
std::vector<DbValue> updateValues;
updateValues.reserve(out->columns.size());