From 94927bfef6548ac20118586bfcd51e60b296e569 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 24 Dec 2015 03:43:16 +0000 Subject: Beginnings of embbeded MySQL --- libmysqlpp/embeddedmy-mock.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 libmysqlpp/embeddedmy-mock.cpp (limited to 'libmysqlpp/embeddedmy-mock.cpp') diff --git a/libmysqlpp/embeddedmy-mock.cpp b/libmysqlpp/embeddedmy-mock.cpp new file mode 100644 index 0000000..0ad0cc5 --- /dev/null +++ b/libmysqlpp/embeddedmy-mock.cpp @@ -0,0 +1,52 @@ +#include "embeddedmy-connection.h" +#include "embeddedmy-mock.h" +#include +#include + +namespace MySQL { + namespace Embedded { + + Mock::Mock(const std::string & name, const std::vector & ss) : + MockDatabase(name), + testDbPath(boost::filesystem::path("/tmp") / stringbf("embeddedmysql-%d-%d", getpid(), ++DB::MockDatabase::mocked)) + { + CreateNewDatabase(); + PlaySchemaScripts(ss); + } + + Mock::~Mock() + { + DropDatabase(); + } + + DB::Connection * + Mock::openConnection() const + { + return new Connection(testDbPath.string()); + } + + void + Mock::CreateNewDatabase() const + { + boost::filesystem::create_directories(testDbPath); + const auto datadir = stringbf("--datadir=%s", testDbPath.string()); + static const char * opts[] = { + typeid(this).name(), + datadir.c_str(), + "--bootstrap", + NULL + }; + static const char * groups[] = { NULL }; + mysql_library_init(3, (char**)opts, (char**)groups); + sleep(20); + } + + void + Mock::DropDatabase() const + { + mysql_library_end(); + boost::filesystem::remove_all(testDbPath); + } + } +} + -- cgit v1.2.3