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-command.cpp | 64 ++++++++++++++++------------------------------- 1 file changed, 21 insertions(+), 43 deletions(-) (limited to 'libmysqlpp/my-command.cpp') 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) -- cgit v1.2.3