2
0
mirror of https://github.com/boostorg/mysql.git synced 2026-02-14 12:52:17 +00:00

Row reading reworks

- Removed distinction between row and owning_row
- Changed semantics for fetch_one to row& + bool
- Renamed all fetch_* fns to read_*
- Added row.clear()
This commit is contained in:
Ruben Perez
2021-02-19 21:23:40 +01:00
parent dd2447c6cb
commit 4c7ca0a1b4
38 changed files with 798 additions and 507 deletions

View File

@@ -6,13 +6,87 @@
//
#include "boost/mysql/row.hpp"
#include "boost/mysql/connection.hpp"
#include "boost/mysql/detail/auxiliar/bytestring.hpp"
#include "boost/mysql/value.hpp"
#include "test_common.hpp"
#include <boost/test/unit_test_suite.hpp>
#include <boost/utility/string_view_fwd.hpp>
#include <vector>
using namespace boost::mysql::test;
using boost::mysql::row;
using boost::mysql::value;
using boost::mysql::detail::bytestring;
BOOST_AUTO_TEST_SUITE(test_row)
// Constructors
BOOST_AUTO_TEST_SUITE(constructors)
static std::vector<value> string_value_from_buffer(const bytestring& buffer)
{
return make_value_vector(boost::string_view(reinterpret_cast<const char*>(buffer.data()), buffer.size()));
}
BOOST_AUTO_TEST_CASE(init_ctor)
{
// Given a value vector with strings pointing into a buffer, after initializing
// the row via moves, the string still points to valid memory
bytestring buffer {'a', 'b', 'c', 'd'};
auto values = string_value_from_buffer(buffer);
row r (std::move(values), std::move(buffer));
buffer = {'e', 'f'};
BOOST_TEST(r.values()[0] == value("abcd"));
}
BOOST_AUTO_TEST_CASE(move_ctor)
{
// Given a row with strings, after a move construction,
// the string still points to valid memory
bytestring buffer {'a', 'b', 'c', 'd'};
auto values = string_value_from_buffer(buffer);
row r (std::move(values), std::move(buffer));
row r2 (std::move(r));
r = row({}, {'e', 'f'});
BOOST_TEST(r2.values()[0] == value("abcd"));
}
BOOST_AUTO_TEST_CASE(move_assignment)
{
// Given a row with strings, after a move assignment,
// the string still points to valid memory
bytestring buffer {'a', 'b', 'c', 'd'};
auto values = string_value_from_buffer(buffer);
row r (std::move(values), std::move(buffer));
row r2;
r2 = std::move(r);
r = row({}, {'e', 'f'});
BOOST_TEST(r2.values()[0] == value("abcd"));
}
BOOST_AUTO_TEST_SUITE_END()
// Clear
BOOST_AUTO_TEST_SUITE(clear)
BOOST_AUTO_TEST_CASE(empty_row)
{
row r;
r.clear();
BOOST_TEST(r.values().empty());
}
BOOST_AUTO_TEST_CASE(non_empty_row)
{
row r = makerow("abc");
r.clear();
BOOST_TEST(r.values().empty());
}
BOOST_AUTO_TEST_SUITE_END()
// Equality operators
BOOST_AUTO_TEST_SUITE(operators_eq_ne)