summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-06-13 21:29:56 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-06-13 21:29:56 +0100
commit76a180856082102a0ee50506ac887aa3e8b3d64e (patch)
tree041478ee5fc41e8845bed55fd8dbd35dabeb8000
parentAdd transaction support (diff)
downloadmygrate-76a180856082102a0ee50506ac887aa3e8b3d64e.tar.bz2
mygrate-76a180856082102a0ee50506ac887aa3e8b3d64e.tar.xz
mygrate-76a180856082102a0ee50506ac887aa3e8b3d64e.zip
Perform source setup in transaction
-rw-r--r--lib/output/pq/updateDatabase.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/output/pq/updateDatabase.cpp b/lib/output/pq/updateDatabase.cpp
index 99d2861..f344f42 100644
--- a/lib/output/pq/updateDatabase.cpp
+++ b/lib/output/pq/updateDatabase.cpp
@@ -47,10 +47,11 @@ namespace MyGrate::Output::Pq {
{
Input::MySQLConn my {host, username, password, port};
auto ms = input::sql::showMasterStatus::execute(&my);
- auto source_id = output::pq::sql::insertSource::execute(
- pq, host, username, password, port, db, ms->at(0, 0), ms->at(0, 1), sid, schema);
- pq->query(scprintf<"CREATE SCHEMA IF NOT EXISTS %?">(schema).c_str());
-
- return UpdateDatabase(pq->connstr.c_str(), source_id->at(0, 0));
+ auto source_id = Tx {pq}([&]() {
+ pq->query(scprintf<"CREATE SCHEMA IF NOT EXISTS %?">(schema).c_str());
+ return **output::pq::sql::insertSource::execute(
+ pq, host, username, password, port, db, ms->at(0, 0), ms->at(0, 1), sid, schema);
+ });
+ return UpdateDatabase(pq->connstr.c_str(), source_id);
}
}