Skip to content

Commit

Permalink
Merge pull request #185 from TreatTrick/bugfix-msvc-debug-error-if-op…
Browse files Browse the repository at this point in the history
…tional
  • Loading branch information
qicosmos authored Dec 15, 2024
2 parents 9826379 + 57849d3 commit f3a59b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ormpp/mysql.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ class mysql {
std::map<size_t, std::vector<char>> &mp, B &is_null) {
using U = std::remove_const_t<std::remove_reference_t<T>>;
if constexpr (is_optional_v<U>::value) {
using value_type = typename U::value_type;
if (!value.has_value()) {
value = value_type{};
}
return set_param_bind(param_bind, *value, i, mp, is_null);
}
else if constexpr (std::is_enum_v<U>) {
Expand Down
13 changes: 12 additions & 1 deletion tests/test_ormpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ TEST_CASE("optional") {
CHECK(vec2.front().age.value() == 200);
CHECK(vec2.front().name.value() == "purecpp");
CHECK(vec2.front().empty_.has_value() == false);

auto vec3 = mysql.query_s<test_optional>();
REQUIRE(vec3.size() > 0);
CHECK(vec3.front().age.value() == 200);
CHECK(vec3.front().name.value() == "purecpp");
CHECK(vec3.front().empty_.has_value() == false);
auto vec4 = mysql.query_s<test_optional>("select * from test_optional;");
REQUIRE(vec4.size() > 0);
CHECK(vec4.front().age.value() == 200);
CHECK(vec4.front().name.value() == "purecpp");
CHECK(vec4.front().empty_.has_value() == false);
}
#endif
#ifdef ORMPP_ENABLE_PG
Expand Down Expand Up @@ -2084,4 +2095,4 @@ TEST_CASE("unsigned type") {
CHECK(vec.front().h == 8);
}
#endif
}
}

0 comments on commit f3a59b9

Please sign in to comment.