diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-12-07 17:03:52 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-12-07 17:03:52 +0000 |
commit | 815a325980b3339bb3e37c45424156755110de8b (patch) | |
tree | 0dc0cda69acea8d2e7f976f715124cd3fc90b324 | |
parent | Remove p2 referencen in table name and be specific about schema it exists in. (diff) | |
download | libdbpp-0.10.1.tar.bz2 libdbpp-0.10.1.tar.xz libdbpp-0.10.1.zip |
Smart pointer things up for error handling during setuplibdbpp-0.10.1
-rw-r--r-- | libdbpp/mockDatabase.cpp | 16 |
1 files 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<boost::filesystem::path> & 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) : |