summaryrefslogtreecommitdiff
path: root/libmysqlpp/embeddedmy-connection.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-12-31 04:04:31 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2017-05-04 20:44:40 +0100
commitdb1e2f066393af3e58814417de5bbe7ea08a145d (patch)
tree9d01e48d8ef7d63fbcca6aced2461b3f1e234dfd /libmysqlpp/embeddedmy-connection.cpp
parentBeginnings of embbeded MySQL (diff)
downloadlibdbpp-mysql-db1e2f066393af3e58814417de5bbe7ea08a145d.tar.bz2
libdbpp-mysql-db1e2f066393af3e58814417de5bbe7ea08a145d.tar.xz
libdbpp-mysql-db1e2f066393af3e58814417de5bbe7ea08a145d.zip
Basics working, could do with a tidy up around mocking
Diffstat (limited to 'libmysqlpp/embeddedmy-connection.cpp')
-rw-r--r--libmysqlpp/embeddedmy-connection.cpp64
1 files changed, 61 insertions, 3 deletions
diff --git a/libmysqlpp/embeddedmy-connection.cpp b/libmysqlpp/embeddedmy-connection.cpp
index f0bb24d..2a21450 100644
--- a/libmysqlpp/embeddedmy-connection.cpp
+++ b/libmysqlpp/embeddedmy-connection.cpp
@@ -1,16 +1,74 @@
#include "embeddedmy-connection.h"
+#include "my-opts.h"
+#include <nvpParse.h>
NAMEDFACTORY("embeddedmysql", MySQL::Embedded::Connection, DB::ConnectionFactory);
namespace MySQL {
namespace Embedded {
- Connection::Connection(const std::string &)
+ class Opts {
+ public:
+ boost::filesystem::path path;
+ MySQL::OptString database;
+ MySQL::OptString options;
+ std::vector<std::string> serverOptions;
+ };
+
+ using namespace AdHoc;
+ NvpTarget(Opts) OptsTargetMap {
+ NvpValue(Opts, path),
+ NvpValue(Opts, database),
+ NvpValue(Opts, options),
+ NvpValue(Opts, serverOptions),
+ };
+
+ Connection::Connection(const std::string & str)
{
+ std::stringstream i(str);
+ Opts o;
+ NvpParse::parse(i, OptsTargetMap, o);
mysql_init(&conn);
+ if (o.options) {
+ mysql_options(&conn, MYSQL_READ_DEFAULT_GROUP, ~o.options);
+ }
mysql_options(&conn, MYSQL_OPT_USE_EMBEDDED_CONNECTION, NULL);
- if (mysql_real_connect(&conn, NULL, NULL, NULL, "database1", 0, NULL, 0)) {
- throw MySQL::Error(&conn);
+ server = Server::get(o.path, o.serverOptions);
+ if (mysql_real_connect(&conn, NULL, NULL, NULL, ~o.database,
+ 0, NULL, CLIENT_LOCAL_FILES | CLIENT_MULTI_STATEMENTS) == NULL) {
+ throw MySQL::ConnectionError(&conn);
+ }
+ if (mysql_set_character_set(&conn, "utf8")) {
+ throw MySQL::ConnectionError(&conn);
+ }
+ }
+
+ Connection::Connection(Server *, const std::string & db)
+ {
+ mysql_init(&conn);
+ mysql_options(&conn, MYSQL_OPT_USE_EMBEDDED_CONNECTION, NULL);
+ if (mysql_real_connect(&conn, NULL, NULL, NULL, db.c_str(),
+ 0, NULL, CLIENT_LOCAL_FILES | CLIENT_MULTI_STATEMENTS) == NULL) {
+ throw MySQL::ConnectionError(&conn);
+ }
+ if (mysql_set_character_set(&conn, "utf8")) {
+ throw MySQL::ConnectionError(&conn);
}
}
+
+ void Connection::beginBulkUpload(const char * t, const char * e)
+ {
+ DB::Connection::beginBulkUpload(t, e);
+ }
+
+ void Connection::endBulkUpload(const char * msg)
+ {
+ DB::Connection::endBulkUpload(msg);
+ }
+
+ size_t Connection::bulkUploadData(const char * b, size_t s) const
+ {
+ return DB::Connection::bulkUploadData(b, s);
+ }
+
}
}