summaryrefslogtreecommitdiff
path: root/libmysqlpp
diff options
context:
space:
mode:
Diffstat (limited to 'libmysqlpp')
-rw-r--r--libmysqlpp/my-column.cpp50
-rw-r--r--libmysqlpp/my-column.h41
-rw-r--r--libmysqlpp/my-command.cpp17
-rw-r--r--libmysqlpp/my-command.h67
-rw-r--r--libmysqlpp/my-connection.cpp136
-rw-r--r--libmysqlpp/my-connection.h45
-rw-r--r--libmysqlpp/my-error.cpp11
-rw-r--r--libmysqlpp/my-error.h15
-rw-r--r--libmysqlpp/my-mock.cpp35
-rw-r--r--libmysqlpp/my-mock.h9
-rw-r--r--libmysqlpp/my-modifycommand.cpp7
-rw-r--r--libmysqlpp/my-modifycommand.h15
-rw-r--r--libmysqlpp/my-selectcommand.cpp18
-rw-r--r--libmysqlpp/my-selectcommand.h20
-rw-r--r--libmysqlpp/unittests/testmysql.cpp53
15 files changed, 253 insertions, 286 deletions
diff --git a/libmysqlpp/my-column.cpp b/libmysqlpp/my-column.cpp
index 60c8c10..4d2c762 100644
--- a/libmysqlpp/my-column.cpp
+++ b/libmysqlpp/my-column.cpp
@@ -1,15 +1,10 @@
#include "my-column.h"
-#include "my-selectcommand.h"
#include "my-error.h"
-#include <cstring>
+#include "my-selectcommand.h"
#include <boost/date_time/gregorian/gregorian_types.hpp>
+#include <cstring>
-MySQL::ColumnBase::ColumnBase(const char * name, unsigned int i) :
- DB::Column(name, i),
- is_null(false),
- length(0)
-{
-}
+MySQL::ColumnBase::ColumnBase(const char * name, unsigned int i) : DB::Column(name, i), is_null(false), length(0) { }
bool
MySQL::ColumnBase::isNull() const
@@ -18,9 +13,7 @@ MySQL::ColumnBase::isNull() const
}
MySQL::StringColumn::StringColumn(const char * name, unsigned int field, MYSQL_BIND * b, unsigned int len) :
- ColumnBase(name, field),
- value(len),
- length(0)
+ ColumnBase(name, field), value(len), length(0)
{
b->is_null = &is_null;
b->buffer_type = MYSQL_TYPE_STRING;
@@ -37,12 +30,11 @@ MySQL::StringColumn::apply(DB::HandleField & h) const
h.null();
}
else {
- h.string({ value.data(), length });
+ h.string({value.data(), length});
}
}
-MySQL::NullColumn::NullColumn(const char * name, unsigned int field, MYSQL_BIND * b) :
- ColumnBase(name, field)
+MySQL::NullColumn::NullColumn(const char * name, unsigned int field, MYSQL_BIND * b) : ColumnBase(name, field)
{
b->is_null = &is_null;
b->buffer_type = MYSQL_TYPE_NULL;
@@ -57,8 +49,8 @@ MySQL::NullColumn::apply(DB::HandleField & h) const
}
namespace MySQL {
- template <class T, enum_field_types MT> Column<T, MT>::Column(const char * name, unsigned int field, MYSQL_BIND * b) :
- ColumnBase(name, field)
+ template<class T, enum_field_types MT>
+ Column<T, MT>::Column(const char * name, unsigned int field, MYSQL_BIND * b) : ColumnBase(name, field)
{
b->is_null = &is_null;
b->buffer_type = MT;
@@ -67,7 +59,9 @@ namespace MySQL {
b->buffer_length = sizeof(T);
}
- template <> void Column<int64_t, MYSQL_TYPE_LONGLONG>::apply(DB::HandleField & h) const
+ template<>
+ void
+ Column<int64_t, MYSQL_TYPE_LONGLONG>::apply(DB::HandleField & h) const
{
if (is_null) {
h.null();
@@ -76,7 +70,9 @@ namespace MySQL {
h.integer(value);
}
}
- template <> void Column<double, MYSQL_TYPE_DOUBLE>::apply(DB::HandleField & h) const
+ template<>
+ void
+ Column<double, MYSQL_TYPE_DOUBLE>::apply(DB::HandleField & h) const
{
if (is_null) {
h.null();
@@ -85,25 +81,29 @@ namespace MySQL {
h.floatingpoint(value);
}
}
- template <> void Column<MYSQL_TIME, MYSQL_TYPE_DATETIME>::apply(DB::HandleField & h) const
+ template<>
+ void
+ Column<MYSQL_TIME, MYSQL_TYPE_DATETIME>::apply(DB::HandleField & h) const
{
if (is_null) {
h.null();
}
else {
- h.timestamp(boost::posix_time::ptime(
- boost::gregorian::date(value.year, value.month, value.day),
- boost::posix_time::time_duration(value.hour, value.minute, value.second) + boost::posix_time::microseconds(value.second_part)));
+ h.timestamp(boost::posix_time::ptime(boost::gregorian::date(value.year, value.month, value.day),
+ boost::posix_time::time_duration(value.hour, value.minute, value.second)
+ + boost::posix_time::microseconds(value.second_part)));
}
}
- template <> void Column<MYSQL_TIME, MYSQL_TYPE_TIME>::apply(DB::HandleField & h) const
+ template<>
+ void
+ Column<MYSQL_TIME, MYSQL_TYPE_TIME>::apply(DB::HandleField & h) const
{
if (is_null) {
h.null();
}
else {
- h.interval(
- boost::posix_time::time_duration(value.hour, value.minute, value.second) + boost::posix_time::microseconds(value.second_part));
+ h.interval(boost::posix_time::time_duration(value.hour, value.minute, value.second)
+ + boost::posix_time::microseconds(value.second_part));
}
}
diff --git a/libmysqlpp/my-column.h b/libmysqlpp/my-column.h
index ec0ce85..51c4503 100644
--- a/libmysqlpp/my-column.h
+++ b/libmysqlpp/my-column.h
@@ -7,43 +7,42 @@
namespace MySQL {
class SelectCommand;
class ColumnBase : public DB::Column {
- public:
- ColumnBase(const char * name, unsigned int field);
+ public:
+ ColumnBase(const char * name, unsigned int field);
- [[nodiscard]] bool isNull() const override;
+ [[nodiscard]] bool isNull() const override;
- protected:
- bool is_null;
- long unsigned int length;
- friend class SelectCommand;
+ protected:
+ bool is_null;
+ long unsigned int length;
+ friend class SelectCommand;
};
class StringColumn : public ColumnBase {
- public:
- StringColumn(const char * name, unsigned int field, MYSQL_BIND * b, unsigned int len);
+ public:
+ StringColumn(const char * name, unsigned int field, MYSQL_BIND * b, unsigned int len);
- void apply(DB::HandleField &) const override;
+ void apply(DB::HandleField &) const override;
- std::vector<char> value;
- long unsigned int length;
+ std::vector<char> value;
+ long unsigned int length;
};
class NullColumn : public ColumnBase {
- public:
- NullColumn(const char * name, unsigned int field, MYSQL_BIND * b);
+ public:
+ NullColumn(const char * name, unsigned int field, MYSQL_BIND * b);
- void apply(DB::HandleField &) const override;
+ void apply(DB::HandleField &) const override;
};
- template <class T, enum_field_types MT> class Column : public ColumnBase {
- public:
- Column(const char * name, unsigned int field, MYSQL_BIND * b);
+ template<class T, enum_field_types MT> class Column : public ColumnBase {
+ public:
+ Column(const char * name, unsigned int field, MYSQL_BIND * b);
- void apply(DB::HandleField & h) const override;
+ void apply(DB::HandleField & h) const override;
- T value;
+ T value;
};
}
#endif
-
diff --git a/libmysqlpp/my-command.cpp b/libmysqlpp/my-command.cpp
index e15a3c1..a5efeef 100644
--- a/libmysqlpp/my-command.cpp
+++ b/libmysqlpp/my-command.cpp
@@ -1,14 +1,11 @@
#include "my-command.h"
#include "my-connection.h"
+#include <boost/numeric/conversion/cast.hpp>
#include <cstdlib>
#include <cstring>
-#include <boost/numeric/conversion/cast.hpp>
MySQL::Command::Command(const Connection * conn, const std::string & sql) :
- DB::Command(sql),
- c(conn),
- stmt(mysql_stmt_init(&conn->conn)),
- paramsNeedBinding(false)
+ DB::Command(sql), c(conn), stmt(mysql_stmt_init(&conn->conn)), paramsNeedBinding(false)
{
if (!stmt) {
throw Error(&conn->conn);
@@ -105,7 +102,7 @@ MySQL::Command::bindParamF(unsigned int n, float v)
void
MySQL::Command::bindParamS(unsigned int n, const Glib::ustring & s)
{
- bindParamS(n, std::string_view { s.data(), s.bytes() });
+ bindParamS(n, std::string_view {s.data(), s.bytes()});
}
void
@@ -114,7 +111,7 @@ MySQL::Command::bindParamS(unsigned int n, const std::string_view & s)
binds[n].buffer_type = MYSQL_TYPE_STRING;
// NOLINTNEXTLINE(hicpp-no-malloc)
binds[n].buffer = realloc(binds[n].buffer, s.length());
- s.copy(static_cast<char*>(binds[n].buffer), s.length(), 0);
+ s.copy(static_cast<char *>(binds[n].buffer), s.length(), 0);
binds[n].buffer_length = s.length();
binds[n].is_unsigned = false;
}
@@ -124,7 +121,7 @@ MySQL::Command::bindParamT(unsigned int n, const boost::posix_time::ptime & v)
binds[n].buffer_type = MYSQL_TYPE_DATETIME;
// NOLINTNEXTLINE(hicpp-no-malloc)
binds[n].buffer = realloc(binds[n].buffer, sizeof(MYSQL_TIME));
- MYSQL_TIME & ts = *static_cast<MYSQL_TIME*>(binds[n].buffer);
+ MYSQL_TIME & ts = *static_cast<MYSQL_TIME *>(binds[n].buffer);
ts.year = v.date().year();
ts.month = v.date().month();
ts.day = v.date().day();
@@ -140,7 +137,7 @@ MySQL::Command::bindParamT(unsigned int n, const boost::posix_time::time_duratio
binds[n].buffer_type = MYSQL_TYPE_TIME;
// NOLINTNEXTLINE(hicpp-no-malloc)
binds[n].buffer = realloc(binds[n].buffer, sizeof(MYSQL_TIME));
- MYSQL_TIME & ts = *static_cast<MYSQL_TIME*>(binds[n].buffer);
+ MYSQL_TIME & ts = *static_cast<MYSQL_TIME *>(binds[n].buffer);
ts.year = 0;
ts.month = 0;
ts.day = 0;
@@ -169,5 +166,3 @@ MySQL::Command::bindParams()
}
}
}
-
-
diff --git a/libmysqlpp/my-command.h b/libmysqlpp/my-command.h
index ddb2d11..53f37c5 100644
--- a/libmysqlpp/my-command.h
+++ b/libmysqlpp/my-command.h
@@ -8,41 +8,40 @@
namespace MySQL {
class Connection;
class Command : public virtual DB::Command {
- public:
- Command(const Connection *, const std::string & sql);
- virtual ~Command() = 0;
-
- void bindParamI(unsigned int, int) override;
- void bindParamI(unsigned int, long int) override;
- void bindParamI(unsigned int, long long int) override;
- void bindParamI(unsigned int, unsigned int) override;
- void bindParamI(unsigned int, long unsigned int) override;
- void bindParamI(unsigned int, long long unsigned int) override;
-
- void bindParamB(unsigned int, bool) override;
-
- void bindParamF(unsigned int, double) override;
- void bindParamF(unsigned int, float) override;
-
- void bindParamS(unsigned int, const Glib::ustring&) override;
- void bindParamS(unsigned int, const std::string_view&) override;
-
- void bindParamT(unsigned int, const boost::posix_time::time_duration &) override;
- void bindParamT(unsigned int, const boost::posix_time::ptime &) override;
-
- void bindNull(unsigned int) override;
- protected:
- void bindParams();
- void * realloc(void * buffer, size_t size);
-
- const Connection * c;
- MYSQL_STMT * stmt;
- typedef std::vector<MYSQL_BIND> Binds;
- Binds binds;
- bool paramsNeedBinding;
+ public:
+ Command(const Connection *, const std::string & sql);
+ virtual ~Command() = 0;
+
+ void bindParamI(unsigned int, int) override;
+ void bindParamI(unsigned int, long int) override;
+ void bindParamI(unsigned int, long long int) override;
+ void bindParamI(unsigned int, unsigned int) override;
+ void bindParamI(unsigned int, long unsigned int) override;
+ void bindParamI(unsigned int, long long unsigned int) override;
+
+ void bindParamB(unsigned int, bool) override;
+
+ void bindParamF(unsigned int, double) override;
+ void bindParamF(unsigned int, float) override;
+
+ void bindParamS(unsigned int, const Glib::ustring &) override;
+ void bindParamS(unsigned int, const std::string_view &) override;
+
+ void bindParamT(unsigned int, const boost::posix_time::time_duration &) override;
+ void bindParamT(unsigned int, const boost::posix_time::ptime &) override;
+
+ void bindNull(unsigned int) override;
+
+ protected:
+ void bindParams();
+ void * realloc(void * buffer, size_t size);
+
+ const Connection * c;
+ MYSQL_STMT * stmt;
+ typedef std::vector<MYSQL_BIND> Binds;
+ Binds binds;
+ bool paramsNeedBinding;
};
}
#endif
-
-
diff --git a/libmysqlpp/my-connection.cpp b/libmysqlpp/my-connection.cpp
index 63f4932..6e4d1a1 100644
--- a/libmysqlpp/my-connection.cpp
+++ b/libmysqlpp/my-connection.cpp
@@ -1,31 +1,31 @@
#include "my-connection.h"
#include "my-error.h"
-#include "my-selectcommand.h"
#include "my-modifycommand.h"
+#include "my-selectcommand.h"
+#include <compileTimeFormatter.h>
#include <nvpParse.h>
+#include <optional>
#include <runtimeContext.h>
#include <ucontext.h>
-#include <optional>
-#include <compileTimeFormatter.h>
NAMEDFACTORY("mysql", MySQL::Connection, DB::ConnectionFactory);
-MySQL::ConnectionError::ConnectionError(MYSQL * m) :
- MySQL::Error(m)
-{
-}
+MySQL::ConnectionError::ConnectionError(MYSQL * m) : MySQL::Error(m) { }
class Opts {
- public:
- Opts() { port = 3306; }
- using OptString = std::optional<std::string>;
- OptString server;
- OptString user;
- OptString password;
- OptString database;
- unsigned int port;
- OptString unix_socket;
- OptString options;
+public:
+ Opts()
+ {
+ port = 3306;
+ }
+ using OptString = std::optional<std::string>;
+ OptString server;
+ OptString user;
+ OptString password;
+ OptString database;
+ unsigned int port;
+ OptString unix_socket;
+ OptString options;
};
const char *
@@ -38,7 +38,7 @@ operator~(const Opts::OptString & os)
}
namespace std {
- template <typename T>
+ template<typename T>
std::istream &
operator>>(std::istream & s, std::optional<T> & o)
{
@@ -49,18 +49,16 @@ namespace std {
using namespace AdHoc;
NvpTarget(Opts) OptsTargetMap {
- NvpValue(Opts, server),
- NvpValue(Opts, user),
- NvpValue(Opts, password),
- NvpValue(Opts, database),
- NvpValue(Opts, unix_socket),
- NvpValue(Opts, port),
- NvpValue(Opts, options),
+ NvpValue(Opts, server),
+ NvpValue(Opts, user),
+ NvpValue(Opts, password),
+ NvpValue(Opts, database),
+ NvpValue(Opts, unix_socket),
+ NvpValue(Opts, port),
+ NvpValue(Opts, options),
};
-
-MySQL::Connection::Connection(const std::string & str) :
- conn({})
+MySQL::Connection::Connection(const std::string & str) : conn({})
{
std::stringstream i(str);
Opts o;
@@ -128,7 +126,6 @@ MySQL::Connection::ping() const
}
}
-
DB::SelectCommandPtr
MySQL::Connection::select(const std::string & sql, const DB::CommandOptionsCPtr &)
{
@@ -143,53 +140,55 @@ MySQL::Connection::modify(const std::string & sql, const DB::CommandOptionsCPtr
namespace MySQL {
class LoadContext : public AdHoc::System::RuntimeContext {
- public:
- explicit LoadContext(MYSQL * c) :
- loadBuf(nullptr),
- loadBufLen(0),
- bufOff(0),
- conn(c),
- loadReturn(0)
- {
- }
+ public:
+ explicit LoadContext(MYSQL * c) : loadBuf(nullptr), loadBufLen(0), bufOff(0), conn(c), loadReturn(0) { }
- static int local_infile_init(void ** ptr, const char *, void * ctx) {
- *ptr = ctx;
- return 0;
- }
+ static int
+ local_infile_init(void ** ptr, const char *, void * ctx)
+ {
+ *ptr = ctx;
+ return 0;
+ }
- static int local_infile_read(void * obj, char * buf, unsigned int bufSize) {
- auto ctx = static_cast<LoadContext *>(obj);
- if (ctx->loadBufLen - ctx->bufOff == 0) {
- ctx->swapContext();
- if (ctx->loadBufLen - ctx->bufOff <= 0) {
- // Nothing to do or error
- return ctx->bufOff;
- }
+ static int
+ local_infile_read(void * obj, char * buf, unsigned int bufSize)
+ {
+ auto ctx = static_cast<LoadContext *>(obj);
+ if (ctx->loadBufLen - ctx->bufOff == 0) {
+ ctx->swapContext();
+ if (ctx->loadBufLen - ctx->bufOff <= 0) {
+ // Nothing to do or error
+ return ctx->bufOff;
}
- auto copy = std::min<size_t>(ctx->loadBufLen - ctx->bufOff, bufSize);
- memcpy(buf, ctx->loadBuf + ctx->bufOff, copy);
- ctx->bufOff += copy;
- return copy;
}
+ auto copy = std::min<size_t>(ctx->loadBufLen - ctx->bufOff, bufSize);
+ memcpy(buf, ctx->loadBuf + ctx->bufOff, copy);
+ ctx->bufOff += copy;
+ return copy;
+ }
- static void local_infile_end(void *) {
- }
+ static void
+ local_infile_end(void *)
+ {
+ }
- static int local_infile_error(void *, char*, unsigned int) {
- return 0;
- }
+ static int
+ local_infile_error(void *, char *, unsigned int)
+ {
+ return 0;
+ }
- void callback() override
- {
- loadReturn = mysql_read_query_result(conn);
- }
+ void
+ callback() override
+ {
+ loadReturn = mysql_read_query_result(conn);
+ }
- const char * loadBuf;
- size_t loadBufLen;
- size_t bufOff;
- MYSQL * conn;
- int loadReturn;
+ const char * loadBuf;
+ size_t loadBufLen;
+ size_t bufOff;
+ MYSQL * conn;
+ int loadReturn;
};
}
@@ -242,4 +241,3 @@ MySQL::Connection::insertId()
{
return mysql_insert_id(&conn);
}
-
diff --git a/libmysqlpp/my-connection.h b/libmysqlpp/my-connection.h
index 21b98b0..073acda 100644
--- a/libmysqlpp/my-connection.h
+++ b/libmysqlpp/my-connection.h
@@ -1,46 +1,45 @@
#ifndef MY_CONNECTION_H
#define MY_CONNECTION_H
-#include <connection.h>
#include "my-error.h"
-#include <mysql.h>
+#include <connection.h>
#include <memory>
+#include <mysql.h>
namespace MySQL {
class ConnectionError : public virtual Error, public virtual DB::ConnectionError {
- public:
- ConnectionError(MYSQL *);
+ public:
+ ConnectionError(MYSQL *);
};
class LoadContext;
class Connection : public DB::Connection {
- public:
- Connection(const std::string & info);
- ~Connection();
+ public:
+ Connection(const std::string & info);
+ ~Connection();
- void beginTxInt() override;
- void commitTxInt() override;
- void rollbackTxInt() override;
- void ping() const override;
- DB::BulkDeleteStyle bulkDeleteStyle() const override;
- DB::BulkUpdateStyle bulkUpdateStyle() const override;
+ void beginTxInt() override;
+ void commitTxInt() override;
+ void rollbackTxInt() override;
+ void ping() const override;
+ DB::BulkDeleteStyle bulkDeleteStyle() const override;
+ DB::BulkUpdateStyle bulkUpdateStyle() const override;
- DB::SelectCommandPtr select(const std::string & sql, const DB::CommandOptionsCPtr &) override;
- DB::ModifyCommandPtr modify(const std::string & sql, const DB::CommandOptionsCPtr &) override;
+ DB::SelectCommandPtr select(const std::string & sql, const DB::CommandOptionsCPtr &) override;
+ DB::ModifyCommandPtr modify(const std::string & sql, const DB::CommandOptionsCPtr &) override;
- void beginBulkUpload(const char *, const char *) override;
- void endBulkUpload(const char *) override;
- size_t bulkUploadData(const char *, size_t) const override;
+ void beginBulkUpload(const char *, const char *) override;
+ void endBulkUpload(const char *) override;
+ size_t bulkUploadData(const char *, size_t) const override;
- int64_t insertId() override;
+ int64_t insertId() override;
- mutable MYSQL conn;
+ mutable MYSQL conn;
- private:
- mutable std::unique_ptr<LoadContext> ctx;
+ private:
+ mutable std::unique_ptr<LoadContext> ctx;
};
}
#endif
-
diff --git a/libmysqlpp/my-error.cpp b/libmysqlpp/my-error.cpp
index f563236..1af24ea 100644
--- a/libmysqlpp/my-error.cpp
+++ b/libmysqlpp/my-error.cpp
@@ -1,19 +1,12 @@
#include "my-error.h"
#include <cstring>
-MySQL::Error::Error(MYSQL * m) :
- msg(mysql_error(m))
-{
-}
+MySQL::Error::Error(MYSQL * m) : msg(mysql_error(m)) { }
-MySQL::Error::Error(MYSQL_STMT * m) :
- msg(mysql_stmt_error(m))
-{
-}
+MySQL::Error::Error(MYSQL_STMT * m) : msg(mysql_stmt_error(m)) { }
std::string
MySQL::Error::message() const noexcept
{
return msg;
}
-
diff --git a/libmysqlpp/my-error.h b/libmysqlpp/my-error.h
index b48c4a6..85fff63 100644
--- a/libmysqlpp/my-error.h
+++ b/libmysqlpp/my-error.h
@@ -2,20 +2,19 @@
#define MY_ERROR_H
#include <error.h>
-#include <mysql.h>
#include <exception.h>
+#include <mysql.h>
namespace MySQL {
class Error : public AdHoc::Exception<DB::Error> {
- public:
- explicit Error(MYSQL_STMT *);
- explicit Error(MYSQL *);
- std::string message() const noexcept override;
+ public:
+ explicit Error(MYSQL_STMT *);
+ explicit Error(MYSQL *);
+ std::string message() const noexcept override;
- private:
- std::string msg;
+ private:
+ std::string msg;
};
}
#endif
-
diff --git a/libmysqlpp/my-mock.cpp b/libmysqlpp/my-mock.cpp
index 3c03ba8..52d4899 100644
--- a/libmysqlpp/my-mock.cpp
+++ b/libmysqlpp/my-mock.cpp
@@ -1,29 +1,28 @@
-#include "my-connection.h"
#include "my-mock.h"
+#include "my-connection.h"
#include <compileTimeFormatter.h>
NAMEDFACTORY("mysql", MySQL::Mock, DB::MockDatabaseFactory);
namespace MySQL {
-Mock::Mock(const std::string & master, const std::string & name, const std::vector<std::filesystem::path> & ss) :
- MockServerDatabase(master, name, "mysql")
-{
- CreateNewDatabase();
- PlaySchemaScripts(ss);
-}
+ Mock::Mock(const std::string & master, const std::string & name, const std::vector<std::filesystem::path> & ss) :
+ MockServerDatabase(master, name, "mysql")
+ {
+ CreateNewDatabase();
+ PlaySchemaScripts(ss);
+ }
-AdHocFormatter(MockConnStr, "options=libdbpp;database=%?");
-DB::ConnectionPtr
-Mock::openConnection() const
-{
- return std::make_shared<Connection>(MockConnStr::get(testDbName));
-}
+ AdHocFormatter(MockConnStr, "options=libdbpp;database=%?");
+ DB::ConnectionPtr
+ Mock::openConnection() const
+ {
+ return std::make_shared<Connection>(MockConnStr::get(testDbName));
+ }
-Mock::~Mock()
-{
- DropDatabase();
-}
+ Mock::~Mock()
+ {
+ DropDatabase();
+ }
}
-
diff --git a/libmysqlpp/my-mock.h b/libmysqlpp/my-mock.h
index 6be9750..fca2b67 100644
--- a/libmysqlpp/my-mock.h
+++ b/libmysqlpp/my-mock.h
@@ -1,14 +1,14 @@
#ifndef MOCKMYSQLDATASOURCE_H
#define MOCKMYSQLDATASOURCE_H
-#include <mockDatabase.h>
+#include <c++11Helpers.h>
#include <filesystem>
+#include <mockDatabase.h>
#include <visibility.h>
-#include <c++11Helpers.h>
namespace MySQL {
-class DLL_PUBLIC Mock : public DB::MockServerDatabase {
+ class DLL_PUBLIC Mock : public DB::MockServerDatabase {
public:
Mock(const std::string & master, const std::string & name, const std::vector<std::filesystem::path> & ss);
~Mock() override;
@@ -17,9 +17,8 @@ class DLL_PUBLIC Mock : public DB::MockServerDatabase {
private:
[[nodiscard]] DB::ConnectionPtr openConnection() const override;
-};
+ };
}
#endif
-
diff --git a/libmysqlpp/my-modifycommand.cpp b/libmysqlpp/my-modifycommand.cpp
index 083603f..7610a27 100644
--- a/libmysqlpp/my-modifycommand.cpp
+++ b/libmysqlpp/my-modifycommand.cpp
@@ -1,12 +1,10 @@
#include "my-modifycommand.h"
+#include "connection.h"
#include "my-error.h"
#include <cstdlib>
-#include "connection.h"
MySQL::ModifyCommand::ModifyCommand(const Connection * conn, const std::string & sql) :
- DB::Command(sql),
- DB::ModifyCommand(sql),
- MySQL::Command(conn, sql)
+ DB::Command(sql), DB::ModifyCommand(sql), MySQL::Command(conn, sql)
{
}
@@ -23,4 +21,3 @@ MySQL::ModifyCommand::execute(bool anc)
}
return rows;
}
-
diff --git a/libmysqlpp/my-modifycommand.h b/libmysqlpp/my-modifycommand.h
index 0670adc..ec2753f 100644
--- a/libmysqlpp/my-modifycommand.h
+++ b/libmysqlpp/my-modifycommand.h
@@ -1,23 +1,20 @@
#ifndef MY_MODIFYCOMMAND_H
#define MY_MODIFYCOMMAND_H
-#include <modifycommand.h>
#include "my-command.h"
+#include <modifycommand.h>
namespace MySQL {
class Connection;
class ModifyCommand : public DB::ModifyCommand, public Command {
- public:
- ModifyCommand(const Connection *, const std::string & sql);
+ public:
+ ModifyCommand(const Connection *, const std::string & sql);
- unsigned int execute(bool) override;
+ unsigned int execute(bool) override;
- private:
- void prepare() const;
+ private:
+ void prepare() const;
};
}
#endif
-
-
-
diff --git a/libmysqlpp/my-selectcommand.cpp b/libmysqlpp/my-selectcommand.cpp
index bb7ca10..2bf336f 100644
--- a/libmysqlpp/my-selectcommand.cpp
+++ b/libmysqlpp/my-selectcommand.cpp
@@ -1,15 +1,11 @@
#include "my-selectcommand.h"
-#include "my-connection.h"
#include "my-column.h"
+#include "my-connection.h"
#include "my-error.h"
#include <cstring>
MySQL::SelectCommand::SelectCommand(const Connection * conn, const std::string & sql) :
- DB::Command(sql),
- DB::SelectCommand(sql),
- MySQL::Command(conn, sql),
- prepared(false),
- executed(false)
+ DB::Command(sql), DB::SelectCommand(sql), MySQL::Command(conn, sql), prepared(false), executed(false)
{
}
@@ -32,7 +28,8 @@ MySQL::SelectCommand::execute()
case MYSQL_TYPE_INT24:
case MYSQL_TYPE_LONGLONG:
case MYSQL_TYPE_YEAR:
- insertColumn(std::make_unique<Column<int64_t, MYSQL_TYPE_LONGLONG>>(fieldDefs[i].name, i, &fields[i]));
+ insertColumn(
+ std::make_unique<Column<int64_t, MYSQL_TYPE_LONGLONG>>(fieldDefs[i].name, i, &fields[i]));
break;
case MYSQL_TYPE_DECIMAL:
case MYSQL_TYPE_NEWDECIMAL:
@@ -43,10 +40,12 @@ MySQL::SelectCommand::execute()
case MYSQL_TYPE_TIMESTAMP:
case MYSQL_TYPE_DATE:
case MYSQL_TYPE_DATETIME:
- insertColumn(std::make_unique<Column<MYSQL_TIME, MYSQL_TYPE_DATETIME>>(fieldDefs[i].name, i, &fields[i]));
+ insertColumn(std::make_unique<Column<MYSQL_TIME, MYSQL_TYPE_DATETIME>>(
+ fieldDefs[i].name, i, &fields[i]));
break;
case MYSQL_TYPE_TIME:
- insertColumn(std::make_unique<Column<MYSQL_TIME, MYSQL_TYPE_TIME>>(fieldDefs[i].name, i, &fields[i]));
+ insertColumn(
+ std::make_unique<Column<MYSQL_TIME, MYSQL_TYPE_TIME>>(fieldDefs[i].name, i, &fields[i]));
break;
case MYSQL_TYPE_STRING:
case MYSQL_TYPE_VAR_STRING:
@@ -96,4 +95,3 @@ MySQL::SelectCommand::fetch()
throw Error(stmt);
}
}
-
diff --git a/libmysqlpp/my-selectcommand.h b/libmysqlpp/my-selectcommand.h
index b9a0edc..9613731 100644
--- a/libmysqlpp/my-selectcommand.h
+++ b/libmysqlpp/my-selectcommand.h
@@ -1,26 +1,24 @@
#ifndef MY_SELECTCOMMAND_H
#define MY_SELECTCOMMAND_H
-#include <selectcommand.h>
#include "my-command.h"
+#include <selectcommand.h>
namespace MySQL {
class Connection;
class ColumnBase;
class SelectCommand : public DB::SelectCommand, public Command {
- public:
- SelectCommand(const Connection *, const std::string & sql);
+ public:
+ SelectCommand(const Connection *, const std::string & sql);
- bool fetch() override;
- void execute() override;
+ bool fetch() override;
+ void execute() override;
- private:
- bool prepared;
- bool executed;
- Binds fields;
+ private:
+ bool prepared;
+ bool executed;
+ Binds fields;
};
}
#endif
-
-
diff --git a/libmysqlpp/unittests/testmysql.cpp b/libmysqlpp/unittests/testmysql.cpp
index 17f807e..2f60e68 100644
--- a/libmysqlpp/unittests/testmysql.cpp
+++ b/libmysqlpp/unittests/testmysql.cpp
@@ -1,30 +1,29 @@
#define BOOST_TEST_MODULE TestMySQL
#include <boost/test/unit_test.hpp>
-#include <my-mock.h>
-#include <my-error.h>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <column.h>
+#include <connection.h>
#include <definedDirs.h>
+#include <fstream>
#include <modifycommand.h>
+#include <my-error.h>
+#include <my-mock.h>
#include <selectcommand.h>
-#include <column.h>
-#include <connection.h>
#include <testCore.h>
-#include <fstream>
-#include <boost/date_time/posix_time/posix_time.hpp>
class StandardMockDatabase : public DB::PluginMock<MySQL::Mock> {
- public:
- StandardMockDatabase() : DB::PluginMock<MySQL::Mock>("mysqlmock", {
- rootDir / "mysqlschema.sql" }, "options=libdbpp")
- {
- }
+public:
+ StandardMockDatabase() : DB::PluginMock<MySQL::Mock>("mysqlmock", {rootDir / "mysqlschema.sql"}, "options=libdbpp")
+ {
+ }
};
-BOOST_GLOBAL_FIXTURE( StandardMockDatabase );
+BOOST_GLOBAL_FIXTURE(StandardMockDatabase);
-BOOST_FIXTURE_TEST_SUITE( Core, DB::TestCore );
+BOOST_FIXTURE_TEST_SUITE(Core, DB::TestCore);
-BOOST_AUTO_TEST_CASE( transactions )
+BOOST_AUTO_TEST_CASE(transactions)
{
auto ro = DB::MockDatabase::openConnectionTo("mysqlmock");
@@ -40,7 +39,7 @@ BOOST_AUTO_TEST_CASE( transactions )
BOOST_REQUIRE_EQUAL(false, ro->inTx());
}
-BOOST_AUTO_TEST_CASE( bindAndSend )
+BOOST_AUTO_TEST_CASE(bindAndSend)
{
auto rw = DB::MockDatabase::openConnectionTo("mysqlmock");
@@ -54,7 +53,7 @@ BOOST_AUTO_TEST_CASE( bindAndSend )
mod->execute();
}
-BOOST_AUTO_TEST_CASE( bindAndSelect )
+BOOST_AUTO_TEST_CASE(bindAndSelect)
{
auto ro = DB::MockDatabase::openConnectionTo("mysqlmock");
@@ -74,7 +73,7 @@ BOOST_AUTO_TEST_CASE( bindAndSelect )
BOOST_REQUIRE_EQUAL(1, rows);
}
-BOOST_AUTO_TEST_CASE( bindAndSelectOther )
+BOOST_AUTO_TEST_CASE(bindAndSelectOther)
{
auto ro = DB::MockDatabase::openConnectionTo("mysqlmock");
@@ -87,14 +86,15 @@ BOOST_AUTO_TEST_CASE( bindAndSelectOther )
assertColumnValueHelper(*select, 1, 123.45);
assertColumnValueHelper(*select, 2, std::string_view("some text"));
assertColumnValueHelper(*select, 3, true);
- assertColumnValueHelper(*select, 4, boost::posix_time::ptime_from_tm({ 3, 6, 23, 27, 3, 115, 0, 0, 0, 0, nullptr}));
+ assertColumnValueHelper(
+ *select, 4, boost::posix_time::ptime_from_tm({3, 6, 23, 27, 3, 115, 0, 0, 0, 0, nullptr}));
assertColumnValueHelper(*select, 5, boost::posix_time::time_duration(38, 13, 12));
rows += 1;
}
BOOST_REQUIRE_EQUAL(1, rows);
}
-BOOST_AUTO_TEST_CASE( bulkload )
+BOOST_AUTO_TEST_CASE(bulkload)
{
auto ro = DB::MockDatabase::openConnectionTo("mysqlmock");
@@ -110,14 +110,14 @@ BOOST_AUTO_TEST_CASE( bulkload )
throw std::runtime_error("Couldn't open bulk.sample");
}
std::array<char, BUFSIZ> buf {};
- for (std::streamsize r; (r = in.readsome(buf.data(), buf.size())) > 0; ) {
+ for (std::streamsize r; (r = in.readsome(buf.data(), buf.size())) > 0;) {
ro->bulkUploadData(buf.data(), r);
}
ro->endBulkUpload(nullptr);
assertScalarValueHelper(*count, 800);
}
-BOOST_AUTO_TEST_CASE( bigIterate )
+BOOST_AUTO_TEST_CASE(bigIterate)
{
auto ro = DB::MockDatabase::openConnectionTo("mysqlmock");
@@ -129,12 +129,12 @@ BOOST_AUTO_TEST_CASE( bigIterate )
BOOST_REQUIRE_EQUAL(800, rows);
}
-BOOST_AUTO_TEST_CASE( insertId )
+BOOST_AUTO_TEST_CASE(insertId)
{
auto ro = DB::MockDatabase::openConnectionTo("mysqlmock");
auto ins = ro->modify("INSERT INTO inserts(num) VALUES(?)");
int prevId = 0;
- for (int n : { 4, 40, -4 }) {
+ for (int n : {4, 40, -4}) {
ins->bindParamI(0, n);
ins->execute();
auto id = ro->insertId();
@@ -143,14 +143,11 @@ BOOST_AUTO_TEST_CASE( insertId )
}
}
-BOOST_AUTO_TEST_CASE( errors )
+BOOST_AUTO_TEST_CASE(errors)
{
auto ro = DB::MockDatabase::openConnectionTo("mysqlmock");
BOOST_REQUIRE_THROW(ro->execute("nonsense"), DB::Error);
- BOOST_REQUIRE_THROW(
- (void)DB::ConnectionFactory::createNew("mysql", "server=nohost"),
- DB::ConnectionError);
+ BOOST_REQUIRE_THROW((void)DB::ConnectionFactory::createNew("mysql", "server=nohost"), DB::ConnectionError);
}
BOOST_AUTO_TEST_SUITE_END();
-