From 18990a7e5d4fac45f8829701b3984320ebdd098d Mon Sep 17 00:00:00 2001 From: treattrick <1154174767@qq.com> Date: Wed, 11 Dec 2024 21:18:10 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug=EF=BC=9A=E5=9C=A8MSVC?= =?UTF-8?q?=20debug=E7=8E=AF=E5=A2=83=E4=B8=8B=EF=BC=8C=E7=9B=B4=E6=8E=A5v?= =?UTF-8?q?alue=E8=A7=A3=E5=BC=95=E7=94=A8=E4=BC=9A=E8=A7=A6=E5=8F=91canno?= =?UTF-8?q?t=20access=20empty=20value=20optional=E6=96=AD=E8=A8=80?= =?UTF-8?q?=EF=BC=8C=E5=AF=BC=E8=87=B4=E7=A8=8B=E5=BA=8F=E5=B4=A9=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ormpp/mysql.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ormpp/mysql.hpp b/ormpp/mysql.hpp index 68d9f80..6051b27 100644 --- a/ormpp/mysql.hpp +++ b/ormpp/mysql.hpp @@ -209,6 +209,8 @@ class mysql { std::map> &mp, B &is_null) { using U = std::remove_const_t>; if constexpr (is_optional_v::value) { + using value_type = typename U::value_type; + value = value_type(); return set_param_bind(param_bind, *value, i, mp, is_null); } else if constexpr (std::is_enum_v) { From ea69f6757ec51275dee187a487293ed2f07e30ea Mon Sep 17 00:00:00 2001 From: TreatTrick <1154174767@qq.com> Date: Thu, 12 Dec 2024 09:39:16 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E8=B5=8B=E5=88=9D=E5=A7=8B=E5=80=BC?= =?UTF-8?q?=E6=97=B6=E5=85=88=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6=E5=B7=B2?= =?UTF-8?q?=E7=BB=8F=E6=9C=89=E5=80=BC=EF=BC=9B=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E7=94=B1=E5=B0=8F=E6=8B=AC=E5=8F=B7=E6=9B=B4?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E8=8A=B1=E6=8B=AC=E5=8F=B7=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ormpp/mysql.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ormpp/mysql.hpp b/ormpp/mysql.hpp index 6051b27..5dcf1e1 100644 --- a/ormpp/mysql.hpp +++ b/ormpp/mysql.hpp @@ -210,7 +210,9 @@ class mysql { using U = std::remove_const_t>; if constexpr (is_optional_v::value) { using value_type = typename U::value_type; - value = 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) { From 93bd286c98a822e47444578010e590d2aa35dddb Mon Sep 17 00:00:00 2001 From: TreatTrick <1154174767@qq.com> Date: Thu, 12 Dec 2024 21:41:37 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=B9optional?= =?UTF-8?q?=E7=9A=84query=5Fs=E6=B5=8B=E8=AF=95=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_ormpp.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_ormpp.cpp b/tests/test_ormpp.cpp index d99f66a..3431b68 100644 --- a/tests/test_ormpp.cpp +++ b/tests/test_ormpp.cpp @@ -121,6 +121,18 @@ 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(); + 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("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 From 5d32428c8bf5d6f9d34b7414375877d542a94b8f Mon Sep 17 00:00:00 2001 From: treattrick <1154174767@qq.com> Date: Sat, 14 Dec 2024 16:16:10 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E7=94=A8=E6=9C=AC=E5=9C=B0clang-format?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ormpp/mysql.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ormpp/mysql.hpp b/ormpp/mysql.hpp index 5dcf1e1..e550c81 100644 --- a/ormpp/mysql.hpp +++ b/ormpp/mysql.hpp @@ -210,7 +210,7 @@ class mysql { using U = std::remove_const_t>; if constexpr (is_optional_v::value) { using value_type = typename U::value_type; - if(!value.has_value()) { + if (!value.has_value()) { value = value_type{}; } return set_param_bind(param_bind, *value, i, mp, is_null); From 57849d308cd973450227b0148f9920523996c022 Mon Sep 17 00:00:00 2001 From: qicosmos <383121719@qq.com> Date: Sat, 14 Dec 2024 19:05:00 +0800 Subject: [PATCH 5/5] format --- tests/test_ormpp.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_ormpp.cpp b/tests/test_ormpp.cpp index 3431b68..4647e5c 100644 --- a/tests/test_ormpp.cpp +++ b/tests/test_ormpp.cpp @@ -132,7 +132,6 @@ TEST_CASE("optional") { CHECK(vec4.front().age.value() == 200); CHECK(vec4.front().name.value() == "purecpp"); CHECK(vec4.front().empty_.has_value() == false); - } #endif #ifdef ORMPP_ENABLE_PG @@ -2096,4 +2095,4 @@ TEST_CASE("unsigned type") { CHECK(vec.front().h == 8); } #endif -} \ No newline at end of file +}