From dfa9924288cd9f3167c4c9d27901fa28fd7f5e85 Mon Sep 17 00:00:00 2001 From: Roland Bock Date: Sat, 3 Aug 2024 11:41:32 +0200 Subject: [PATCH] More tests and changed parentheses handling in operators --- .../core/operator/arithmetic_expression.h | 32 +------ include/sqlpp11/core/operator/as_expression.h | 5 -- .../sqlpp11/core/operator/assign_expression.h | 17 +--- .../core/operator/between_expression.h | 85 ++----------------- .../sqlpp11/core/operator/bit_expression.h | 24 +----- include/sqlpp11/core/operator/case.h | 7 +- .../core/operator/comparison_expression.h | 35 +------- .../sqlpp11/core/operator/exists_expression.h | 2 +- include/sqlpp11/core/operator/in_expression.h | 20 ++--- .../core/operator/logical_expression.h | 33 +------ .../core/operator/sort_order_expression.h | 18 ---- include/sqlpp11/core/type_traits.h | 5 +- tests/core/serialize/Any.cpp | 42 --------- tests/core/serialize/CMakeLists.txt | 3 +- tests/core/types/operator/CMakeLists.txt | 2 +- 15 files changed, 36 insertions(+), 294 deletions(-) delete mode 100644 tests/core/serialize/Any.cpp diff --git a/include/sqlpp11/core/operator/arithmetic_expression.h b/include/sqlpp11/core/operator/arithmetic_expression.h index 960560fc..5d2f7ea1 100644 --- a/include/sqlpp11/core/operator/arithmetic_expression.h +++ b/include/sqlpp11/core/operator/arithmetic_expression.h @@ -88,45 +88,15 @@ namespace sqlpp using type = detail::type_vector; }; -#if 0 - template - struct value_type_of_t> - { - using type = numeric_t; - }; + struct requires_braces> : public std::true_type{}; - template - constexpr auto requires_braces_v> = true; - - template - [[nodiscard]] auto to_sql_string(Context& context, const arithmetic_expression& t) - { - return to_sql_string(context, embrace(t._l)) + Operator::symbol + to_sql_string(context, embrace(t._r)); - } - - template - [[nodiscard]] auto to_sql_string(Context& context, const arithmetic_expression& t) - { - return Operator::symbol + to_sql_string(context, embrace(t._r)); - } - - template - [[nodiscard]] auto to_sql_string(Context& context, - const arithmetic_expression, Operator, R2>& t) - { - return to_sql_string(context, t._l) + Operator::symbol + to_sql_string(context, embrace(t._r)); - } -#endif - template auto serialize(Context& context, const arithmetic_expression& t) -> Context& { - context << "("; serialize_operand(context, t._l); context << Operator::symbol; serialize_operand(context, t._r); - context << ")"; return context; } diff --git a/include/sqlpp11/core/operator/as_expression.h b/include/sqlpp11/core/operator/as_expression.h index 3509e890..87afeccc 100644 --- a/include/sqlpp11/core/operator/as_expression.h +++ b/include/sqlpp11/core/operator/as_expression.h @@ -39,11 +39,6 @@ namespace sqlpp using _traits = make_traits, tag::is_selectable, tag::is_alias>; #warning Maybe make constructor of expressions private to force construction in the respective functions? - /* - static_assert(is_expression_t::value, "invalid argument for an expression alias"); - static_assert(not is_alias_t::value, "cannot create an alias of an alias"); - */ - constexpr as_expression(Expression expression) : _expression(std::move(expression)) { } diff --git a/include/sqlpp11/core/operator/assign_expression.h b/include/sqlpp11/core/operator/assign_expression.h index fe7bad43..e85b275c 100644 --- a/include/sqlpp11/core/operator/assign_expression.h +++ b/include/sqlpp11/core/operator/assign_expression.h @@ -77,22 +77,7 @@ namespace sqlpp using type = R; }; - /* - template - struct column_of> - { - using type = L; - }; - - template - constexpr auto requires_braces_v> = true; - - template - [[nodiscard]] auto to_sql_string(Context& context, const assign_t& t) - { - return to_sql_string(context, t.column) + " = " + to_sql_string(context, embrace(t.value)); - } - */ +#warning does this require braces? template Context& serialize(Context& context, const assign_expression& t) diff --git a/include/sqlpp11/core/operator/between_expression.h b/include/sqlpp11/core/operator/between_expression.h index df47b938..e0b47d42 100644 --- a/include/sqlpp11/core/operator/between_expression.h +++ b/include/sqlpp11/core/operator/between_expression.h @@ -67,38 +67,8 @@ namespace sqlpp using type = detail::type_vector; }; - - /* - - template - struct nodes_of> - { - using type = type_vector; - }; - - template - constexpr auto in(L l, Args... args) - -> ::sqlpp::enable_if_t<((sizeof...(Args) > 0) and ... and values_are_compatible_v), between_t> - { - return between_t{l, std::tuple{args...}}; - } - - template - constexpr auto requires_braces_v> = true; - - template - [[nodiscard]] auto to_sql_string(Context& context, const between_t& t) - { - if constexpr (sizeof...(Args) == 1) - { - return to_sql_string(context, embrace(t.l)) + " IN(" + to_sql_string(context, std::get<0>(t.args)) + ")"; - } - else - { - return to_sql_string(context, embrace(t.l)) + " IN(" + tuple_to_sql_string(context, ", ", t.args) + ")"; - } - } - */ + template + struct requires_braces> : public std::true_type{}; #warning: Need tests for between expressions template > @@ -107,52 +77,15 @@ namespace sqlpp return {std::move(l), std::move(r1), std::move(r2)}; } -#if 0 // original serialize implementation - template - Context& serialize(Context& context, const between_t& t) + template + auto serialize(Context& context, const between_expression& t) -> Context& { - serialize(context, t._operand); - context << " IN("; - if (sizeof...(Args) == 0) - { - serialize(context, std::get<0>(t._args)); - } - else - { - interpret_tuple(t._args, ',', context); - } - context << ')'; + serialize_operand(context, t._l); + context << " BETWEEN "; + serialize_operand(context, t._r1); + context << " AND "; + serialize_operand(context, t._r2); return context; } - template - Context& serialize(Context& context, const between_t&) - { - serialize(context, boolean_operand{false}); - return context; - } - - template - struct value_list_t; - - template - Context& serialize(Context& context, const between_t>& t) - { - const auto& value_list = std::get<0>(t._args); - if (value_list._container.empty()) - { - serialize(context, boolean_operand{false}); - } - else - { - serialize(context, t._operand); - context << " IN("; - serialize(context, value_list); - context << ')'; - } - return context; - } - -#endif - } // namespace sqlpp diff --git a/include/sqlpp11/core/operator/bit_expression.h b/include/sqlpp11/core/operator/bit_expression.h index 559af420..ef0fdcc9 100644 --- a/include/sqlpp11/core/operator/bit_expression.h +++ b/include/sqlpp11/core/operator/bit_expression.h @@ -71,37 +71,15 @@ namespace sqlpp template using check_bit_shift_expression_args = ::sqlpp::enable_if_t::value and (is_integral::value or is_unsigned_integral::value)>; -#if 0 template - struct value_type_of_t> - { - using type = integral_t; - }; - - template - constexpr auto requires_braces_v> = true; - - template - [[nodiscard]] auto to_sql_string(Context& context, const binary_t& t) - { - return to_sql_string(context, embrace(t._l)) + Operator::symbol + to_sql_string(context, embrace(t._r)); - } - - template - [[nodiscard]] auto to_sql_string(Context& context, const binary_t& t) - { - return Operator::symbol + to_sql_string(context, embrace(t._r)); - } -#endif + struct requires_braces> : public std::true_type {}; template auto serialize(Context& context, const bit_expression& t) -> Context& { - context << "("; serialize_operand(context, t._l); context << Operator::symbol; serialize_operand(context, t._r); - context << ")"; return context; } diff --git a/include/sqlpp11/core/operator/case.h b/include/sqlpp11/core/operator/case.h index 062c7b93..a6aa31c1 100644 --- a/include/sqlpp11/core/operator/case.h +++ b/include/sqlpp11/core/operator/case.h @@ -86,6 +86,9 @@ namespace sqlpp { }; + template + struct requires_braces> : public std::true_type{}; + template class case_then_t { @@ -156,13 +159,13 @@ namespace sqlpp template Context& serialize(Context& context, const case_t& t) { - context << "(CASE WHEN "; + context << "CASE WHEN "; serialize(context, t._when); context << " THEN "; serialize(context, t._then); context << " ELSE "; serialize(context, t._else); - context << " END)"; + context << " END"; return context; } diff --git a/include/sqlpp11/core/operator/comparison_expression.h b/include/sqlpp11/core/operator/comparison_expression.h index 72e56250..8c5e22d3 100644 --- a/include/sqlpp11/core/operator/comparison_expression.h +++ b/include/sqlpp11/core/operator/comparison_expression.h @@ -84,48 +84,15 @@ namespace sqlpp using type = detail::type_vector; }; - -#if 0 - SQLPP_WRAPPED_STATIC_ASSERT(assert_comparison_operands_are_compatible, - "comparison operands must have compatible value types"); - - template - constexpr auto check_comparison_args() - { - if constexpr (not values_are_compatible_v) - { - return failed{}; - } - else - { - return succeeded{}; - } - } - template - struct value_type_of_t> - { - using type = bool; - }; - - template - constexpr auto requires_braces_v> = true; - - template - [[nodiscard]] auto to_sql_string(Context& context, const comparison_expression& t) - { - return to_sql_string(context, embrace(t.l)) + Operator::symbol + to_sql_string(context, embrace(t.r)); - } -#endif + struct requires_braces> : public std::true_type{}; template auto serialize(Context& context, const comparison_expression& t) -> Context& { - context << "("; serialize_operand(context, t._l); context << Operator::symbol; serialize_operand(context, t._r); - context << ")"; return context; } diff --git a/include/sqlpp11/core/operator/exists_expression.h b/include/sqlpp11/core/operator/exists_expression.h index 001f4a71..f1fe7f87 100644 --- a/include/sqlpp11/core/operator/exists_expression.h +++ b/include/sqlpp11/core/operator/exists_expression.h @@ -66,7 +66,7 @@ namespace sqlpp template auto serialize(Context& context, const exists_expression