From 815a325980b3339bb3e37c45424156755110de8b Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 7 Dec 2015 17:03:52 +0000 Subject: Smart pointer things up for error handling during setup --- libdbpp/mockDatabase.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/libdbpp/mockDatabase.cpp b/libdbpp/mockDatabase.cpp index ae2d06c..694ec6e 100644 --- a/libdbpp/mockDatabase.cpp +++ b/libdbpp/mockDatabase.cpp @@ -39,22 +39,20 @@ MockDatabase::openConnectionTo(const std::string & mockName) void MockDatabase::PlaySchemaScripts(const std::vector & ss) const { - DB::Connection * conn = openConnection(); + auto conn = ConnectionPtr(openConnection()); try { - CreateStatusTable(conn); + CreateStatusTable(conn.get()); for (auto s : ss) { conn->beginTx(); - PlaySchemaScript(conn, s); + PlaySchemaScript(conn.get(), s); conn->commitTx(); } - DropStatusTable(conn); - delete conn; + DropStatusTable(conn.get()); } catch (...) { if (conn->inTx()) { conn->rollbackTx(); } - delete conn; DropDatabase(); throw; } @@ -81,11 +79,10 @@ MockDatabase::CreateStatusTable(DB::Connection * conn) const pid int, \ script varchar(256), \ scriptdir varchar(256))"); - auto ins = conn->newModifyCommand( + auto ins = ModifyCommandPtr(conn->newModifyCommand( "INSERT INTO public._libdbpp_teststatus(pid) VALUES(?)")); ins->bindParamI(0, getpid()); ins->execute(); - delete ins; } void @@ -97,12 +94,11 @@ MockDatabase::DropStatusTable(DB::Connection * conn) const void MockDatabase::UpdateStatusTable(DB::Connection * conn, const boost::filesystem::path & script) const { - auto upd = conn->newModifyCommand( + auto upd = ModifyCommandPtr(conn->newModifyCommand( "UPDATE public._libdbpp_teststatus SET script = ?, scriptdir = ?")); upd->bindParamS(0, script.string()); upd->bindParamS(1, script.parent_path().string()); upd->execute(); - delete upd; } MockServerDatabase::MockServerDatabase(const std::string & masterdb, const std::string & name, const std::string & type) : -- cgit v1.2.3