diff options
Diffstat (limited to 'libmysqlpp')
-rw-r--r-- | libmysqlpp/my-column.cpp | 2 | ||||
-rw-r--r-- | libmysqlpp/my-command.cpp | 12 | ||||
-rw-r--r-- | libmysqlpp/my-command.h | 1 | ||||
-rw-r--r-- | libmysqlpp/my-selectcommand.cpp | 12 | ||||
-rw-r--r-- | libmysqlpp/unittests/testmysql.cpp | 2 |
5 files changed, 18 insertions, 11 deletions
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 @@ -116,10 +116,16 @@ 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<char*>(binds[n].buffer), s.bytes()); - binds[n].buffer_length = s.bytes(); + 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(); 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<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: case MYSQL_TYPE_FLOAT: case MYSQL_TYPE_DOUBLE: - insertColumn(std::make_shared<Column<double, MYSQL_TYPE_DOUBLE>>(fieldDefs[i].name, i, &fields[i])); + insertColumn(std::make_unique<Column<double, MYSQL_TYPE_DOUBLE>>(fieldDefs[i].name, i, &fields[i])); break; case MYSQL_TYPE_TIMESTAMP: case MYSQL_TYPE_DATE: case MYSQL_TYPE_DATETIME: - insertColumn(std::make_shared<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_shared<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: - insertColumn(std::make_shared<StringColumn>(fieldDefs[i].name, i, &fields[i], fieldDefs[i].length)); + insertColumn(std::make_unique<StringColumn>(fieldDefs[i].name, i, &fields[i], fieldDefs[i].length)); break; case MYSQL_TYPE_NULL: - insertColumn(std::make_shared<NullColumn>(fieldDefs[i].name, i, &fields[i])); + insertColumn(std::make_unique<NullColumn>(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)); |