From 7cc4e45abd517bc2c4681ab46a13a7f229f1d99e Mon Sep 17 00:00:00 2001 From: Roland Bock Date: Thu, 18 Jul 2024 20:17:57 +0200 Subject: [PATCH] Add dynamic to AND and OR --- include/sqlpp11/operator/logical_expression.h | 10 +++++----- include/sqlpp11/serialize.h | 10 ++++++++++ tests/core/serialize/CMakeLists.txt | 1 + tests/core/types/logical_expression.cpp | 20 +++++++++++++------ 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/include/sqlpp11/operator/logical_expression.h b/include/sqlpp11/operator/logical_expression.h index bd994101..f413f594 100644 --- a/include/sqlpp11/operator/logical_expression.h +++ b/include/sqlpp11/operator/logical_expression.h @@ -29,11 +29,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -//#include +#include //#include //#include #include -//#include namespace sqlpp { @@ -65,7 +64,7 @@ namespace sqlpp template struct value_type_of> - : std::conditional>::value or sqlpp::is_optional>::value, + : std::conditional>::value or sqlpp::is_optional>>::value, sqlpp::compat::optional, boolean> { @@ -141,7 +140,8 @@ namespace sqlpp static constexpr auto symbol = " AND "; }; - template > +#warning: need tests with dynamic AND/OR + template >> constexpr auto operator and(L l, R r) -> logical_expression { return {std::move(l), std::move(r)}; @@ -152,7 +152,7 @@ namespace sqlpp static constexpr auto symbol = " OR "; }; - template > + template >> constexpr auto operator||(L l, R r) -> logical_expression { return {std::move(l), std::move(r)}; diff --git a/include/sqlpp11/serialize.h b/include/sqlpp11/serialize.h index e108cf40..46557fb9 100644 --- a/include/sqlpp11/serialize.h +++ b/include/sqlpp11/serialize.h @@ -47,6 +47,16 @@ namespace sqlpp return context; } +#warning: We should switch context and arg to allow for this to have fewer error messages + /* + template + auto serialize(Context& context, ...) -> Context& + { + static_assert(wrong_t::value, "Missing specialization"); + return context; + } + */ + template auto serialize(const bool& t, Context& context) -> Context& { diff --git a/tests/core/serialize/CMakeLists.txt b/tests/core/serialize/CMakeLists.txt index 5b15e1b7..092c9593 100644 --- a/tests/core/serialize/CMakeLists.txt +++ b/tests/core/serialize/CMakeLists.txt @@ -23,6 +23,7 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. set(test_files + logical_expression.cpp Any.cpp As.cpp Avg.cpp diff --git a/tests/core/types/logical_expression.cpp b/tests/core/types/logical_expression.cpp index b2f538f6..699969f4 100644 --- a/tests/core/types/logical_expression.cpp +++ b/tests/core/types/logical_expression.cpp @@ -23,14 +23,10 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "MockDb.h" -#include "Sample.h" #include namespace { - auto db = MockDb{}; - template using is_bool = std::is_same, sqlpp::boolean>; @@ -48,18 +44,30 @@ void test_logical_expression(Value v) static_assert(is_bool::value, ""); static_assert(is_bool::value, ""); - // Compare non-nullable with nullable. + static_assert(is_bool::value, ""); + static_assert(is_bool::value, ""); + + // Compare nullable with non-nullable. static_assert(is_maybe_bool::value, ""); static_assert(is_maybe_bool::value, ""); - // Compare nullable with non-nullable. + static_assert(is_maybe_bool::value, ""); + static_assert(is_maybe_bool::value, ""); + + // Compare non-nullable with nullable. static_assert(is_maybe_bool::value, ""); static_assert(is_maybe_bool::value, ""); + static_assert(is_maybe_bool::value, ""); + static_assert(is_maybe_bool::value, ""); + // Compare nullable with nullable. static_assert(is_maybe_bool::value, ""); static_assert(is_maybe_bool::value, ""); + static_assert(is_maybe_bool::value, ""); + static_assert(is_maybe_bool::value, ""); + // not. static_assert(is_bool::value, ""); static_assert(is_maybe_bool::value, "");