mirror of
https://github.com/boostorg/mysql.git
synced 2026-02-14 00:42:53 +00:00
Now years are represented as plain ints
Now values do not have ::date::year as an option; represented as plain uint32_t instead
This commit is contained in:
1
TODO.txt
1
TODO.txt
@@ -32,3 +32,4 @@ Technical debt
|
||||
Force the same number of values in each row as in fields()
|
||||
CMake exporting?
|
||||
Integration test for network errors (e.g. host unreachable)
|
||||
Refactor file structucture for serialization and tests
|
||||
|
||||
@@ -22,7 +22,6 @@ template <> struct get_serializable_type<std::int64_t> { using type = int8_signe
|
||||
template <> struct get_serializable_type<float> { using type = value_holder<float>; };
|
||||
template <> struct get_serializable_type<double> { using type = value_holder<double>; };
|
||||
template <> struct get_serializable_type<std::string_view> { using type = string_lenenc; };
|
||||
template <> struct get_serializable_type<year> { using type = int2; };
|
||||
template <> struct get_serializable_type<nullptr_t> { using type = dummy_serializable; };
|
||||
|
||||
template <typename T>
|
||||
@@ -31,11 +30,6 @@ inline get_serializable_type_t<T> to_serializable_type(T input) noexcept
|
||||
return get_serializable_type_t<T>(input);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline get_serializable_type_t<year> to_serializable_type(year input) noexcept
|
||||
{
|
||||
return get_serializable_type_t<year>(static_cast<int>(input));
|
||||
}
|
||||
|
||||
inline Error deserialize_binary_date(date& output, std::uint8_t length, DeserializationContext& ctx) noexcept
|
||||
{
|
||||
|
||||
@@ -29,7 +29,6 @@ inline protocol_field_type get_protocol_field_type(
|
||||
constexpr auto operator()(date) const noexcept { return protocol_field_type::date; }
|
||||
constexpr auto operator()(datetime) const noexcept { return protocol_field_type::datetime; }
|
||||
constexpr auto operator()(time) const noexcept { return protocol_field_type::time; }
|
||||
constexpr auto operator()(year) const noexcept { return protocol_field_type::short_; }
|
||||
constexpr auto operator()(std::nullptr_t) const noexcept { return protocol_field_type::null; }
|
||||
};
|
||||
return std::visit(visitor(), input);
|
||||
@@ -45,8 +44,7 @@ inline bool is_unsigned(
|
||||
return std::visit([](auto v) {
|
||||
using type = decltype(v);
|
||||
return std::is_same_v<type, std::uint32_t> ||
|
||||
std::is_same_v<type, std::uint64_t> ||
|
||||
std::is_same_v<type, year>;
|
||||
std::is_same_v<type, std::uint64_t>;
|
||||
}, input);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "mysql/error.hpp"
|
||||
#include "mysql/value.hpp"
|
||||
#include "mysql/metadata.hpp"
|
||||
#include "mysql/value.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace mysql
|
||||
|
||||
@@ -113,15 +113,6 @@ inline Error deserialize_text_value_impl(std::string_view from, std::string_view
|
||||
return Error::ok;
|
||||
}
|
||||
|
||||
inline Error deserialize_text_value_impl(std::string_view from, year& to)
|
||||
{
|
||||
int value;
|
||||
auto err = deserialize_text_value_impl(from, value);
|
||||
if (err != Error::ok) return err;
|
||||
to = year(value);
|
||||
return to.ok() ? Error::ok : Error::protocol_value_error;
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
Error deserialize_text_value_to_variant(std::string_view from, value& to, Args&&... args)
|
||||
{
|
||||
@@ -166,6 +157,7 @@ inline mysql::Error mysql::detail::deserialize_text_value(
|
||||
case protocol_field_type::short_:
|
||||
case protocol_field_type::int24:
|
||||
case protocol_field_type::long_:
|
||||
case protocol_field_type::year:
|
||||
return meta.is_unsigned() ?
|
||||
deserialize_text_value_to_variant<std::uint32_t>(from, output) :
|
||||
deserialize_text_value_to_variant<std::int32_t>(from, output);
|
||||
@@ -184,8 +176,6 @@ inline mysql::Error mysql::detail::deserialize_text_value(
|
||||
return deserialize_text_value_to_variant<date>(from, output);
|
||||
case protocol_field_type::time:
|
||||
return deserialize_text_value_to_variant<time>(from, output, meta.decimals());
|
||||
case protocol_field_type::year:
|
||||
return deserialize_text_value_to_variant<year>(from, output);
|
||||
// True string types
|
||||
case protocol_field_type::varchar:
|
||||
case protocol_field_type::var_string:
|
||||
|
||||
@@ -52,7 +52,6 @@ struct print_visitor
|
||||
os << buffer;
|
||||
}
|
||||
void operator()(const datetime& value) const { ::date::operator<<(os, value); }
|
||||
void operator()(const year& value) const { ::date::operator<<(os, value); }
|
||||
void operator()(std::nullptr_t) const { os << "<NULL>"; }
|
||||
};
|
||||
|
||||
|
||||
@@ -20,9 +20,6 @@ using datetime = ::date::sys_time<std::chrono::microseconds>;
|
||||
/// Type representing MySQL TIME data type.
|
||||
using time = std::chrono::microseconds;
|
||||
|
||||
/// Type representing MySQL YEAR data type.
|
||||
using year = ::date::year;
|
||||
|
||||
/**
|
||||
* \brief Represents a value in the database of any of the allowed types.
|
||||
* \details If a value is NULL, the type of the variant will be nullptr_t.
|
||||
@@ -37,7 +34,7 @@ using year = ::date::year;
|
||||
using value = std::variant<
|
||||
std::int32_t, // signed TINYINT, SMALLINT, MEDIUMINT, INT
|
||||
std::int64_t, // signed BIGINT
|
||||
std::uint32_t, // unsigned TINYINT, SMALLINT, MEDIUMINT, INT
|
||||
std::uint32_t, // unsigned TINYINT, SMALLINT, MEDIUMINT, INT, YEAR
|
||||
std::uint64_t, // unsigned BIGINT
|
||||
std::string_view, // CHAR, VARCHAR, BINARY, VARBINARY, TEXT (all sizes), BLOB (all sizes), ENUM, SET, DECIMAL, BIT, GEOMTRY
|
||||
float, // FLOAT
|
||||
@@ -45,7 +42,6 @@ using value = std::variant<
|
||||
date, // DATE
|
||||
datetime, // DATETIME, TIMESTAMP
|
||||
time, // TIME
|
||||
year, // YEAR
|
||||
std::nullptr_t // Any of the above when the value is NULL
|
||||
>;
|
||||
|
||||
|
||||
@@ -407,10 +407,10 @@ INSTANTIATE_TEST_SUITE_P(TIME, QueryTypesTest, Values(
|
||||
));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(YEAR, QueryTypesTest, Values(
|
||||
QueryTypesParams("types_year", "field_default", "regular", mysql::year(2019), field_type::year, flags_zerofill),
|
||||
QueryTypesParams("types_year", "field_default", "min", mysql::year(1901), field_type::year, flags_zerofill),
|
||||
QueryTypesParams("types_year", "field_default", "max", mysql::year(2155), field_type::year, flags_zerofill),
|
||||
QueryTypesParams("types_year", "field_default", "zero", mysql::year(0), field_type::year, flags_zerofill)
|
||||
QueryTypesParams("types_year", "field_default", "regular", std::uint32_t(2019), field_type::year, flags_zerofill),
|
||||
QueryTypesParams("types_year", "field_default", "min", std::uint32_t(1901), field_type::year, flags_zerofill),
|
||||
QueryTypesParams("types_year", "field_default", "max", std::uint32_t(2155), field_type::year, flags_zerofill),
|
||||
QueryTypesParams("types_year", "field_default", "zero", std::uint32_t(0), field_type::year, flags_zerofill)
|
||||
));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(STRING, QueryTypesTest, Values(
|
||||
|
||||
@@ -76,7 +76,7 @@ TEST(RowTest, OperatorStream_OneElement)
|
||||
TEST(RowTest, OperatorStream_SeveralElements)
|
||||
{
|
||||
EXPECT_EQ((to_string(makerow("value", nullptr))), "{value, <NULL>}");
|
||||
EXPECT_EQ((to_string(makerow("value", mysql::year(2019), 3.14f))), "{value, 2019, 3.14}");
|
||||
EXPECT_EQ((to_string(makerow("value", std::uint32_t(2019), 3.14f))), "{value, 2019, 3.14}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -234,22 +234,6 @@ INSTANTIATE_TEST_SUITE_P(Time, FullSerializationTest, ::testing::Values(
|
||||
0x3a, 0x58, 0x3e, 0x0f, 0x00}, "negative_hmsu")
|
||||
));
|
||||
|
||||
|
||||
/*
|
||||
* std::int32_t, // signed TINYINT, SMALLINT, MEDIUMINT, INT
|
||||
std::int64_t, // signed BIGINT
|
||||
std::uint32_t, // unsigned TINYINT, SMALLINT, MEDIUMINT, INT
|
||||
std::uint64_t, // unsigned BIGINT
|
||||
std::string_view, // CHAR, VARCHAR, BINARY, VARBINARY, TEXT (all sizes), BLOB (all sizes), ENUM, SET, DECIMAL, BIT, GEOMTRY
|
||||
float, // FLOAT
|
||||
double, // DOUBLE
|
||||
date, // DATE
|
||||
datetime, // DATETIME, TIMESTAMP
|
||||
time, // TIME
|
||||
year, // YEAR
|
||||
std::nullptr_t // Any of the above when the value is NULL
|
||||
*/
|
||||
|
||||
// Messages
|
||||
INSTANTIATE_TEST_SUITE_P(PacketHeader, FullSerializationTest, ::testing::Values(
|
||||
SerializeParams(packet_header{int3(3), int1(0)}, {0x03, 0x00, 0x00, 0x00}, "small packet, seqnum==0"),
|
||||
@@ -724,13 +708,6 @@ INSTANTIATE_TEST_SUITE_P(ComStmtExecute, SerializeTest, testing::Values(
|
||||
},
|
||||
"time"
|
||||
),
|
||||
make_stmt_execute_test(1, 0, 1, 1, // stmt ID, flags, itercount, new params
|
||||
{ mysql::year(2010) }, {
|
||||
0x17, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01, 0x02, 0x80, 0xda, 0x07
|
||||
},
|
||||
"year"
|
||||
),
|
||||
make_stmt_execute_test(1, 0, 1, 1, // stmt ID, flags, itercount, new params
|
||||
{ nullptr }, {
|
||||
0x17, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
|
||||
@@ -746,27 +723,24 @@ INSTANTIATE_TEST_SUITE_P(ComStmtExecute, SerializeTest, testing::Values(
|
||||
std::string_view("test"),
|
||||
nullptr,
|
||||
2.1e214,
|
||||
mysql::year(2010),
|
||||
makedate(2010, 9, 3),
|
||||
makedt(2010, 9, 3, 10, 30, 59, 231800),
|
||||
maket(230, 30, 59, 231800),
|
||||
nullptr,
|
||||
mysql::year(2010)
|
||||
nullptr
|
||||
), {
|
||||
0x17, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
|
||||
0x00, 0x00, 0x20, 0x08, 0x01, 0x03, 0x80, 0x03,
|
||||
0x00, 0x00, 0x20, 0x04, 0x01, 0x03, 0x80, 0x03,
|
||||
0x00, 0x08, 0x80, 0x08, 0x00, 0x0f, 0x00, 0x06,
|
||||
0x00, 0x05, 0x00, 0x02, 0x80, 0x0a, 0x00, 0x0c,
|
||||
0x00, 0x0b, 0x00, 0x06, 0x00, 0x02, 0x80, 0xff,
|
||||
0xff, 0xab, 0x00, 0x01, 0x00, 0x54, 0xff, 0xae,
|
||||
0xad, 0xac, 0xab, 0xff, 0xff, 0xab, 0x00, 0x52,
|
||||
0x52, 0x53, 0x54, 0x00, 0x00, 0x54, 0xff, 0x04,
|
||||
0x74, 0x65, 0x73, 0x74, 0x56, 0xc0, 0xee, 0xa6,
|
||||
0x95, 0x30, 0x6f, 0x6c, 0xda, 0x07, 0x04, 0xda,
|
||||
0x07, 0x09, 0x03, 0x0b, 0xda, 0x07, 0x09, 0x03,
|
||||
0x0a, 0x1e, 0x3b, 0x78, 0x89, 0x03, 0x00, 0x0c,
|
||||
0x00, 0x09, 0x00, 0x00, 0x00, 0x0e, 0x1e, 0x3b,
|
||||
0x78, 0x89, 0x03, 0x00, 0xda, 0x07
|
||||
0x00, 0x05, 0x00, 0x0a, 0x00, 0x0c, 0x00, 0x0b,
|
||||
0x00, 0x06, 0x00, 0xff, 0xff, 0xab, 0x00, 0x01,
|
||||
0x00, 0x54, 0xff, 0xae, 0xad, 0xac, 0xab, 0xff,
|
||||
0xff, 0xab, 0x00, 0x52, 0x52, 0x53, 0x54, 0x00,
|
||||
0x00, 0x54, 0xff, 0x04, 0x74, 0x65, 0x73, 0x74,
|
||||
0x56, 0xc0, 0xee, 0xa6, 0x95, 0x30, 0x6f, 0x6c,
|
||||
0x04, 0xda, 0x07, 0x09, 0x03, 0x0b, 0xda, 0x07,
|
||||
0x09, 0x03, 0x0a, 0x1e, 0x3b, 0x78, 0x89, 0x03,
|
||||
0x00, 0x0c, 0x00, 0x09, 0x00, 0x00, 0x00, 0x0e,
|
||||
0x1e, 0x3b, 0x78, 0x89, 0x03, 0x00
|
||||
},
|
||||
"several_params"
|
||||
)
|
||||
|
||||
@@ -292,10 +292,10 @@ INSTANTIATE_TEST_SUITE_P(TIME, DeserializeTextValueTest, Values(
|
||||
));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(YEAR, DeserializeTextValueTest, Values(
|
||||
TextValueParam("regular value", "1999", mysql::year(1999), protocol_field_type::year),
|
||||
TextValueParam("min", "1901", mysql::year(1901), protocol_field_type::year),
|
||||
TextValueParam("max", "2155", mysql::year(2155), protocol_field_type::year),
|
||||
TextValueParam("zero", "0000", mysql::year(0), protocol_field_type::year)
|
||||
TextValueParam("regular value", "1999", std::uint32_t(1999), protocol_field_type::year, column_flags::unsigned_),
|
||||
TextValueParam("min", "1901", std::uint32_t(1901), protocol_field_type::year, column_flags::unsigned_),
|
||||
TextValueParam("max", "2155", std::uint32_t(2155), protocol_field_type::year, column_flags::unsigned_),
|
||||
TextValueParam("zero", "0000", std::uint32_t(0), protocol_field_type::year, column_flags::unsigned_)
|
||||
));
|
||||
|
||||
struct DeserializeTextRowTest : public Test
|
||||
|
||||
@@ -35,7 +35,7 @@ struct ValueEqualityTest : public Test
|
||||
mysql::date(1_d/10/2019_y),
|
||||
mysql::date(1_d/10/2019_y) + std::chrono::hours(10),
|
||||
mysql::time(std::chrono::seconds(-10)),
|
||||
mysql::year(2010),
|
||||
std::uint32_t(2010),
|
||||
nullptr
|
||||
);
|
||||
std::vector<mysql::value> values_copy = values;
|
||||
@@ -49,7 +49,7 @@ struct ValueEqualityTest : public Test
|
||||
mysql::date(1_d/9/2019_y),
|
||||
mysql::date(1_d/9/2019_y) + std::chrono::hours(10),
|
||||
mysql::time(std::chrono::seconds(10)),
|
||||
mysql::year(1900),
|
||||
std::uint32_t(1900),
|
||||
nullptr
|
||||
);
|
||||
};
|
||||
@@ -125,7 +125,6 @@ INSTANTIATE_TEST_SUITE_P(Default, ValueStreamTest, Values(
|
||||
ValueStreamParams(mysql::time(hours(-839) - minutes(20) - seconds(35) - microseconds(999999)), "-839:20:35:999999"),
|
||||
ValueStreamParams(makedt(2019, 1, 8, 9, 20, 11, 123), "2019-01-08 09:20:11.000123"),
|
||||
ValueStreamParams(makedt(2019, 1, 8), "2019-01-08 00:00:00.000000"),
|
||||
ValueStreamParams(mysql::year(2019), "2019"),
|
||||
ValueStreamParams(nullptr, "<NULL>")
|
||||
));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user