mirror of
https://github.com/boostorg/mysql.git
synced 2026-02-17 13:52:18 +00:00
Now YEAR has its own type in mysql::value
Added tests for deserialize_text_value YEAR
This commit is contained in:
@@ -119,6 +119,15 @@ Error deserialize_text_value_impl(std::string_view from, std::nullptr_t& to)
|
||||
return Error::ok;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -160,7 +169,6 @@ inline mysql::Error mysql::detail::deserialize_text_value(
|
||||
case field_type::short_:
|
||||
case field_type::int24:
|
||||
case field_type::long_:
|
||||
case 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);
|
||||
@@ -181,6 +189,8 @@ inline mysql::Error mysql::detail::deserialize_text_value(
|
||||
return deserialize_text_value_to_variant<date>(from, output);
|
||||
case field_type::time:
|
||||
return deserialize_text_value_to_variant<time>(from, output, meta.decimals());
|
||||
case field_type::year:
|
||||
return deserialize_text_value_to_variant<year>(from, output);
|
||||
default:
|
||||
return Error::protocol_value_error;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace mysql
|
||||
using date = ::date::sys_days;
|
||||
using datetime = ::date::sys_time<std::chrono::microseconds>;
|
||||
using time = std::chrono::microseconds;
|
||||
using year = ::date::year;
|
||||
|
||||
/**
|
||||
* field_type::decimal: string_view
|
||||
@@ -52,6 +53,7 @@ using value = std::variant<
|
||||
date,
|
||||
datetime,
|
||||
time,
|
||||
year,
|
||||
std::nullptr_t
|
||||
>;
|
||||
|
||||
|
||||
@@ -97,6 +97,13 @@ INSTANTIATE_TEST_SUITE_P(MEDIUMINT, DeserializeTextValueTest, Values(
|
||||
TextValueParam("usigned max", "16777215", std::uint32_t(16777215), field_type::int24, true)
|
||||
));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(YEAR, DeserializeTextValueTest, Values(
|
||||
TextValueParam("regular value", "1999", year(1999), field_type::year),
|
||||
TextValueParam("min", "1901", year(1901), field_type::year),
|
||||
TextValueParam("max", "2155", year(2155), field_type::year),
|
||||
TextValueParam("zero", "0000", year(0), field_type::year)
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user