From 76a180856082102a0ee50506ac887aa3e8b3d64e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 13 Jun 2021 21:29:56 +0100 Subject: Perform source setup in transaction --- lib/output/pq/updateDatabase.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lib/output/pq') 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); } } -- cgit v1.2.3