From 0f4d3b14518f5e2cdd6a2524f061959d4d6991b4 Mon Sep 17 00:00:00 2001 From: Roland Bock Date: Thu, 18 Jul 2024 20:49:16 +0200 Subject: [PATCH] Reduce error messages for serialize, add first serialize test for dynamic AND --- include/sqlpp11/aggregate_functions/avg.h | 6 +- include/sqlpp11/aggregate_functions/count.h | 6 +- include/sqlpp11/aggregate_functions/max.h | 6 +- include/sqlpp11/aggregate_functions/min.h | 6 +- include/sqlpp11/aggregate_functions/sum.h | 6 +- include/sqlpp11/bad_expression.h | 2 +- include/sqlpp11/case.h | 8 +- include/sqlpp11/column.h | 2 +- include/sqlpp11/cte.h | 14 ++-- include/sqlpp11/custom_query.h | 2 +- include/sqlpp11/default_value.h | 2 +- include/sqlpp11/dynamic.h | 4 +- include/sqlpp11/for_update.h | 2 +- include/sqlpp11/from.h | 4 +- include/sqlpp11/functions.h | 2 +- include/sqlpp11/group_by.h | 2 +- include/sqlpp11/having.h | 4 +- include/sqlpp11/hidden.h | 2 +- include/sqlpp11/insert.h | 2 +- include/sqlpp11/insert_value.h | 4 +- include/sqlpp11/insert_value_list.h | 6 +- include/sqlpp11/interpret_tuple.h | 4 +- include/sqlpp11/into.h | 4 +- include/sqlpp11/join.h | 6 +- include/sqlpp11/limit.h | 4 +- include/sqlpp11/lower.h | 4 +- include/sqlpp11/mysql/connection.h | 20 ++--- include/sqlpp11/no_data.h | 2 +- include/sqlpp11/noop.h | 2 +- include/sqlpp11/offset.h | 4 +- include/sqlpp11/on.h | 6 +- include/sqlpp11/operator/any.h | 4 +- include/sqlpp11/operator/as_expression.h | 4 +- include/sqlpp11/operator/assign_expression.h | 6 +- include/sqlpp11/operator/between_expression.h | 18 ++--- include/sqlpp11/operator/in_expression.h | 18 ++--- include/sqlpp11/operator/logical_expression.h | 29 +++++++ include/sqlpp11/order_by.h | 2 +- include/sqlpp11/over.h | 4 +- include/sqlpp11/parameter.h | 2 +- include/sqlpp11/parameterized_verbatim.h | 4 +- include/sqlpp11/postgresql/connection.h | 4 +- .../postgresql/on_conflict_do_nothing.h | 2 +- .../postgresql/on_conflict_do_update.h | 6 +- include/sqlpp11/pre_join.h | 6 +- include/sqlpp11/remove.h | 2 +- include/sqlpp11/schema.h | 2 +- include/sqlpp11/schema_qualified_table.h | 6 +- include/sqlpp11/select.h | 2 +- include/sqlpp11/select_column_list.h | 2 +- include/sqlpp11/select_flag_list.h | 2 +- include/sqlpp11/select_flags.h | 6 +- include/sqlpp11/select_pseudo_table.h | 4 +- include/sqlpp11/serialize.h | 79 +++++++++---------- include/sqlpp11/simple_column.h | 2 +- include/sqlpp11/single_table.h | 4 +- include/sqlpp11/sort_order.h | 4 +- include/sqlpp11/sqlite3/connection.h | 24 +++--- include/sqlpp11/statement.h | 4 +- include/sqlpp11/table.h | 2 +- include/sqlpp11/table_alias.h | 4 +- include/sqlpp11/trim.h | 4 +- include/sqlpp11/union_data.h | 8 +- include/sqlpp11/union_flags.h | 4 +- include/sqlpp11/update.h | 2 +- include/sqlpp11/update_list.h | 2 +- include/sqlpp11/upper.h | 4 +- include/sqlpp11/using.h | 2 +- include/sqlpp11/value.h | 4 +- include/sqlpp11/verbatim.h | 2 +- include/sqlpp11/verbatim_table.h | 2 +- include/sqlpp11/where.h | 6 +- include/sqlpp11/with.h | 2 +- include/sqlpp11/without_table_check.h | 4 +- tests/core/serialize/CMakeLists.txt | 60 +++++++------- tests/core/serialize/compare.h | 2 +- tests/core/serialize/logical_expression.cpp | 64 +++++++++++++++ 77 files changed, 334 insertions(+), 244 deletions(-) create mode 100644 tests/core/serialize/logical_expression.cpp diff --git a/include/sqlpp11/aggregate_functions/avg.h b/include/sqlpp11/aggregate_functions/avg.h index 576d7b45..39809c7e 100644 --- a/include/sqlpp11/aggregate_functions/avg.h +++ b/include/sqlpp11/aggregate_functions/avg.h @@ -58,15 +58,15 @@ namespace sqlpp }; template - Context& serialize(const avg_t& t, Context& context) + Context& serialize(Context& context, const avg_t& t) { context << "AVG("; if (std::is_same::value) { - serialize(Flag(), context); + serialize(context, Flag()); context << ' '; } - serialize_operand(t._expr, context); + serialize_operand(context, t._expr); context << ")"; return context; } diff --git a/include/sqlpp11/aggregate_functions/count.h b/include/sqlpp11/aggregate_functions/count.h index 8f93c514..81039b3a 100644 --- a/include/sqlpp11/aggregate_functions/count.h +++ b/include/sqlpp11/aggregate_functions/count.h @@ -63,15 +63,15 @@ namespace sqlpp }; template - Context& serialize(const count_t& t, Context& context) + Context& serialize(Context& context, const count_t& t) { context << "COUNT("; if (std::is_same::value) { - serialize(Flag(), context); + serialize(context, Flag()); context << ' '; } - serialize_operand(t._expr, context); + serialize_operand(context, t._expr); context << ")"; return context; } diff --git a/include/sqlpp11/aggregate_functions/max.h b/include/sqlpp11/aggregate_functions/max.h index 5667e4cc..3f38c2b4 100644 --- a/include/sqlpp11/aggregate_functions/max.h +++ b/include/sqlpp11/aggregate_functions/max.h @@ -59,15 +59,15 @@ namespace sqlpp }; template - Context& serialize(const max_t& t, Context& context) + Context& serialize(Context& context, const max_t& t) { context << "MAX("; if (std::is_same::value) { - serialize(Flag(), context); + serialize(context, Flag()); context << ' '; } - serialize_operand(t._expr, context); + serialize_operand(context, t._expr); context << ")"; return context; } diff --git a/include/sqlpp11/aggregate_functions/min.h b/include/sqlpp11/aggregate_functions/min.h index 1e90b2ab..f4ba3658 100644 --- a/include/sqlpp11/aggregate_functions/min.h +++ b/include/sqlpp11/aggregate_functions/min.h @@ -59,15 +59,15 @@ namespace sqlpp }; template - Context& serialize(const min_t& t, Context& context) + Context& serialize(Context& context, const min_t& t) { context << "MIN("; if (std::is_same::value) { - serialize(Flag(), context); + serialize(context, Flag()); context << ' '; } - serialize_operand(t._expr, context); + serialize_operand(context, t._expr); context << ")"; return context; } diff --git a/include/sqlpp11/aggregate_functions/sum.h b/include/sqlpp11/aggregate_functions/sum.h index 2b54b53e..5adb9de8 100644 --- a/include/sqlpp11/aggregate_functions/sum.h +++ b/include/sqlpp11/aggregate_functions/sum.h @@ -60,15 +60,15 @@ namespace sqlpp }; template - Context& serialize(const sum_t& t, Context& context) + Context& serialize(Context& context, const sum_t& t) { context << "SUM("; if (std::is_same::value) { - serialize(Flag(), context); + serialize(context, Flag()); context << ' '; } - serialize_operand(t._expr, context); + serialize_operand(context, t._expr); context << ")"; return context; } diff --git a/include/sqlpp11/bad_expression.h b/include/sqlpp11/bad_expression.h index 7e0a88fe..55a9859f 100644 --- a/include/sqlpp11/bad_expression.h +++ b/include/sqlpp11/bad_expression.h @@ -45,5 +45,5 @@ namespace sqlpp }; template - Context serialize(const bad_expression& t, Context& context); + Context serialize(Context& context, const bad_expression& t); } // namespace sqlpp diff --git a/include/sqlpp11/case.h b/include/sqlpp11/case.h index 4ea831d2..65eeef50 100644 --- a/include/sqlpp11/case.h +++ b/include/sqlpp11/case.h @@ -147,14 +147,14 @@ namespace sqlpp }; template - Context& serialize(const case_t& t, Context& context) + Context& serialize(Context& context, const case_t& t) { context << "(CASE WHEN "; - serialize(t._when, context); + serialize(context, t._when); context << " THEN "; - serialize(t._then, context); + serialize(context, t._then); context << " ELSE "; - serialize(t._else, context); + serialize(context, t._else); context << " END)"; return context; } diff --git a/include/sqlpp11/column.h b/include/sqlpp11/column.h index 6babe59e..7e5a8cf0 100644 --- a/include/sqlpp11/column.h +++ b/include/sqlpp11/column.h @@ -95,7 +95,7 @@ namespace sqlpp }; template - Context& serialize(const column_t&, Context& context) + Context& serialize(Context& context, const column_t&) { using T = column_t; diff --git a/include/sqlpp11/cte.h b/include/sqlpp11/cte.h index 64d191e0..90dfc6f4 100644 --- a/include/sqlpp11/cte.h +++ b/include/sqlpp11/cte.h @@ -60,13 +60,13 @@ namespace sqlpp // Interpreters template - Context& serialize(const cte_union_t& t, Context& context) + Context& serialize(Context& context, const cte_union_t& t) { - serialize(t._lhs, context); + serialize(context, t._lhs); context << " UNION "; - serialize(Flag{}, context); + serialize(context, Flag{}); context << " "; - serialize(t._rhs, context); + serialize(context, t._rhs); return context; } @@ -217,11 +217,11 @@ namespace sqlpp }; template - Context& serialize(const cte_t& t, Context& context) + Context& serialize(Context& context, const cte_t& t) { using T = cte_t; context << name_of::template char_ptr() << " AS ("; - serialize(t._statement, context); + serialize(context, t._statement); context << ")"; return context; } @@ -253,7 +253,7 @@ namespace sqlpp }; template - Context& serialize(const cte_ref_t&, Context& context) + Context& serialize(Context& context, const cte_ref_t&) { context << name_of>::template char_ptr(); return context; diff --git a/include/sqlpp11/custom_query.h b/include/sqlpp11/custom_query.h index 6c337da2..1fc50456 100644 --- a/include/sqlpp11/custom_query.h +++ b/include/sqlpp11/custom_query.h @@ -122,7 +122,7 @@ namespace sqlpp }; template - Context& serialize(const custom_query_t& t, Context& context) + Context& serialize(Context& context, const custom_query_t& t) { interpret_tuple_without_braces(t._parts, " ", context); return context; diff --git a/include/sqlpp11/default_value.h b/include/sqlpp11/default_value.h index 98a6c4a0..1425017a 100644 --- a/include/sqlpp11/default_value.h +++ b/include/sqlpp11/default_value.h @@ -37,7 +37,7 @@ namespace sqlpp }; template - Context& serialize(const default_value_t&, Context& context) + Context& serialize(Context& context, const default_value_t&) { context << "DEFAULT"; return context; diff --git a/include/sqlpp11/dynamic.h b/include/sqlpp11/dynamic.h index b17ee800..967ecf7a 100644 --- a/include/sqlpp11/dynamic.h +++ b/include/sqlpp11/dynamic.h @@ -85,11 +85,11 @@ namespace sqlpp using dynamic_to_optional_t = typename dynamic_to_optional::type; template - Context& serialize(const dynamic_t& t) { if (t._condition) { - serialize(t._expr, context); + serialize(context, t._expr); } else { diff --git a/include/sqlpp11/for_update.h b/include/sqlpp11/for_update.h index d29eb7c9..70c89131 100644 --- a/include/sqlpp11/for_update.h +++ b/include/sqlpp11/for_update.h @@ -92,7 +92,7 @@ namespace sqlpp // Interpreters template - Context& serialize(const for_update_data_t&, Context& context) + Context& serialize(Context& context, const for_update_data_t&) { context << " FOR UPDATE "; return context; diff --git a/include/sqlpp11/from.h b/include/sqlpp11/from.h index 47dc63d8..32aea575 100644 --- a/include/sqlpp11/from.h +++ b/include/sqlpp11/from.h @@ -137,10 +137,10 @@ namespace sqlpp // Interpreters template - Context& serialize(const from_data_t& t, Context& context) + Context& serialize(Context& context, const from_data_t
& t) { context << " FROM "; - serialize(t._table, context); + serialize(context, t._table); return context; } diff --git a/include/sqlpp11/functions.h b/include/sqlpp11/functions.h index 024aa5dc..a032090b 100644 --- a/include/sqlpp11/functions.h +++ b/include/sqlpp11/functions.h @@ -50,7 +50,7 @@ namespace sqlpp static_assert(not make_parameter_list_t::size::value, "parameters are not allowed in flattened expressions"); auto context = db.get_serializer_context(); - serialize(exp, context); + serialize(context, exp); return {context.str()}; } diff --git a/include/sqlpp11/group_by.h b/include/sqlpp11/group_by.h index 6a142241..7d93d2c8 100644 --- a/include/sqlpp11/group_by.h +++ b/include/sqlpp11/group_by.h @@ -146,7 +146,7 @@ namespace sqlpp // Interpreters template - Context& serialize(const group_by_data_t& t, Context& context) + Context& serialize(Context& context, const group_by_data_t& t) { context << " GROUP BY "; interpret_tuple(t._expressions, ',', context); diff --git a/include/sqlpp11/having.h b/include/sqlpp11/having.h index 2d612505..529aa13b 100644 --- a/include/sqlpp11/having.h +++ b/include/sqlpp11/having.h @@ -176,10 +176,10 @@ namespace sqlpp // Interpreters template - Context& serialize(const having_data_t& t, Context& context) + Context& serialize(Context& context, const having_data_t& t) { context << " HAVING "; - serialize(t._expression, context); + serialize(context, t._expression); return context; } diff --git a/include/sqlpp11/hidden.h b/include/sqlpp11/hidden.h index b8d67423..9b28b0e3 100644 --- a/include/sqlpp11/hidden.h +++ b/include/sqlpp11/hidden.h @@ -43,7 +43,7 @@ namespace sqlpp }; template - Context& serialize(const hidden_t&, Context& context) + Context& serialize(Context& context, const hidden_t&) { return context; } diff --git a/include/sqlpp11/insert.h b/include/sqlpp11/insert.h index d0c80bb7..2161885a 100644 --- a/include/sqlpp11/insert.h +++ b/include/sqlpp11/insert.h @@ -88,7 +88,7 @@ namespace sqlpp }; template - Context& serialize(const insert_name_t&, Context& context) + Context& serialize(Context& context, const insert_name_t&) { context << "INSERT"; diff --git a/include/sqlpp11/insert_value.h b/include/sqlpp11/insert_value.h index 3b10d57f..c499cdcb 100644 --- a/include/sqlpp11/insert_value.h +++ b/include/sqlpp11/insert_value.h @@ -87,7 +87,7 @@ namespace sqlpp }; template - Context& serialize(const insert_value_t& t, Context& context) + Context& serialize(Context& context, const insert_value_t& t) { if (t._is_null) { @@ -99,7 +99,7 @@ namespace sqlpp } else { - serialize_operand(t._value, context); + serialize_operand(context, t._value); } return context; } diff --git a/include/sqlpp11/insert_value_list.h b/include/sqlpp11/insert_value_list.h index 7237ec4c..3aa5aabc 100644 --- a/include/sqlpp11/insert_value_list.h +++ b/include/sqlpp11/insert_value_list.h @@ -385,7 +385,7 @@ namespace sqlpp // Interpreters template - Context& serialize(const insert_default_values_data_t&, Context& context) + Context& serialize(Context& context, const insert_default_values_data_t&) { context << " DEFAULT VALUES"; return context; @@ -393,7 +393,7 @@ namespace sqlpp template - Context& serialize(const column_list_data_t& t, Context& context) + Context& serialize(Context& context, const column_list_data_t& t) { context << " ("; interpret_tuple(t._columns, ",", context); @@ -419,7 +419,7 @@ namespace sqlpp } template - Context& serialize(const insert_list_data_t& t, Context& context) + Context& serialize(Context& context, const insert_list_data_t& t) { context << " ("; interpret_tuple(t._columns, ",", context); diff --git a/include/sqlpp11/interpret_tuple.h b/include/sqlpp11/interpret_tuple.h index e31d7675..b066883b 100644 --- a/include/sqlpp11/interpret_tuple.h +++ b/include/sqlpp11/interpret_tuple.h @@ -43,11 +43,11 @@ namespace sqlpp } if (UseBraces::value) { - serialize_operand(element, context); + serialize_operand(context, element); } else { - serialize(element, context); + serialize(context, element); } } diff --git a/include/sqlpp11/into.h b/include/sqlpp11/into.h index 51aeb283..1f6c1fe2 100644 --- a/include/sqlpp11/into.h +++ b/include/sqlpp11/into.h @@ -137,10 +137,10 @@ namespace sqlpp // Interpreters template - Context& serialize(const into_data_t
& t, Context& context) + Context& serialize(Context& context, const into_data_t
& t) { context << " INTO "; - serialize(t._table, context); + serialize(context, t._table); return context; } diff --git a/include/sqlpp11/join.h b/include/sqlpp11/join.h index 3d42027f..afc12690 100644 --- a/include/sqlpp11/join.h +++ b/include/sqlpp11/join.h @@ -82,10 +82,10 @@ namespace sqlpp }; template - Context& serialize(const join_t& t, Context& context) + Context& serialize(Context& context, const join_t& t) { - serialize(t._pre_join, context); - serialize(t._on, context); + serialize(context, t._pre_join); + serialize(context, t._on); return context; } } // namespace sqlpp diff --git a/include/sqlpp11/limit.h b/include/sqlpp11/limit.h index 39f43169..fd72ca6c 100644 --- a/include/sqlpp11/limit.h +++ b/include/sqlpp11/limit.h @@ -128,10 +128,10 @@ namespace sqlpp // Interpreters template - Context& serialize(const limit_data_t& t, Context& context) + Context& serialize(Context& context, const limit_data_t& t) { context << " LIMIT "; - serialize_operand(t._value, context); + serialize_operand(context, t._value); return context; } diff --git a/include/sqlpp11/lower.h b/include/sqlpp11/lower.h index c8f0b780..4f30e177 100644 --- a/include/sqlpp11/lower.h +++ b/include/sqlpp11/lower.h @@ -52,10 +52,10 @@ namespace sqlpp }; template - Context& serialize(const lower_t& t, Context& context) + Context& serialize(Context& context, const lower_t& t) { context << "LOWER("; - serialize_operand(t._expr, context); + serialize_operand(context, t._expr); context << ")"; return context; } diff --git a/include/sqlpp11/mysql/connection.h b/include/sqlpp11/mysql/connection.h index c44957a0..9a7b1ea0 100644 --- a/include/sqlpp11/mysql/connection.h +++ b/include/sqlpp11/mysql/connection.h @@ -272,13 +272,13 @@ namespace sqlpp template static _context_t& _serialize_interpretable(const T& t, _context_t& context) { - return serialize(t, context); + return serialize(context, t); } template static _context_t& _interpret_interpretable(const T& t, _context_t& context) { - return serialize(t, context); + return serialize(context, t); } [[deprecated("Use ping_server() instead")]] bool is_valid() const @@ -295,7 +295,7 @@ namespace sqlpp char_result_t select(const Select& s) { _context_t context{*this}; - serialize(s, context); + serialize(context, s); return select_impl(context.str()); } @@ -303,7 +303,7 @@ namespace sqlpp _prepared_statement_t prepare_select(Select& s) { _context_t context{*this}; - serialize(s, context); + serialize(context, s); return prepare_impl(context.str(), s._get_no_of_parameters(), s.get_no_of_result_columns()); } @@ -319,7 +319,7 @@ namespace sqlpp size_t insert(const Insert& i) { _context_t context{*this}; - serialize(i, context); + serialize(context, i); return insert_impl(context.str()); } @@ -327,7 +327,7 @@ namespace sqlpp _prepared_statement_t prepare_insert(Insert& i) { _context_t context{*this}; - serialize(i, context); + serialize(context, i); return prepare_impl(context.str(), i._get_no_of_parameters(), 0); } @@ -343,7 +343,7 @@ namespace sqlpp size_t update(const Update& u) { _context_t context{*this}; - serialize(u, context); + serialize(context, u); return update_impl(context.str()); } @@ -351,7 +351,7 @@ namespace sqlpp _prepared_statement_t prepare_update(Update& u) { _context_t context{*this}; - serialize(u, context); + serialize(context, u); return prepare_impl(context.str(), u._get_no_of_parameters(), 0); } @@ -367,7 +367,7 @@ namespace sqlpp size_t remove(const Remove& r) { _context_t context{*this}; - serialize(r, context); + serialize(context, r); return remove_impl(context.str()); } @@ -375,7 +375,7 @@ namespace sqlpp _prepared_statement_t prepare_remove(Remove& r) { _context_t context{*this}; - serialize(r, context); + serialize(context, r); return prepare_impl(context.str(), r._get_no_of_parameters(), 0); } diff --git a/include/sqlpp11/no_data.h b/include/sqlpp11/no_data.h index d4c772ff..29f3124d 100644 --- a/include/sqlpp11/no_data.h +++ b/include/sqlpp11/no_data.h @@ -33,7 +33,7 @@ namespace sqlpp }; template - Context& serialize(const no_data_t&, Context& context) + Context& serialize(Context& context, const no_data_t&) { return context; } diff --git a/include/sqlpp11/noop.h b/include/sqlpp11/noop.h index 57f2a7aa..95e2de7b 100644 --- a/include/sqlpp11/noop.h +++ b/include/sqlpp11/noop.h @@ -79,7 +79,7 @@ namespace sqlpp }; template - Context& serialize(const noop&, Context& context) + Context& serialize(Context& context, const noop&) { return context; } diff --git a/include/sqlpp11/offset.h b/include/sqlpp11/offset.h index f6da1d81..ff151882 100644 --- a/include/sqlpp11/offset.h +++ b/include/sqlpp11/offset.h @@ -140,10 +140,10 @@ namespace sqlpp // Interpreters template - Context& serialize(const offset_data_t& t, Context& context) + Context& serialize(Context& context, const offset_data_t& t) { context << " OFFSET "; - serialize_operand(t._value, context); + serialize_operand(context, t._value); return context; } diff --git a/include/sqlpp11/on.h b/include/sqlpp11/on.h index 3783ebab..ef6524d8 100644 --- a/include/sqlpp11/on.h +++ b/include/sqlpp11/on.h @@ -62,16 +62,16 @@ namespace sqlpp }; template - Context& serialize(const on_t&, Context& context) + Context& serialize(Context& context, const on_t&) { return context; } template - Context& serialize(const on_t& t, Context& context) + Context& serialize(Context& context, const on_t& t) { context << " ON "; - serialize(t._expression, context); + serialize(context, t._expression); return context; } } // namespace sqlpp diff --git a/include/sqlpp11/operator/any.h b/include/sqlpp11/operator/any.h index 762f1de7..d4f9cb49 100644 --- a/include/sqlpp11/operator/any.h +++ b/include/sqlpp11/operator/any.h @@ -69,10 +69,10 @@ namespace sqlpp using remove_any_t = typename remove_any::type; template - Context& serialize(const any_t& t) { context << "ANY"; - serialize_operand(t._select, context); + serialize_operand(context, t._select); return context; } diff --git a/include/sqlpp11/operator/as_expression.h b/include/sqlpp11/operator/as_expression.h index 332f0c2c..4a61c125 100644 --- a/include/sqlpp11/operator/as_expression.h +++ b/include/sqlpp11/operator/as_expression.h @@ -72,9 +72,9 @@ namespace sqlpp }; template - Context& serialize(const as_expression& t, Context& context) + Context& serialize(Context& context, const as_expression& t) { - serialize_operand(t._expression, context); + serialize_operand(context, t._expression); context << " AS "; context << name_of>::template char_ptr(); return context; diff --git a/include/sqlpp11/operator/assign_expression.h b/include/sqlpp11/operator/assign_expression.h index 9d19866a..6748f8c6 100644 --- a/include/sqlpp11/operator/assign_expression.h +++ b/include/sqlpp11/operator/assign_expression.h @@ -88,11 +88,11 @@ namespace sqlpp */ template - Context& serialize(const assign_expression& t, Context& context) + Context& serialize(Context& context, const assign_expression& t) { - serialize(simple_column(t._lhs), context); + serialize(context, simple_column(t._lhs)); context << "="; - serialize_operand(t._rhs, context); + serialize_operand(context, t._rhs); return context; } } // namespace sqlpp diff --git a/include/sqlpp11/operator/between_expression.h b/include/sqlpp11/operator/between_expression.h index ccae2570..1a3f1d3f 100644 --- a/include/sqlpp11/operator/between_expression.h +++ b/include/sqlpp11/operator/between_expression.h @@ -94,13 +94,13 @@ namespace sqlpp #if 0 // original serialize implementation template - Context& serialize(const between_t& t, Context& context) + Context& serialize(Context& context, const between_t& t) { - serialize(t._operand, context); + serialize(context, t._operand); context << " IN("; if (sizeof...(Args) == 0) { - serialize(std::get<0>(t._args), context); + serialize(context, std::get<0>(t._args)); } else { @@ -111,9 +111,9 @@ namespace sqlpp } template - Context& serialize(const between_t&, Context& context) + Context& serialize(Context& context, const between_t&) { - serialize(boolean_operand{false}, context); + serialize(context, boolean_operand{false}); return context; } @@ -121,18 +121,18 @@ namespace sqlpp struct value_list_t; template - Context& serialize(const between_t>& t, Context& context) + Context& serialize(Context& context, const between_t>& t) { const auto& value_list = std::get<0>(t._args); if (value_list._container.empty()) { - serialize(boolean_operand{false}, context); + serialize(context, boolean_operand{false}); } else { - serialize(t._operand, context); + serialize(context, t._operand); context << " IN("; - serialize(value_list, context); + serialize(context, value_list); context << ')'; } return context; diff --git a/include/sqlpp11/operator/in_expression.h b/include/sqlpp11/operator/in_expression.h index 132f9c69..15ebbdd6 100644 --- a/include/sqlpp11/operator/in_expression.h +++ b/include/sqlpp11/operator/in_expression.h @@ -132,13 +132,13 @@ namespace sqlpp #if 0 // original serialize implementation template - Context& serialize(const in_t& t, Context& context) + Context& serialize(Context& context, const in_t& t) { - serialize(t._operand, context); + serialize(context, t._operand); context << " IN("; if (sizeof...(Args) == 0) { - serialize(std::get<0>(t._args), context); + serialize(context, std::get<0>(t._args)); } else { @@ -149,9 +149,9 @@ namespace sqlpp } template - Context& serialize(const in_t&, Context& context) + Context& serialize(Context& context, const in_t&) { - serialize(boolean_operand{false}, context); + serialize(context, boolean_operand{false}); return context; } @@ -159,18 +159,18 @@ namespace sqlpp struct value_list_t; template - Context& serialize(const in_t>& t, Context& context) + Context& serialize(Context& context, const in_t>& t) { const auto& value_list = std::get<0>(t._args); if (value_list._container.empty()) { - serialize(boolean_operand{false}, context); + serialize(context, boolean_operand{false}); } else { - serialize(t._operand, context); + serialize(context, t._operand); context << " IN("; - serialize(value_list, context); + serialize(context, value_list); context << ')'; } return context; diff --git a/include/sqlpp11/operator/logical_expression.h b/include/sqlpp11/operator/logical_expression.h index f413f594..d15b83da 100644 --- a/include/sqlpp11/operator/logical_expression.h +++ b/include/sqlpp11/operator/logical_expression.h @@ -134,6 +134,35 @@ namespace sqlpp return to_sql_string(context, t._l) + Operator::symbol + to_sql_string(context, embrace(t._r)); } */ + template + auto serialize_impl(Context& context, const logical_expression& t) -> Context& + { + context << "("; + serialize_operand(context, t._l); + context << Operator::symbol; + serialize_operand(context, t._r); + context << ")"; + return context; + } + + template + auto serialize(Context& context, const logical_expression& t) -> Context& + { + serialize_impl(context, t); + } + + template + auto serialize(Context& context, const logical_expression>& t) -> Context& + { + if (t._r._condition) + { + return serialize_impl(context, t); + } + + // If the dynamic part is inactive ignore it. + serialize(context, t._l); + return context; + } struct logical_and { diff --git a/include/sqlpp11/order_by.h b/include/sqlpp11/order_by.h index a32f222d..2fb20e02 100644 --- a/include/sqlpp11/order_by.h +++ b/include/sqlpp11/order_by.h @@ -146,7 +146,7 @@ namespace sqlpp // Interpreters template - Context& serialize(const order_by_data_t& t, Context& context) + Context& serialize(Context& context, const order_by_data_t& t) { context << " ORDER BY "; interpret_tuple(t._expressions, ',', context); diff --git a/include/sqlpp11/over.h b/include/sqlpp11/over.h index a4485278..8dd955f9 100644 --- a/include/sqlpp11/over.h +++ b/include/sqlpp11/over.h @@ -54,9 +54,9 @@ namespace sqlpp }; template - Context& serialize(const over_t& t, Context& context) + Context& serialize(Context& context, const over_t& t) { - serialize_operand(t._aggregate_expression, context); + serialize_operand(context, t._aggregate_expression); context << " OVER()"; return context; } diff --git a/include/sqlpp11/parameter.h b/include/sqlpp11/parameter.h index a7b4e89a..002f6a5b 100644 --- a/include/sqlpp11/parameter.h +++ b/include/sqlpp11/parameter.h @@ -55,7 +55,7 @@ namespace sqlpp }; template - Context& serialize(const parameter_t&, Context& context) + Context& serialize(Context& context, const parameter_t&) { context << "?"; return context; diff --git a/include/sqlpp11/parameterized_verbatim.h b/include/sqlpp11/parameterized_verbatim.h index 622ad557..cbc72732 100644 --- a/include/sqlpp11/parameterized_verbatim.h +++ b/include/sqlpp11/parameterized_verbatim.h @@ -57,10 +57,10 @@ namespace sqlpp }; template - Context& serialize(const parameterized_verbatim_t& t, Context& context) + Context& serialize(Context& context, const parameterized_verbatim_t& t) { context << t._verbatim_lhs; - serialize(t._expr, context); + serialize(context, t._expr); context << t._verbatim_rhs; return context; } diff --git a/include/sqlpp11/postgresql/connection.h b/include/sqlpp11/postgresql/connection.h index 80a1a84d..f66ee666 100644 --- a/include/sqlpp11/postgresql/connection.h +++ b/include/sqlpp11/postgresql/connection.h @@ -224,13 +224,13 @@ namespace sqlpp template static _context_t& _serialize_interpretable(const T& t, _context_t& context) { - return ::sqlpp::serialize(t, context); + return ::sqlpp::serialize(context, t); } template static _context_t& _interpret_interpretable(const T& t, _context_t& context) { - return ::sqlpp::serialize(t, context); + return ::sqlpp::serialize(context, t); } // Select stmt (returns a result) diff --git a/include/sqlpp11/postgresql/on_conflict_do_nothing.h b/include/sqlpp11/postgresql/on_conflict_do_nothing.h index abc23b9e..79bb2be4 100644 --- a/include/sqlpp11/postgresql/on_conflict_do_nothing.h +++ b/include/sqlpp11/postgresql/on_conflict_do_nothing.h @@ -85,7 +85,7 @@ namespace sqlpp postgresql::context_t& serialize(const postgresql::on_conflict_do_nothing_data_t& o, postgresql::context_t& context) { - serialize(o._column, context); + serialize(context, o._column); context << "DO NOTHING"; return context; } diff --git a/include/sqlpp11/postgresql/on_conflict_do_update.h b/include/sqlpp11/postgresql/on_conflict_do_update.h index 8ddee85f..cc02811f 100644 --- a/include/sqlpp11/postgresql/on_conflict_do_update.h +++ b/include/sqlpp11/postgresql/on_conflict_do_update.h @@ -143,7 +143,7 @@ namespace sqlpp const postgresql::on_conflict_do_update_data_t& o, postgresql::context_t& context) { - serialize(o._conflict_target, context); + serialize(context, o._conflict_target); context << "DO UPDATE SET "; interpret_tuple(o._assignments, ",", context); return context; @@ -154,9 +154,9 @@ namespace sqlpp const postgresql::on_conflict_do_update_where_data_t& o, postgresql::context_t& context) { - serialize(o._assignments, context); + serialize(context, o._assignments); context << " WHERE "; - serialize(o._expression, context); + serialize(context, o._expression); return context; } } // namespace postgresql diff --git a/include/sqlpp11/pre_join.h b/include/sqlpp11/pre_join.h index ddf9beb0..86a3da1b 100644 --- a/include/sqlpp11/pre_join.h +++ b/include/sqlpp11/pre_join.h @@ -133,12 +133,12 @@ namespace sqlpp }; template - Context& serialize(const pre_join_t& t, Context& context) + Context& serialize(Context& context, const pre_join_t& t) { - serialize(t._lhs, context); + serialize(context, t._lhs); context << JoinType::_name; context << " JOIN "; - serialize(t._rhs, context); + serialize(context, t._rhs); return context; } diff --git a/include/sqlpp11/remove.h b/include/sqlpp11/remove.h index aff2e33e..f06631fe 100644 --- a/include/sqlpp11/remove.h +++ b/include/sqlpp11/remove.h @@ -87,7 +87,7 @@ namespace sqlpp }; template - Context& serialize(const remove_name_t&, Context& context) + Context& serialize(Context& context, const remove_name_t&) { context << "DELETE"; diff --git a/include/sqlpp11/schema.h b/include/sqlpp11/schema.h index b7a8e721..bc9b1f9d 100644 --- a/include/sqlpp11/schema.h +++ b/include/sqlpp11/schema.h @@ -36,7 +36,7 @@ namespace sqlpp }; template - Context& serialize(const schema_t& t, Context& context) + Context& serialize(Context& context, const schema_t& t) { context << t._name; return context; diff --git a/include/sqlpp11/schema_qualified_table.h b/include/sqlpp11/schema_qualified_table.h index ef95778c..5727f744 100644 --- a/include/sqlpp11/schema_qualified_table.h +++ b/include/sqlpp11/schema_qualified_table.h @@ -62,11 +62,11 @@ namespace sqlpp }; template - Context& serialize(const schema_qualified_table_t
& t, Context& context) + Context& serialize(Context& context, const schema_qualified_table_t
& t) { - serialize(t._schema, context); + serialize(context, t._schema); context << '.'; - serialize(t._table, context); + serialize(context, t._table); return context; } diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 782b99b2..318f68a1 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -55,7 +55,7 @@ namespace sqlpp }; template - Context& serialize(const select_name_t&, Context& context) + Context& serialize(Context& context, const select_name_t&) { context << "SELECT "; diff --git a/include/sqlpp11/select_column_list.h b/include/sqlpp11/select_column_list.h index 4df422ea..aacf95e7 100644 --- a/include/sqlpp11/select_column_list.h +++ b/include/sqlpp11/select_column_list.h @@ -268,7 +268,7 @@ namespace sqlpp // Interpreters template - Context& serialize(const std::tuple& t, Context& context) + Context& serialize(Context& context, const std::tuple& t) { interpret_tuple(t, ',', context); return context; diff --git a/include/sqlpp11/select_flag_list.h b/include/sqlpp11/select_flag_list.h index 38b99d39..06b3a69b 100644 --- a/include/sqlpp11/select_flag_list.h +++ b/include/sqlpp11/select_flag_list.h @@ -135,7 +135,7 @@ namespace sqlpp // Interpreters template - Context& serialize(const select_flag_list_data_t& t, Context& context) + Context& serialize(Context& context, const select_flag_list_data_t& t) { interpret_tuple(t._flags, ' ', context); if (sizeof...(Flags) != 0u) diff --git a/include/sqlpp11/select_flags.h b/include/sqlpp11/select_flags.h index 2ce0cba8..25bf3f11 100644 --- a/include/sqlpp11/select_flags.h +++ b/include/sqlpp11/select_flags.h @@ -42,7 +42,7 @@ namespace sqlpp static constexpr all_t all = {}; template - Context& serialize(const all_t&, Context& context) + Context& serialize(Context& context, const all_t&) { context << "ALL"; return context; @@ -56,7 +56,7 @@ namespace sqlpp static constexpr distinct_t distinct = {}; template - Context& serialize(const distinct_t&, Context& context) + Context& serialize(Context& context, const distinct_t&) { context << "DISTINCT"; return context; @@ -70,7 +70,7 @@ namespace sqlpp static constexpr straight_join_t straight_join = {}; template - Context& serialize(const straight_join_t&, Context& context) + Context& serialize(Context& context, const straight_join_t&) { context << "STRAIGHT_JOIN"; return context; diff --git a/include/sqlpp11/select_pseudo_table.h b/include/sqlpp11/select_pseudo_table.h index add46101..1b73d350 100644 --- a/include/sqlpp11/select_pseudo_table.h +++ b/include/sqlpp11/select_pseudo_table.h @@ -91,9 +91,9 @@ namespace sqlpp }; template - Context& serialize(const select_pseudo_table_t& t, Context& context) + Context& serialize(Context& context, const select_pseudo_table_t& t) { - serialize(t._select, context); + serialize(context, t._select); return context; } } // namespace sqlpp diff --git a/include/sqlpp11/serialize.h b/include/sqlpp11/serialize.h index 46557fb9..bc40f704 100644 --- a/include/sqlpp11/serialize.h +++ b/include/sqlpp11/serialize.h @@ -30,105 +30,85 @@ namespace sqlpp { - template - auto serialize_operand(const T& t, Context& context) -> Context& - { - if (requires_parens_t::value) - { - context << '('; - serialize(t, context); - context << ')'; - } - else - { - serialize(t, context); - } - - 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& + auto serialize(Context& context, const bool& t) -> Context& { context << t; return context; } template - auto serialize(const int8_t& t, Context& context) -> Context& + auto serialize(Context& context, const int8_t& t) -> Context& { context << t; return context; } template - auto serialize(const int16_t& t, Context& context) -> Context& + auto serialize(Context& context, const int16_t& t) -> Context& { context << t; return context; } template - auto serialize(const int32_t& t, Context& context) -> Context& + auto serialize(Context& context, const int32_t& t) -> Context& { context << t; return context; } template - auto serialize(const int64_t& t, Context& context) -> Context& + auto serialize(Context& context, const int64_t& t) -> Context& { context << t; return context; } template - auto serialize(const uint8_t& t, Context& context) -> Context& + auto serialize(Context& context, const uint8_t& t) -> Context& { context << t; return context; } template - auto serialize(const uint16_t& t, Context& context) -> Context& + auto serialize(Context& context, const uint16_t& t) -> Context& { context << t; return context; } template - auto serialize(const uint32_t& t, Context& context) -> Context& + auto serialize(Context& context, const uint32_t& t) -> Context& { context << t; return context; } template - auto serialize(const uint64_t& t, Context& context) -> Context& + auto serialize(Context& context, const uint64_t& t) -> Context& { context << t; return context; } template - auto serialize(const float& t, Context& context) -> Context& + auto serialize(Context& context, const float& t) -> Context& { context << t; return context; } template - auto serialize(const double& t, Context& context) -> Context& + auto serialize(Context& context, const double& t) -> Context& { #warning: Analyze precision. There was a bug about this... context << t; @@ -136,35 +116,35 @@ namespace sqlpp } template - auto serialize(const char& t, Context& context) -> Context& + auto serialize(Context& context, const char& t) -> Context& { context << t; return context; } template - auto serialize(const char* t, Context& context) -> Context& + auto serialize(Context& context, const char* t) -> Context& { context << t; return context; } template - auto serialize(const std::string& t, Context& context) -> Context& + auto serialize(Context& context, const std::string& t) -> Context& { context << t; return context; } template - auto serialize(const sqlpp::compat::string_view& t, Context& context) -> Context& + auto serialize(Context& context, const sqlpp::compat::string_view& t) -> Context& { context << t; return context; } template - Context& serialize(const std::vector& t, Context& context) + Context& serialize(Context& context, const std::vector& t) { constexpr char hexChars[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; context << "x'"; @@ -178,7 +158,7 @@ namespace sqlpp } template - Context& serialize(const ::sqlpp::chrono::day_point& t, Context& context) + Context& serialize(Context& context, const ::sqlpp::chrono::day_point& t) { const auto ymd = ::date::year_month_day{t}; context << "DATE '" << ymd << "'"; @@ -186,14 +166,14 @@ namespace sqlpp } template - Context& serialize(const std::chrono::microseconds& t, Context& context) + Context& serialize(Context& context, const std::chrono::microseconds& t) { context << '\'' << ::date::make_time(t) << '\''; return context; } template - Context& serialize(const std::chrono::time_point& t, Context& context) + Context& serialize(Context& context, const std::chrono::time_point& t) { const auto dp = ::sqlpp::chrono::floor<::date::days>(t); const auto time = ::date::make_time(t - dp); @@ -203,7 +183,7 @@ namespace sqlpp } template - auto serialize(const sqlpp::compat::optional& t, Context& context) -> Context& + auto serialize(Context& context, const sqlpp::compat::optional& t) -> Context& { if (not t.has_value()) { @@ -211,9 +191,26 @@ namespace sqlpp } else { - serialize(*t, context); + serialize(context, *t); } return context; } + template + auto serialize_operand(Context& context, const T& t) -> Context& + { + if (requires_parens_t::value) + { + context << '('; + serialize(context, t); + context << ')'; + } + else + { + serialize(context, t); + } + + return context; + } + } // namespace sqlpp diff --git a/include/sqlpp11/simple_column.h b/include/sqlpp11/simple_column.h index 7d5060e4..fa309fff 100644 --- a/include/sqlpp11/simple_column.h +++ b/include/sqlpp11/simple_column.h @@ -47,7 +47,7 @@ namespace sqlpp }; template - Context& serialize(const simple_column_t&, Context& context) + Context& serialize(Context& context, const simple_column_t&) { context << name_of::_column_t>::template char_ptr(); return context; diff --git a/include/sqlpp11/single_table.h b/include/sqlpp11/single_table.h index 77287a81..aff0a285 100644 --- a/include/sqlpp11/single_table.h +++ b/include/sqlpp11/single_table.h @@ -138,9 +138,9 @@ namespace sqlpp // Interpreters template - Context& serialize(const single_table_data_t
& t, Context& context) + Context& serialize(Context& context, const single_table_data_t
& t) { - serialize(t._table, context); + serialize(context, t._table); return context; } } // namespace sqlpp diff --git a/include/sqlpp11/sort_order.h b/include/sqlpp11/sort_order.h index 72d0ab6d..9a67adfa 100644 --- a/include/sqlpp11/sort_order.h +++ b/include/sqlpp11/sort_order.h @@ -49,9 +49,9 @@ namespace sqlpp }; template - Context& serialize(const sort_order_t& t, Context& context) + Context& serialize(Context& context, const sort_order_t& t) { - serialize_operand(t._expression, context); + serialize_operand(context, t._expression); switch (t._sort_type) { case sort_type::asc: diff --git a/include/sqlpp11/sqlite3/connection.h b/include/sqlpp11/sqlite3/connection.h index 63aac63c..79544910 100644 --- a/include/sqlpp11/sqlite3/connection.h +++ b/include/sqlpp11/sqlite3/connection.h @@ -249,13 +249,13 @@ namespace sqlpp template static _context_t& _serialize_interpretable(const T& t, _context_t& context) { - return ::sqlpp::serialize(t, context); + return ::sqlpp::serialize(context, t); } template static _context_t& _interpret_interpretable(const T& t, _context_t& context) { - return ::sqlpp::serialize(t, context); + return ::sqlpp::serialize(context, t); } //! select returns a result (which can be iterated row by row) @@ -263,7 +263,7 @@ namespace sqlpp bind_result_t select(const Select& s) { _context_t context{*this}; - serialize(s, context); + serialize(context, s); return select_impl(context.str()); } @@ -271,7 +271,7 @@ namespace sqlpp _prepared_statement_t prepare_select(Select& s) { _context_t context{*this}; - serialize(s, context); + serialize(context, s); return prepare_impl(context.str()); } @@ -288,7 +288,7 @@ namespace sqlpp size_t insert(const Insert& i) { _context_t context{*this}; - serialize(i, context); + serialize(context, i); return insert_impl(context.str()); } @@ -296,7 +296,7 @@ namespace sqlpp _prepared_statement_t prepare_insert(Insert& i) { _context_t context{*this}; - serialize(i, context); + serialize(context, i); return prepare_impl(context.str()); } @@ -313,7 +313,7 @@ namespace sqlpp size_t update(const Update& u) { _context_t context{*this}; - serialize(u, context); + serialize(context, u); return update_impl(context.str()); } @@ -321,7 +321,7 @@ namespace sqlpp _prepared_statement_t prepare_update(Update& u) { _context_t context{*this}; - serialize(u, context); + serialize(context, u); return prepare_impl(context.str()); } @@ -338,7 +338,7 @@ namespace sqlpp size_t remove(const Remove& r) { _context_t context{*this}; - serialize(r, context); + serialize(context, r); return remove_impl(context.str()); } @@ -346,7 +346,7 @@ namespace sqlpp _prepared_statement_t prepare_remove(Remove& r) { _context_t context{*this}; - serialize(r, context); + serialize(context, r); return prepare_impl(context.str()); } @@ -373,7 +373,7 @@ namespace sqlpp size_t execute(const Execute& x) { _context_t context{*this}; - serialize(x, context); + serialize(context, x); return execute(context.str()); } @@ -381,7 +381,7 @@ namespace sqlpp _prepared_statement_t prepare_execute(Execute& x) { _context_t context{*this}; - serialize(x, context); + serialize(context, x); return prepare_impl(context.str()); } diff --git a/include/sqlpp11/statement.h b/include/sqlpp11/statement.h index 62b8359c..5d1584e5 100644 --- a/include/sqlpp11/statement.h +++ b/include/sqlpp11/statement.h @@ -268,12 +268,12 @@ namespace sqlpp struct value_type_of> : value_type_of> {}; template - Context& serialize(const statement_t& t, Context& context) + Context& serialize(Context& context, const statement_t& t) { using P = detail::statement_policies_t; using swallow = int[]; - (void)swallow{0, (serialize(static_cast&>(t)._data, context), 0)...}; + (void)swallow{0, (serialize(context, static_cast&>(t)._data), 0)...}; return context; } diff --git a/include/sqlpp11/table.h b/include/sqlpp11/table.h index 45db9ac4..4940bfab 100644 --- a/include/sqlpp11/table.h +++ b/include/sqlpp11/table.h @@ -97,7 +97,7 @@ namespace sqlpp }; template - Context& serialize(const table_t& /*unused*/, Context& context) + Context& serialize(Context& context, const table_t& /*unused*/) { context << name_of
::template char_ptr(); return context; diff --git a/include/sqlpp11/table_alias.h b/include/sqlpp11/table_alias.h index bee596d9..d2e76fad 100644 --- a/include/sqlpp11/table_alias.h +++ b/include/sqlpp11/table_alias.h @@ -99,13 +99,13 @@ namespace sqlpp }; template - Context& serialize(const table_alias_t& t, Context& context) + Context& serialize(Context& context, const table_alias_t& t) { if (requires_parens_t
::value) { context << "("; } - serialize(t._table, context); + serialize(context, t._table); if (requires_parens_t
::value) { context << ")"; diff --git a/include/sqlpp11/trim.h b/include/sqlpp11/trim.h index ac03006c..47b76c5f 100644 --- a/include/sqlpp11/trim.h +++ b/include/sqlpp11/trim.h @@ -53,10 +53,10 @@ namespace sqlpp }; template - Context& serialize(const trim_t& t, Context& context) + Context& serialize(Context& context, const trim_t& t) { context << "TRIM("; - serialize_operand(t._expr, context); + serialize_operand(context, t._expr); context << ")"; return context; } diff --git a/include/sqlpp11/union_data.h b/include/sqlpp11/union_data.h index ae4a4b7e..54e54371 100644 --- a/include/sqlpp11/union_data.h +++ b/include/sqlpp11/union_data.h @@ -47,13 +47,13 @@ namespace sqlpp // Interpreters template - Context& serialize(const union_data_t& t, Context& context) + Context& serialize(Context& context, const union_data_t& t) { - serialize(t._lhs, context); + serialize(context, t._lhs); context << " UNION "; - serialize(Flag{}, context); + serialize(context, Flag{}); context << " "; - serialize(t._rhs, context); + serialize(context, t._rhs); return context; } } // namespace sqlpp diff --git a/include/sqlpp11/union_flags.h b/include/sqlpp11/union_flags.h index e5c36d67..6c2d087f 100644 --- a/include/sqlpp11/union_flags.h +++ b/include/sqlpp11/union_flags.h @@ -41,7 +41,7 @@ namespace sqlpp }; template - Context& serialize(const union_all_t&, Context& context) + Context& serialize(Context& context, const union_all_t&) { context << "ALL"; return context; @@ -54,7 +54,7 @@ namespace sqlpp }; template - Context& serialize(const union_distinct_t&, Context& context) + Context& serialize(Context& context, const union_distinct_t&) { return context; } diff --git a/include/sqlpp11/update.h b/include/sqlpp11/update.h index a2e5fa35..717ab3ca 100644 --- a/include/sqlpp11/update.h +++ b/include/sqlpp11/update.h @@ -88,7 +88,7 @@ namespace sqlpp }; template - Context& serialize(const update_name_t&, Context& context) + Context& serialize(Context& context, const update_name_t&) { context << "UPDATE "; return context; diff --git a/include/sqlpp11/update_list.h b/include/sqlpp11/update_list.h index 7ba9959b..7ecd1733 100644 --- a/include/sqlpp11/update_list.h +++ b/include/sqlpp11/update_list.h @@ -165,7 +165,7 @@ namespace sqlpp // Interpreters template - Context& serialize(const update_list_data_t& t, Context& context) + Context& serialize(Context& context, const update_list_data_t& t) { context << " SET "; interpret_tuple(t._assignments, ",", context); diff --git a/include/sqlpp11/upper.h b/include/sqlpp11/upper.h index db4ab13c..466e739b 100644 --- a/include/sqlpp11/upper.h +++ b/include/sqlpp11/upper.h @@ -52,10 +52,10 @@ namespace sqlpp }; template - Context& serialize(const upper_t& t, Context& context) + Context& serialize(Context& context, const upper_t& t) { context << "UPPER("; - serialize_operand(t._expr, context); + serialize_operand(context, t._expr); context << ")"; return context; } diff --git a/include/sqlpp11/using.h b/include/sqlpp11/using.h index 9aefdd0b..39f17135 100644 --- a/include/sqlpp11/using.h +++ b/include/sqlpp11/using.h @@ -136,7 +136,7 @@ namespace sqlpp // Interpreters template - Context& serialize(const using_data_t& t, Context& context) + Context& serialize(Context& context, const using_data_t& t) { context << " USING "; interpret_tuple(t._tables, ',', context); diff --git a/include/sqlpp11/value.h b/include/sqlpp11/value.h index f74eea04..b4db9d76 100644 --- a/include/sqlpp11/value.h +++ b/include/sqlpp11/value.h @@ -54,10 +54,10 @@ namespace sqlpp using check_value_arg = std::enable_if_t, no_value_t>::value and values_are_comparable::value>; template - Context& serialize(const value_t& t, Context& context) + Context& serialize(Context& context, const value_t& t) { #warning: Untested - serialize(t._value, context); + serialize(context, t._value); return context; } diff --git a/include/sqlpp11/verbatim.h b/include/sqlpp11/verbatim.h index af0b9b7c..80990fa0 100644 --- a/include/sqlpp11/verbatim.h +++ b/include/sqlpp11/verbatim.h @@ -56,7 +56,7 @@ namespace sqlpp }; template - Context& serialize(const verbatim_t& t, Context& context) + Context& serialize(Context& context, const verbatim_t& t) { context << t._verbatim; return context; diff --git a/include/sqlpp11/verbatim_table.h b/include/sqlpp11/verbatim_table.h index a1c0b91c..b1931593 100644 --- a/include/sqlpp11/verbatim_table.h +++ b/include/sqlpp11/verbatim_table.h @@ -75,7 +75,7 @@ namespace sqlpp }; template - Context& serialize(const verbatim_table_t& t, Context& context) + Context& serialize(Context& context, const verbatim_table_t& t) { context << t._representation; return context; diff --git a/include/sqlpp11/where.h b/include/sqlpp11/where.h index c13860eb..614e4dc1 100644 --- a/include/sqlpp11/where.h +++ b/include/sqlpp11/where.h @@ -199,15 +199,15 @@ namespace sqlpp // Interpreters template - Context& serialize(const where_data_t& t, Context& context) + Context& serialize(Context& context, const where_data_t& t) { context << " WHERE "; - serialize(t._expression, context); + serialize(context, t._expression); return context; } template - Context& serialize(const where_data_t&, Context& context) + Context& serialize(Context& context, const where_data_t&) { return context; } diff --git a/include/sqlpp11/with.h b/include/sqlpp11/with.h index 0f0ca995..89efdb9f 100644 --- a/include/sqlpp11/with.h +++ b/include/sqlpp11/with.h @@ -124,7 +124,7 @@ namespace sqlpp // Interpreters template - Context& serialize(const with_data_t& t, Context& context) + Context& serialize(Context& context, const with_data_t& t) { using T = with_data_t; // FIXME: If there is a recursive CTE, add a "RECURSIVE" here diff --git a/include/sqlpp11/without_table_check.h b/include/sqlpp11/without_table_check.h index 2db10d11..793d83b4 100644 --- a/include/sqlpp11/without_table_check.h +++ b/include/sqlpp11/without_table_check.h @@ -43,9 +43,9 @@ namespace sqlpp }; template - Context& serialize(const without_table_check_t& t, Context& context) + Context& serialize(Context& context, const without_table_check_t& t) { - serialize(t.expr(), context); + serialize(context, t.expr()); return context; } diff --git a/tests/core/serialize/CMakeLists.txt b/tests/core/serialize/CMakeLists.txt index 092c9593..ec2a69c7 100644 --- a/tests/core/serialize/CMakeLists.txt +++ b/tests/core/serialize/CMakeLists.txt @@ -24,36 +24,36 @@ set(test_files logical_expression.cpp - Any.cpp - As.cpp - Avg.cpp - Blob.cpp - Count.cpp - CustomQuery.cpp - DynamicWhere.cpp - Exists.cpp - Float.cpp - ForUpdate.cpp - From.cpp - In.cpp - Insert.cpp - IsNotNull.cpp - IsNull.cpp - Lower.cpp - Max.cpp - Min.cpp - Operator.cpp - Over.cpp - SelectAs.cpp - SelectColumns.cpp - SelectFlags.cpp - Some.cpp - Sum.cpp - TableAlias.cpp - Trim.cpp - Upper.cpp - Where.cpp - ParameterizedVerbatim.cpp +#Any.cpp +#As.cpp +#Avg.cpp +#Blob.cpp +#Count.cpp +#CustomQuery.cpp +#DynamicWhere.cpp +#Exists.cpp +#Float.cpp +#ForUpdate.cpp +#From.cpp +#In.cpp +#Insert.cpp +#IsNotNull.cpp +#IsNull.cpp +#Lower.cpp +#Max.cpp +#Min.cpp +#Operator.cpp +#Over.cpp +#SelectAs.cpp +#SelectColumns.cpp +#SelectFlags.cpp +#Some.cpp +#Sum.cpp +#TableAlias.cpp +#Trim.cpp +#Upper.cpp +#Where.cpp +#ParameterizedVerbatim.cpp ) create_test_sourcelist(test_sources test_serializer_main.cpp ${test_files}) diff --git a/tests/core/serialize/compare.h b/tests/core/serialize/compare.h index 52c75e48..88022400 100644 --- a/tests/core/serialize/compare.h +++ b/tests/core/serialize/compare.h @@ -46,7 +46,7 @@ namespace { MockDb::_serializer_context_t printer = {}; - const auto result = serialize(expr, printer).str(); + const auto result = serialize(printer, expr).str(); assert_equal(lineNo, result, expected); } diff --git a/tests/core/serialize/logical_expression.cpp b/tests/core/serialize/logical_expression.cpp new file mode 100644 index 00000000..c4d16ac1 --- /dev/null +++ b/tests/core/serialize/logical_expression.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2021-2021, Roland Bock + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "Sample.h" +#include "compare.h" +#include + +#include + +int logical_expression(int, char* []) +{ + const auto foo = test::TabFoo{}; + const auto bar = test::TabBar{}; + + /* + // Plus + compare(__LINE__, bar.id + 3u, "(tab_bar.id+3)"); + compare(__LINE__, sqlpp::value(3) + foo.uIntN, "(3+tab_foo.u_int_n)"); + + // Shift left + compare(__LINE__, sqlpp::value(3) << foo.uIntN, "(3<> foo.uIntN, "(3>>tab_foo.u_int_n)"); + compare(__LINE__, bar.id >> 3u, "(tab_bar.id>>3)"); + + // Comparison + compare(__LINE__, bar.id < 3u, "(tab_bar.id<3)"); + compare(__LINE__, bar.id <= 3u, "(tab_bar.id<=3)"); + compare(__LINE__, bar.id == 3u, "(tab_bar.id=3)"); + compare(__LINE__, bar.id != 3u, "(tab_bar.id<>3)"); + compare(__LINE__, bar.id >= 3u, "(tab_bar.id>=3)"); + compare(__LINE__, bar.id > 3u, "(tab_bar.id>3)"); + */ + +#warning: Consider reducing braces a bit as in sqlpp17 + compare(__LINE__, true and dynamic(true, bar.boolNn), "(1 AND tab_bar.bool_nn)"); + compare(__LINE__, true and dynamic(false, bar.boolNn), "1"); + + return 0; +}