From 626343c699d42aab176e740f5e75853f51290a49 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 31 Dec 2016 04:59:00 +0000 Subject: Do lots more work with compile time formatter instead runtime formatters --- libmysqlpp/my-connection.cpp | 7 ++++--- libmysqlpp/my-mock.cpp | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'libmysqlpp') diff --git a/libmysqlpp/my-connection.cpp b/libmysqlpp/my-connection.cpp index 687572f..c25a97b 100644 --- a/libmysqlpp/my-connection.cpp +++ b/libmysqlpp/my-connection.cpp @@ -6,6 +6,7 @@ #include #include #include +#include NAMEDFACTORY("mysql", MySQL::Connection, DB::ConnectionFactory); @@ -189,12 +190,12 @@ namespace MySQL { }; } +AdHocFormatter(MySQLConnectionLoadData, "LOAD DATA LOCAL INFILE 'any' INTO TABLE %? %?"); void MySQL::Connection::beginBulkUpload(const char * table, const char * extra) { - static char buf[BUFSIZ]; - int len = snprintf(buf, BUFSIZ, "LOAD DATA LOCAL INFILE 'any' INTO TABLE %s %s", table, extra); - mysql_send_query(&conn, buf, len); + auto sql = MySQLConnectionLoadData::get(table, extra); + mysql_send_query(&conn, sql.c_str(), sql.length()); ctx = boost::shared_ptr(new MySQL::LoadContext(&conn)); diff --git a/libmysqlpp/my-mock.cpp b/libmysqlpp/my-mock.cpp index bf02e11..2eee416 100644 --- a/libmysqlpp/my-mock.cpp +++ b/libmysqlpp/my-mock.cpp @@ -1,6 +1,6 @@ #include "my-connection.h" #include "my-mock.h" -#include +#include namespace MySQL { @@ -11,10 +11,11 @@ Mock::Mock(const std::string & name, const std::vector PlaySchemaScripts(ss); } +AdHocFormatter(MockConnStr, "options=p2testmysql;database=%?"); DB::Connection * Mock::openConnection() const { - return new Connection(stringbf("options=p2testmysql;database=%s", testDbName)); + return new Connection(MockConnStr::get(testDbName)); } Mock::~Mock() -- cgit v1.2.3