From c25edfb75a65b80a0e0c43bbaf59c7cd806f0b5b Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 30 Mar 2019 11:43:04 +0000 Subject: Tidy fixes for latest clang --- libmysqlpp/my-column.h | 2 +- libmysqlpp/my-command.cpp | 64 ++++++++++++++--------------------------- libmysqlpp/my-connection.cpp | 6 ++-- libmysqlpp/my-selectcommand.cpp | 2 +- 4 files changed, 26 insertions(+), 48 deletions(-) diff --git a/libmysqlpp/my-column.h b/libmysqlpp/my-column.h index be1d41d..2b59a49 100644 --- a/libmysqlpp/my-column.h +++ b/libmysqlpp/my-column.h @@ -10,7 +10,7 @@ namespace MySQL { public: ColumnBase(const char * name, unsigned int field); - bool isNull() const override; + [[nodiscard]] bool isNull() const override; protected: my_bool is_null; diff --git a/libmysqlpp/my-command.cpp b/libmysqlpp/my-command.cpp index fa1ebef..380d1f9 100644 --- a/libmysqlpp/my-command.cpp +++ b/libmysqlpp/my-command.cpp @@ -2,6 +2,7 @@ #include "my-connection.h" #include #include +#include MySQL::Command::Command(const Connection * conn, const std::string & sql) : DB::Command(sql), @@ -45,84 +46,61 @@ MySQL::Command::realloc(void * buffer, size_t size) return newBuffer; } +template void -MySQL::Command::bindParamI(unsigned int n, int v) +bindNumber(MYSQL_BIND & bind, const P & v) { - binds[n].buffer_type = MYSQL_TYPE_LONG; + bind.buffer_type = b; // NOLINTNEXTLINE(hicpp-no-malloc) - binds[n].buffer = realloc(binds[n].buffer, sizeof(int)); - *static_cast(binds[n].buffer) = v; - binds[n].is_unsigned = 0; + bind.buffer = realloc(bind.buffer, sizeof(B)); + *static_cast(bind.buffer) = boost::numeric_cast(v); + bind.is_unsigned = std::is_unsigned

::value; +} + +void +MySQL::Command::bindParamI(unsigned int n, int v) +{ + bindNumber(binds[n], v); } void MySQL::Command::bindParamI(unsigned int n, long int v) { - binds[n].buffer_type = MYSQL_TYPE_LONGLONG; - // NOLINTNEXTLINE(hicpp-no-malloc) - binds[n].buffer = realloc(binds[n].buffer, sizeof(long long int)); - *static_cast(binds[n].buffer) = v; - binds[n].is_unsigned = 0; + bindNumber(binds[n], v); } void MySQL::Command::bindParamI(unsigned int n, long long int v) { - binds[n].buffer_type = MYSQL_TYPE_LONGLONG; - // NOLINTNEXTLINE(hicpp-no-malloc) - binds[n].buffer = realloc(binds[n].buffer, sizeof(long long int)); - *static_cast(binds[n].buffer) = v; - binds[n].is_unsigned = 0; + bindNumber(binds[n], v); } void MySQL::Command::bindParamI(unsigned int n, unsigned int v) { - binds[n].buffer_type = MYSQL_TYPE_LONG; - // NOLINTNEXTLINE(hicpp-no-malloc) - binds[n].buffer = realloc(binds[n].buffer, sizeof(int)); - *static_cast(binds[n].buffer) = v; - binds[n].is_unsigned = 1; + bindNumber(binds[n], v); } void MySQL::Command::bindParamI(unsigned int n, long unsigned int v) { - binds[n].buffer_type = MYSQL_TYPE_LONGLONG; - // NOLINTNEXTLINE(hicpp-no-malloc) - binds[n].buffer = realloc(binds[n].buffer, sizeof(long long int)); - *static_cast(binds[n].buffer) = v; - binds[n].is_unsigned = 1; + bindNumber(binds[n], v); } void MySQL::Command::bindParamI(unsigned int n, long long unsigned int v) { - binds[n].buffer_type = MYSQL_TYPE_LONGLONG; - // NOLINTNEXTLINE(hicpp-no-malloc) - binds[n].buffer = realloc(binds[n].buffer, sizeof(long long int)); - *static_cast(binds[n].buffer) = v; - binds[n].is_unsigned = 1; + bindNumber(binds[n], v); } void MySQL::Command::bindParamB(unsigned int n, bool v) { - binds[n].buffer_type = MYSQL_TYPE_TINY; - // NOLINTNEXTLINE(hicpp-no-malloc) - binds[n].buffer = realloc(binds[n].buffer, sizeof(bool)); - *static_cast(binds[n].buffer) = (v ? 1 : 0); - binds[n].is_unsigned = 1; + bindNumber(binds[n], (v ? 1 : 0)); } void MySQL::Command::bindParamF(unsigned int n, double v) { - binds[n].buffer_type = MYSQL_TYPE_DOUBLE; - // NOLINTNEXTLINE(hicpp-no-malloc) - binds[n].buffer = realloc(binds[n].buffer, sizeof(double)); - *static_cast(binds[n].buffer) = v; + bindNumber(binds[n], v); } void MySQL::Command::bindParamF(unsigned int n, float v) { - binds[n].buffer_type = MYSQL_TYPE_FLOAT; - // NOLINTNEXTLINE(hicpp-no-malloc) - binds[n].buffer = realloc(binds[n].buffer, sizeof(float)); - *static_cast(binds[n].buffer) = v; + bindNumber(binds[n], v); } void MySQL::Command::bindParamS(unsigned int n, const Glib::ustring & s) diff --git a/libmysqlpp/my-connection.cpp b/libmysqlpp/my-connection.cpp index 135ef34..e5193ac 100644 --- a/libmysqlpp/my-connection.cpp +++ b/libmysqlpp/my-connection.cpp @@ -167,7 +167,7 @@ namespace MySQL { return ctx->bufOff; } } - unsigned int copy = std::min(ctx->loadBufLen - ctx->bufOff, bufSize); + auto copy = std::min(ctx->loadBufLen - ctx->bufOff, bufSize); memcpy(buf, ctx->loadBuf + ctx->bufOff, copy); ctx->bufOff += copy; return copy; @@ -186,8 +186,8 @@ namespace MySQL { } const char * loadBuf; - unsigned int loadBufLen; - int bufOff; + size_t loadBufLen; + size_t bufOff; MYSQL * conn; int loadReturn; }; diff --git a/libmysqlpp/my-selectcommand.cpp b/libmysqlpp/my-selectcommand.cpp index 893f79f..bb7ca10 100644 --- a/libmysqlpp/my-selectcommand.cpp +++ b/libmysqlpp/my-selectcommand.cpp @@ -24,7 +24,7 @@ MySQL::SelectCommand::execute() } MYSQL_RES * prepare_meta_result = mysql_stmt_result_metadata(stmt); MYSQL_FIELD * fieldDefs = mysql_fetch_fields(prepare_meta_result); - for (unsigned int i = 0; i < fields.size(); i += 1) { + for (std::size_t i = 0; i < fields.size(); i += 1) { switch (fieldDefs[i].type) { case MYSQL_TYPE_TINY: case MYSQL_TYPE_SHORT: -- cgit v1.2.3