From a84a696a3812446a33761cc0b1669d0f5bbf9335 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 7 Feb 2019 19:35:18 +0000 Subject: Update to new libdbpp interface --- libmysqlpp/my-column.cpp | 2 +- libmysqlpp/my-command.cpp | 12 +++++++++--- libmysqlpp/my-command.h | 1 + libmysqlpp/my-selectcommand.cpp | 12 ++++++------ libmysqlpp/unittests/testmysql.cpp | 2 +- 5 files changed, 18 insertions(+), 11 deletions(-) (limited to 'libmysqlpp') diff --git a/libmysqlpp/my-column.cpp b/libmysqlpp/my-column.cpp index 14c0a58..c5521c7 100644 --- a/libmysqlpp/my-column.cpp +++ b/libmysqlpp/my-column.cpp @@ -39,7 +39,7 @@ MySQL::StringColumn::apply(DB::HandleField & h) const h.null(); } else { - h.string(value, length); + h.string({ value, length }); } } diff --git a/libmysqlpp/my-command.cpp b/libmysqlpp/my-command.cpp index defb8a7..4ad00fc 100644 --- a/libmysqlpp/my-command.cpp +++ b/libmysqlpp/my-command.cpp @@ -115,11 +115,17 @@ 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() }); +} + +void +MySQL::Command::bindParamS(unsigned int n, const std::string_view & s) { binds[n].buffer_type = MYSQL_TYPE_STRING; - binds[n].buffer = realloc(binds[n].buffer, s.bytes()); - s.copy(static_cast(binds[n].buffer), s.bytes()); - binds[n].buffer_length = s.bytes(); + binds[n].buffer = realloc(binds[n].buffer, s.length()); + s.copy(static_cast(binds[n].buffer), s.length(), 0); + binds[n].buffer_length = s.length(); binds[n].is_unsigned = 0; } void diff --git a/libmysqlpp/my-command.h b/libmysqlpp/my-command.h index 71f7d51..ddb2d11 100644 --- a/libmysqlpp/my-command.h +++ b/libmysqlpp/my-command.h @@ -25,6 +25,7 @@ namespace MySQL { 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; diff --git a/libmysqlpp/my-selectcommand.cpp b/libmysqlpp/my-selectcommand.cpp index 248e714..596c9a0 100644 --- a/libmysqlpp/my-selectcommand.cpp +++ b/libmysqlpp/my-selectcommand.cpp @@ -32,28 +32,28 @@ MySQL::SelectCommand::execute() case MYSQL_TYPE_INT24: case MYSQL_TYPE_LONGLONG: case MYSQL_TYPE_YEAR: - insertColumn(std::make_shared>(fieldDefs[i].name, i, &fields[i])); + insertColumn(std::make_unique>(fieldDefs[i].name, i, &fields[i])); break; case MYSQL_TYPE_DECIMAL: case MYSQL_TYPE_NEWDECIMAL: case MYSQL_TYPE_FLOAT: case MYSQL_TYPE_DOUBLE: - insertColumn(std::make_shared>(fieldDefs[i].name, i, &fields[i])); + insertColumn(std::make_unique>(fieldDefs[i].name, i, &fields[i])); break; case MYSQL_TYPE_TIMESTAMP: case MYSQL_TYPE_DATE: case MYSQL_TYPE_DATETIME: - insertColumn(std::make_shared>(fieldDefs[i].name, i, &fields[i])); + insertColumn(std::make_unique>(fieldDefs[i].name, i, &fields[i])); break; case MYSQL_TYPE_TIME: - insertColumn(std::make_shared>(fieldDefs[i].name, i, &fields[i])); + insertColumn(std::make_unique>(fieldDefs[i].name, i, &fields[i])); break; case MYSQL_TYPE_STRING: case MYSQL_TYPE_VAR_STRING: - insertColumn(std::make_shared(fieldDefs[i].name, i, &fields[i], fieldDefs[i].length)); + insertColumn(std::make_unique(fieldDefs[i].name, i, &fields[i], fieldDefs[i].length)); break; case MYSQL_TYPE_NULL: - insertColumn(std::make_shared(fieldDefs[i].name, i, &fields[i])); + insertColumn(std::make_unique(fieldDefs[i].name, i, &fields[i])); break; case MYSQL_TYPE_BIT: case MYSQL_TYPE_BLOB: diff --git a/libmysqlpp/unittests/testmysql.cpp b/libmysqlpp/unittests/testmysql.cpp index 04e7212..434ce40 100644 --- a/libmysqlpp/unittests/testmysql.cpp +++ b/libmysqlpp/unittests/testmysql.cpp @@ -85,7 +85,7 @@ BOOST_AUTO_TEST_CASE( bindAndSelectOther ) while (select->fetch()) { assertColumnValueHelper(*select, 0, 4); assertColumnValueHelper(*select, 1, 123.45); - assertColumnValueHelper(*select, 2, std::string("some text")); + 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, 0})); assertColumnValueHelper(*select, 5, boost::posix_time::time_duration(38, 13, 12)); -- cgit v1.2.3