Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复bug:在MSVC debug环境下,直接value解引用会触发cannot access empty value optional断… #185

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
Loading