summaryrefslogtreecommitdiff
path: root/libmysqlpp
diff options
context:
space:
mode:
Diffstat (limited to 'libmysqlpp')
-rw-r--r--libmysqlpp/my-column.cpp16
-rw-r--r--libmysqlpp/my-column.h3
-rw-r--r--libmysqlpp/my-command.cpp15
-rw-r--r--libmysqlpp/my-connection.cpp9
-rw-r--r--libmysqlpp/my-modifycommand.h1
5 files changed, 29 insertions, 15 deletions
diff --git a/libmysqlpp/my-column.cpp b/libmysqlpp/my-column.cpp
index 488538e..403933c 100644
--- a/libmysqlpp/my-column.cpp
+++ b/libmysqlpp/my-column.cpp
@@ -5,7 +5,9 @@
#include <boost/date_time/gregorian/gregorian_types.hpp>
MySQL::ColumnBase::ColumnBase(const char * name, unsigned int i) :
- DB::Column(name, i)
+ DB::Column(name, i),
+ is_null(false),
+ length(0)
{
}
@@ -17,21 +19,17 @@ MySQL::ColumnBase::isNull() const
MySQL::StringColumn::StringColumn(const char * name, unsigned int field, MYSQL_BIND * b, unsigned int len) :
ColumnBase(name, field),
- value(new char[len])
+ value(len),
+ length(0)
{
b->is_null = &is_null;
b->buffer_type = MYSQL_TYPE_STRING;
b->is_unsigned = 0;
- b->buffer = value;
+ b->buffer = value.data();
b->buffer_length = len;
b->length = &length;
}
-MySQL::StringColumn::~StringColumn()
-{
- delete[] value;
-}
-
void
MySQL::StringColumn::apply(DB::HandleField & h) const
{
@@ -39,7 +37,7 @@ MySQL::StringColumn::apply(DB::HandleField & h) const
h.null();
}
else {
- h.string({ value, length });
+ h.string({ value.data(), length });
}
}
diff --git a/libmysqlpp/my-column.h b/libmysqlpp/my-column.h
index 0948146..be1d41d 100644
--- a/libmysqlpp/my-column.h
+++ b/libmysqlpp/my-column.h
@@ -21,11 +21,10 @@ namespace MySQL {
class StringColumn : public ColumnBase {
public:
StringColumn(const char * name, unsigned int field, MYSQL_BIND * b, unsigned int len);
- ~StringColumn();
void apply(DB::HandleField &) const override;
- char * value;
+ std::vector<char> value;
long unsigned int length;
};
diff --git a/libmysqlpp/my-command.cpp b/libmysqlpp/my-command.cpp
index c296be4..fa1ebef 100644
--- a/libmysqlpp/my-command.cpp
+++ b/libmysqlpp/my-command.cpp
@@ -28,6 +28,7 @@ MySQL::Command::Command(const Connection * conn, const std::string & sql) :
MySQL::Command::~Command()
{
for (auto & b : binds) {
+ // NOLINTNEXTLINE(hicpp-no-malloc)
free(b.buffer);
}
mysql_stmt_close(stmt);
@@ -36,6 +37,7 @@ MySQL::Command::~Command()
void *
MySQL::Command::realloc(void * buffer, size_t size)
{
+ // NOLINTNEXTLINE(hicpp-no-malloc)
void * newBuffer = ::realloc(buffer, size);
if (buffer != newBuffer) {
paramsNeedBinding = true;
@@ -47,6 +49,7 @@ void
MySQL::Command::bindParamI(unsigned int n, int v)
{
binds[n].buffer_type = MYSQL_TYPE_LONG;
+ // NOLINTNEXTLINE(hicpp-no-malloc)
binds[n].buffer = realloc(binds[n].buffer, sizeof(int));
*static_cast<int*>(binds[n].buffer) = v;
binds[n].is_unsigned = 0;
@@ -55,6 +58,7 @@ 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<long long int*>(binds[n].buffer) = v;
binds[n].is_unsigned = 0;
@@ -63,6 +67,7 @@ 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<long long int*>(binds[n].buffer) = v;
binds[n].is_unsigned = 0;
@@ -71,6 +76,7 @@ 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<int*>(binds[n].buffer) = v;
binds[n].is_unsigned = 1;
@@ -79,6 +85,7 @@ 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<long long int*>(binds[n].buffer) = v;
binds[n].is_unsigned = 1;
@@ -87,6 +94,7 @@ 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<long long int*>(binds[n].buffer) = v;
binds[n].is_unsigned = 1;
@@ -95,6 +103,7 @@ 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<bool*>(binds[n].buffer) = (v ? 1 : 0);
binds[n].is_unsigned = 1;
@@ -103,6 +112,7 @@ 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<double*>(binds[n].buffer) = v;
}
@@ -110,6 +120,7 @@ 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<float*>(binds[n].buffer) = v;
}
@@ -123,6 +134,7 @@ void
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);
binds[n].buffer_length = s.length();
@@ -132,6 +144,7 @@ void
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);
ts.year = v.date().year();
@@ -147,6 +160,7 @@ void
MySQL::Command::bindParamT(unsigned int n, const boost::posix_time::time_duration & v)
{
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);
ts.year = 0;
@@ -163,6 +177,7 @@ MySQL::Command::bindNull(unsigned int n)
{
binds[n].buffer_type = MYSQL_TYPE_NULL;
binds[n].buffer = nullptr;
+ // NOLINTNEXTLINE(hicpp-no-malloc)
free(binds[n].buffer);
}
diff --git a/libmysqlpp/my-connection.cpp b/libmysqlpp/my-connection.cpp
index 8ab2d08..135ef34 100644
--- a/libmysqlpp/my-connection.cpp
+++ b/libmysqlpp/my-connection.cpp
@@ -59,7 +59,8 @@ NvpTarget(Opts) OptsTargetMap {
};
-MySQL::Connection::Connection(const std::string & str)
+MySQL::Connection::Connection(const std::string & str) :
+ conn({})
{
std::stringstream i(str);
Opts o;
@@ -69,6 +70,7 @@ MySQL::Connection::Connection(const std::string & str)
mysql_options(&conn, MYSQL_READ_DEFAULT_GROUP, ~o.options);
}
if (!mysql_real_connect(&conn, ~o.server, ~o.user, ~o.password, ~o.database,
+ // NOLINTNEXTLINE(hicpp-signed-bitwise)
o.port, ~o.unix_socket, CLIENT_LOCAL_FILES | CLIENT_MULTI_STATEMENTS)) {
throw ConnectionError(&conn);
}
@@ -142,11 +144,12 @@ MySQL::Connection::modify(const std::string & sql, const DB::CommandOptionsCPtr
namespace MySQL {
class LoadContext : public AdHoc::System::RuntimeContext {
public:
- LoadContext(MYSQL * c) :
+ explicit LoadContext(MYSQL * c) :
loadBuf(nullptr),
loadBufLen(0),
bufOff(0),
- conn(c)
+ conn(c),
+ loadReturn(0)
{
}
diff --git a/libmysqlpp/my-modifycommand.h b/libmysqlpp/my-modifycommand.h
index d760f93..0670adc 100644
--- a/libmysqlpp/my-modifycommand.h
+++ b/libmysqlpp/my-modifycommand.h
@@ -14,7 +14,6 @@ namespace MySQL {
private:
void prepare() const;
- mutable bool prepared;
};
}