diff --git a/include/sqlpp11/alias.h b/include/sqlpp11/alias.h index ea2c28ee..d53c3c83 100644 --- a/include/sqlpp11/alias.h +++ b/include/sqlpp11/alias.h @@ -57,19 +57,13 @@ namespace sqlpp }; template - struct serializer_t> + Context& serialize(const expression_alias_t& t, Context& context) { - using _serialize_check = serialize_check_of; - using T = expression_alias_t; - - static Context& _(const T& t, Context& context) - { - serialize_operand(t._expression, context); - context << " AS "; - context << name_of::template char_ptr(); - return context; - } - }; + serialize_operand(t._expression, context); + context << " AS "; + context << name_of>::template char_ptr(); + return context; + } } // namespace sqlpp #endif diff --git a/include/sqlpp11/column.h b/include/sqlpp11/column.h index b22dd3b8..74c310ba 100644 --- a/include/sqlpp11/column.h +++ b/include/sqlpp11/column.h @@ -109,32 +109,15 @@ namespace sqlpp } }; - // workaround for msvs bug https://connect.microsoft.com/VisualStudio/feedback/details/2173053 - // template - // struct serializer_t> - // { - // using _serialize_check = consistent_t; - // using T = column_t; - // - // static Context& _(const T&, Context& context) - // { - // context << name_of::char_ptr() << '.' << name_of::char_ptr(); - // return context; - // } - // }; - template - struct serializer_t> + template + Context& serialize(const column_t&, Context& context) { - using _serialize_check = consistent_t; - using T = column_t; + using T = column_t; - static Context& _(const T& /*unused*/, Context& context) - { - context << name_of::template char_ptr() << '.' - << name_of::template char_ptr(); - return context; - } - }; + context << name_of::template char_ptr() << '.' + << name_of::template char_ptr(); + return context; + } } // namespace sqlpp #endif diff --git a/include/sqlpp11/data_types/blob/operand.h b/include/sqlpp11/data_types/blob/operand.h index f8a407be..e3af17e2 100644 --- a/include/sqlpp11/data_types/blob/operand.h +++ b/include/sqlpp11/data_types/blob/operand.h @@ -67,23 +67,17 @@ namespace sqlpp }; template - struct serializer_t + Context& serialize(const blob_operand& t, Context& context) { - using _serialize_check = consistent_t; - using Operand = blob_operand; - - static Context& _(const Operand& t, Context& context) + constexpr char hexChars[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + context << "x'"; + for (const auto c : t._t) { - constexpr char hexChars[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; - context << "x'"; - for (const auto c : t._t) - { - context << hexChars[c >> 4] << hexChars[c & 0x0F]; - } - context << '\''; - - return context; + context << hexChars[c >> 4] << hexChars[c & 0x0F]; } - }; + context << '\''; + + return context; + } } // namespace sqlpp #endif diff --git a/include/sqlpp11/data_types/boolean/operand.h b/include/sqlpp11/data_types/boolean/operand.h index e220ca9a..e5421a9b 100644 --- a/include/sqlpp11/data_types/boolean/operand.h +++ b/include/sqlpp11/data_types/boolean/operand.h @@ -63,17 +63,11 @@ namespace sqlpp }; template - struct serializer_t + Context& serialize(const boolean_operand& t, Context& context) { - using _serialize_check = consistent_t; - using Operand = boolean_operand; - - static Context& _(const Operand& t, Context& context) - { - context << t._t; - return context; - } - }; + context << t._t; + return context; + } } // namespace sqlpp #endif diff --git a/include/sqlpp11/data_types/day_point/operand.h b/include/sqlpp11/data_types/day_point/operand.h index 74b9f86c..e805309d 100644 --- a/include/sqlpp11/data_types/day_point/operand.h +++ b/include/sqlpp11/data_types/day_point/operand.h @@ -61,17 +61,11 @@ namespace sqlpp }; template - struct serializer_t + Context& serialize(const day_point_operand& t, Context& context) { - using _serialize_check = consistent_t; - using Operand = day_point_operand; - - static Context& _(const Operand& t, Context& context) - { - const auto ymd = ::date::year_month_day{t._t}; - context << "DATE '" << ymd << "'"; - return context; - } - }; + const auto ymd = ::date::year_month_day{t._t}; + context << "DATE '" << ymd << "'"; + return context; + } } // namespace sqlpp #endif diff --git a/include/sqlpp11/data_types/floating_point/operand.h b/include/sqlpp11/data_types/floating_point/operand.h index e756d792..c6de06f9 100644 --- a/include/sqlpp11/data_types/floating_point/operand.h +++ b/include/sqlpp11/data_types/floating_point/operand.h @@ -59,16 +59,10 @@ namespace sqlpp }; template - struct serializer_t + Context& serialize(const floating_point_operand& t, Context& context) { - using _serialize_check = consistent_t; - using Operand = floating_point_operand; - - static Context& _(const Operand& t, Context& context) - { - context << t._t; - return context; - } - }; + context << t._t; + return context; + } } // namespace sqlpp #endif diff --git a/include/sqlpp11/data_types/integral/operand.h b/include/sqlpp11/data_types/integral/operand.h index c858c97d..35da87b4 100644 --- a/include/sqlpp11/data_types/integral/operand.h +++ b/include/sqlpp11/data_types/integral/operand.h @@ -61,17 +61,11 @@ namespace sqlpp }; template - struct serializer_t + Context& serialize(const integral_operand& t, Context& context) { - using _serialize_check = consistent_t; - using Operand = integral_operand; - - static Context& _(const Operand& t, Context& context) - { - context << t._t; - return context; - } - }; + context << t._t; + return context; + } } // namespace sqlpp #endif diff --git a/include/sqlpp11/data_types/text/concat.h b/include/sqlpp11/data_types/text/concat.h index 6102cc24..f488f12b 100644 --- a/include/sqlpp11/data_types/text/concat.h +++ b/include/sqlpp11/data_types/text/concat.h @@ -75,19 +75,13 @@ namespace sqlpp }; template - struct serializer_t> + Context& serialize(const concat_t& t, Context& context) { - using _serialize_check = serialize_check_of; - using T = concat_t; - - static Context& _(const T& t, Context& context) - { - context << "("; - interpret_tuple(t._args, "||", context); - context << ")"; - return context; - } - }; + context << "("; + interpret_tuple(t._args, "||", context); + context << ")"; + return context; + } template auto concat(Args... args) -> concat_t diff --git a/include/sqlpp11/data_types/text/like.h b/include/sqlpp11/data_types/text/like.h index 288e4cdb..fc7e5710 100644 --- a/include/sqlpp11/data_types/text/like.h +++ b/include/sqlpp11/data_types/text/like.h @@ -79,20 +79,14 @@ namespace sqlpp }; template - struct serializer_t> + Context& serialize(const like_t& t, Context& context) { - using _serialize_check = serialize_check_of; - using T = like_t; - - static Context& _(const T& t, Context& context) - { - serialize_operand(t._operand, context); - context << " LIKE("; - serialize(t._pattern, context); - context << ")"; - return context; - } - }; + serialize_operand(t._operand, context); + context << " LIKE("; + serialize(t._pattern, context); + context << ")"; + return context; + } } // namespace sqlpp #endif diff --git a/include/sqlpp11/data_types/text/operand.h b/include/sqlpp11/data_types/text/operand.h index 3cd3b809..4d136803 100644 --- a/include/sqlpp11/data_types/text/operand.h +++ b/include/sqlpp11/data_types/text/operand.h @@ -74,16 +74,10 @@ namespace sqlpp }; template - struct serializer_t + Context& serialize(const text_operand& t, Context& context) { - using _serialize_check = consistent_t; - using Operand = text_operand; - - static Context& _(const Operand& t, Context& context) - { - context << '\'' << context.escape(t._t) << '\''; - return context; - } - }; + context << '\'' << context.escape(t._t) << '\''; + return context; + } } // namespace sqlpp #endif diff --git a/include/sqlpp11/data_types/time_of_day/operand.h b/include/sqlpp11/data_types/time_of_day/operand.h index 6ff50c50..824b019b 100644 --- a/include/sqlpp11/data_types/time_of_day/operand.h +++ b/include/sqlpp11/data_types/time_of_day/operand.h @@ -63,16 +63,10 @@ namespace sqlpp }; template - struct serializer_t> + Context& serialize(const time_of_day_operand& t, Context& context) { - using _serialize_check = consistent_t; - using Operand = time_of_day_operand; - - static Context& _(const Operand& t, Context& context) - { - context << '\'' << ::date::make_time(t._t) << '\''; - return context; - } - }; + context << '\'' << ::date::make_time(t._t) << '\''; + return context; + } } // namespace sqlpp #endif diff --git a/include/sqlpp11/data_types/time_point/operand.h b/include/sqlpp11/data_types/time_point/operand.h index 188564f5..297abcd5 100644 --- a/include/sqlpp11/data_types/time_point/operand.h +++ b/include/sqlpp11/data_types/time_point/operand.h @@ -63,19 +63,13 @@ namespace sqlpp }; template - struct serializer_t> + Context& serialize(const time_point_operand& t, Context& context) { - using _serialize_check = consistent_t; - using Operand = time_point_operand; - - static Context& _(const Operand& t, Context& context) - { - const auto dp = ::sqlpp::chrono::floor<::date::days>(t._t); - const auto time = ::date::make_time(t._t - dp); - const auto ymd = ::date::year_month_day{dp}; - context << "TIMESTAMP '" << ymd << ' ' << time << "'"; - return context; - } - }; + const auto dp = ::sqlpp::chrono::floor<::date::days>(t._t); + const auto time = ::date::make_time(t._t - dp); + const auto ymd = ::date::year_month_day{dp}; + context << "TIMESTAMP '" << ymd << ' ' << time << "'"; + return context; + } } // namespace sqlpp #endif diff --git a/include/sqlpp11/data_types/unsigned_integral/operand.h b/include/sqlpp11/data_types/unsigned_integral/operand.h index 333c60e4..94d4498a 100644 --- a/include/sqlpp11/data_types/unsigned_integral/operand.h +++ b/include/sqlpp11/data_types/unsigned_integral/operand.h @@ -61,17 +61,11 @@ namespace sqlpp }; template - struct serializer_t + Context& serialize(const unsigned_integral_operand& t, Context& context) { - using _serialize_check = consistent_t; - using Operand = unsigned_integral_operand; - - static Context& _(const Operand& t, Context& context) - { - context << t._t; - return context; - } - }; + context << t._t; + return context; + } } // namespace sqlpp #endif diff --git a/include/sqlpp11/dynamic_select_column_list.h b/include/sqlpp11/dynamic_select_column_list.h index 4491c07d..5210ab75 100644 --- a/include/sqlpp11/dynamic_select_column_list.h +++ b/include/sqlpp11/dynamic_select_column_list.h @@ -77,39 +77,29 @@ namespace sqlpp }; template - struct serializer_t> + Context& serialize(const dynamic_select_column_list& t, Context& context) { - using T = dynamic_select_column_list; - - static Context& _(const T& t, Context& context) + bool first = true; + for (const auto column : t._dynamic_columns) { - bool first = true; - for (const auto column : t._dynamic_columns) + if (first) { - if (first) - { - first = false; - } - else - { - context << ','; - } - serialize(column, context); + first = false; } - return context; + else + { + context << ','; + } + serialize(column, context); } - }; + return context; + } template - struct serializer_t> + Context& serialize(const dynamic_select_column_list&, Context& context) { - using T = dynamic_select_column_list; - - static Context& _(const T& /*unused*/, Context& context) - { - return context; - } - }; + return context; + } } // namespace sqlpp #endif diff --git a/include/sqlpp11/exists.h b/include/sqlpp11/exists.h index 2aaa9a50..22f5bf25 100644 --- a/include/sqlpp11/exists.h +++ b/include/sqlpp11/exists.h @@ -78,19 +78,13 @@ namespace sqlpp }; template - struct serializer_t> + Context& serialize(const exists_t; - - static Context& _(const T& t, Context& context) - { - context << "EXISTS("; - serialize(t._select, context); - context << ")"; - return context; - } - }; + context << "EXISTS("; + serialize(t._select, context); + context << ")"; + return context; + } template auto exists(T t) -> exists_t> diff --git a/include/sqlpp11/expression.h b/include/sqlpp11/expression.h index e6abd73e..586724b5 100644 --- a/include/sqlpp11/expression.h +++ b/include/sqlpp11/expression.h @@ -61,21 +61,15 @@ namespace sqlpp }; template - struct serializer_t> + Context& serialize(const binary_expression_t& t, Context& context) { - using T = binary_expression_t; - using _serialize_check = serialize_check_of; - - static Context& _(const T& t, Context& context) - { - context << "("; - serialize_operand(t._lhs, context); - context << "="; - serialize_operand(t._rhs, context); - context << ")"; - return context; - } - }; + context << "("; + serialize_operand(t._lhs, context); + context << "="; + serialize_operand(t._rhs, context); + context << ")"; + return context; + } template struct binary_expression_t @@ -102,21 +96,15 @@ namespace sqlpp }; template - struct serializer_t> + Context& serialize(const binary_expression_t& t, Context& context) { - using T = binary_expression_t; - using _serialize_check = serialize_check_of; - - static Context& _(const T& t, Context& context) - { - context << "("; - serialize_operand(t._lhs, context); - context << "<>"; - serialize_operand(t._rhs, context); - context << ")"; - return context; - } - }; + context << "("; + serialize_operand(t._lhs, context); + context << "<>"; + serialize_operand(t._rhs, context); + context << ")"; + return context; + } template struct unary_expression_t @@ -140,21 +128,15 @@ namespace sqlpp }; template - struct serializer_t> + Context& serialize(const unary_expression_t& t, Context& context) { - using _serialize_check = serialize_check_of; - using T = unary_expression_t; + context << "("; + context << "NOT "; + serialize_operand(t._rhs, context); + context << ")"; - static Context& _(const T& t, Context& context) - { - context << "("; - context << "NOT "; - serialize_operand(t._rhs, context); - context << ")"; - - return context; - } - }; + return context; + } template struct binary_expression_t : public expression_operators, value_type_of>, @@ -178,21 +160,15 @@ namespace sqlpp }; template - struct serializer_t> + Context& serialize(const binary_expression_t& t, Context& context) { - using _serialize_check = serialize_check_of; - using T = binary_expression_t; - - static Context& _(const T& t, Context& context) - { - context << "("; - serialize_operand(t._lhs, context); - context << O::_name; - serialize_operand(t._rhs, context); - context << ")"; - return context; - } - }; + context << "("; + serialize_operand(t._lhs, context); + context << O::_name; + serialize_operand(t._rhs, context); + context << ")"; + return context; + } template struct unary_expression_t : public expression_operators, value_type_of>, @@ -215,20 +191,14 @@ namespace sqlpp }; template - struct serializer_t> + Context& serialize(const unary_expression_t& t, Context& context) { - using _serialize_check = serialize_check_of; - using T = unary_expression_t; - - static Context& _(const T& t, Context& context) - { - context << "("; - context << O::_name; - serialize_operand(t._rhs, context); - context << ")"; - return context; - } - }; + context << "("; + context << O::_name; + serialize_operand(t._rhs, context); + context << ")"; + return context; + } } // namespace sqlpp #endif diff --git a/include/sqlpp11/group_by.h b/include/sqlpp11/group_by.h index 91985459..81ab2fb6 100644 --- a/include/sqlpp11/group_by.h +++ b/include/sqlpp11/group_by.h @@ -252,27 +252,21 @@ namespace sqlpp // Interpreters template - struct serializer_t> + Context& serialize(const group_by_data_t& t, Context& context) { - using _serialize_check = serialize_check_of; - using T = group_by_data_t; - - static Context& _(const T& t, Context& context) + if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty()) { - if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty()) - { - return context; - } - context << " GROUP BY "; - interpret_tuple(t._expressions, ',', context); - if (sizeof...(Expressions) and not t._dynamic_expressions.empty()) - { - context << ','; - } - interpret_list(t._dynamic_expressions, ',', context); return context; } - }; + context << " GROUP BY "; + interpret_tuple(t._expressions, ',', context); + if (sizeof...(Expressions) and not t._dynamic_expressions.empty()) + { + context << ','; + } + interpret_list(t._dynamic_expressions, ',', context); + return context; + } template auto group_by(T&&... t) -> decltype(statement_t().group_by(std::forward(t)...)) diff --git a/include/sqlpp11/named_interpretable.h b/include/sqlpp11/named_interpretable.h index 68309024..e85120b2 100644 --- a/include/sqlpp11/named_interpretable.h +++ b/include/sqlpp11/named_interpretable.h @@ -49,9 +49,9 @@ namespace sqlpp named_interpretable_t& operator=(named_interpretable_t&&) = default; ~named_interpretable_t() = default; - _serializer_context_t& serialize(_serializer_context_t& context) const + _serializer_context_t& interpret(_serializer_context_t& context) const { - return _impl->serialize(context); + return _impl->interpret(context); } std::string _get_name() const @@ -65,7 +65,7 @@ namespace sqlpp struct _impl_base { virtual ~_impl_base() = default; - virtual _serializer_context_t& serialize(_serializer_context_t& context) const = 0; + virtual _serializer_context_t& interpret(_serializer_context_t& context) const = 0; virtual std::string _get_name() const = 0; }; @@ -77,9 +77,9 @@ namespace sqlpp { } - _serializer_context_t& serialize(_serializer_context_t& context) const + _serializer_context_t& interpret(_serializer_context_t& context) const { - ::sqlpp::serialize(_t, context); + interpret(_t, context); return context; } @@ -95,27 +95,21 @@ namespace sqlpp }; template - struct serializer_t> + Context& serialize(const named_interpretable_t& t, Context& context) { - using _serialize_check = consistent_t; - using T = named_interpretable_t; - - static Context& _(const T& t, Context& context) + if (t._requires_braces) { - if (t._requires_braces) - { - context << '('; - t.serialize(context); - context << ')'; - } - else - { - t.serialize(context); - } - - return context; + context << '('; + t.interpret(context); + context << ')'; } - }; + else + { + t.interpret(context); + } + + return context; + } } // namespace sqlpp #endif diff --git a/include/sqlpp11/no_data.h b/include/sqlpp11/no_data.h index a8596d0c..e736dac1 100644 --- a/include/sqlpp11/no_data.h +++ b/include/sqlpp11/no_data.h @@ -37,15 +37,9 @@ namespace sqlpp }; template - struct serializer_t + Context& serialize(const no_data_t&, Context& context) { - using _serialize_check = consistent_t; - using T = no_data_t; - - static Context& _(const T& /*unused*/, Context& context) - { - return context; - } - }; + return context; + } } // namespace sqlpp #endif diff --git a/include/sqlpp11/noop.h b/include/sqlpp11/noop.h index 5d0ee40d..e5afa6e0 100644 --- a/include/sqlpp11/noop.h +++ b/include/sqlpp11/noop.h @@ -82,16 +82,10 @@ namespace sqlpp }; template - struct serializer_t + Context& serialize(const noop&, Context& context) { - using _serialize_check = consistent_t; - using T = noop; - - static Context& _(const T& /*unused*/, Context& context) - { - return context; - } - }; + return context; + } template struct is_noop : std::is_same diff --git a/include/sqlpp11/not_in.h b/include/sqlpp11/not_in.h index 08261a71..e54fab86 100644 --- a/include/sqlpp11/not_in.h +++ b/include/sqlpp11/not_in.h @@ -73,67 +73,49 @@ namespace sqlpp }; template - struct serializer_t> + Context& serialize(const not_in_t& t, Context& context) { - using _serialize_check = serialize_check_of; - using T = not_in_t; - - static Context& _(const T& t, Context& context) + serialize_operand(t._operand, context); + context << " NOT IN("; + if (sizeof...(Args) == 1) { - serialize_operand(t._operand, context); - context << " NOT IN("; - if (sizeof...(Args) == 1) - { - serialize(std::get<0>(t._args), context); - } - else - { - interpret_tuple(t._args, ',', context); - } - context << ')'; - return context; + serialize(std::get<0>(t._args), context); } - }; + else + { + interpret_tuple(t._args, ',', context); + } + context << ')'; + return context; + } template - struct serializer_t> + Context& serialize(const not_in_t&, Context& context) { - using _serialize_check = consistent_t; - using T = not_in_t; - - static Context& _(const T& /*unused*/, Context& context) - { - serialize(boolean_operand{true}, context); - return context; - } - }; + serialize(boolean_operand{true}, context); + return context; + } template struct value_list_t; template - struct serializer_t>> + Context& serialize(const not_in_t>& t, Context& context) { - using _serialize_check = serialize_check_of>; - using T = not_in_t>; - - static Context& _(const T& t, Context& context) + const auto& value_list = std::get<0>(t._args); + if (value_list._container.empty()) { - const auto& value_list = std::get<0>(t._args); - if (value_list._container.empty()) - { - serialize(boolean_operand{true}, context); - } - else - { - serialize(t._operand, context); - context << " NOT IN("; - serialize(value_list, context); - context << ')'; - } - return context; + serialize(boolean_operand{true}, context); } - }; + else + { + serialize(t._operand, context); + context << " NOT IN("; + serialize(value_list, context); + context << ')'; + } + return context; + } } // namespace sqlpp #endif diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index c375efc2..8dd84bd4 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -57,18 +57,12 @@ namespace sqlpp }; template - struct serializer_t + Context& serialize(const select_name_t&, Context& context) { - using _serialize_check = consistent_t; - using T = select_name_t; + context << "SELECT "; - static Context& _(const T& /*unused*/, Context& context) - { - context << "SELECT "; - - return context; - } - }; + return context; + } template using blank_select_t = statement_t; static_assert(not column_names::template count(), "a column of this name is present in the select already"); - using _serialize_check = sqlpp::serialize_check_t; - _serialize_check{}; - using ok = - logic::all_t<_is_dynamic::value, is_selectable_t::value, _serialize_check::type::value>; + logic::all_t<_is_dynamic::value, is_selectable_t::value>; _add_impl(namedExpression, ok()); // dispatch to prevent compile messages after the static_assert } diff --git a/include/sqlpp11/serialize.h b/include/sqlpp11/serialize.h index 9d288f29..1732423e 100644 --- a/include/sqlpp11/serialize.h +++ b/include/sqlpp11/serialize.h @@ -32,12 +32,6 @@ namespace sqlpp { - template - auto serialize(const T& t, Context& context) -> Context& - { - return serializer_t::_(t, context); - } - template auto serialize_operand(const T& t, Context& context) -> Context& { diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index b71bf347..5ce3527b 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -443,7 +443,7 @@ namespace sqlpp typename std::enable_if::value or is_prepared_statement_t::value>::type> { using type = - detail::get_first_if>; + detail::get_first_if; }; template diff --git a/include/sqlpp11/value_or_null.h b/include/sqlpp11/value_or_null.h index 788f1899..5360dac7 100644 --- a/include/sqlpp11/value_or_null.h +++ b/include/sqlpp11/value_or_null.h @@ -53,25 +53,19 @@ namespace sqlpp }; template - struct serializer_t> + Context& serialize(const value_or_null_t& t, Context& context) { - using _serialize_check = consistent_t; - using Operand = value_or_null_t; - - static Context& _(const Operand& t, Context& context) + if (t._is_null) { - if (t._is_null) - { - context << "NULL"; - } - else - { - serialize(wrap_operand_t{t._value}, context); - } - - return context; + context << "NULL"; } - }; + else + { + serialize(wrap_operand_t{t._value}, context); + } + + return context; + } template auto value_or_null(T t) -> value_or_null_t>> diff --git a/include/sqlpp11/where.h b/include/sqlpp11/where.h index 2d7298d0..3d279f78 100644 --- a/include/sqlpp11/where.h +++ b/include/sqlpp11/where.h @@ -365,53 +365,35 @@ namespace sqlpp // Interpreters template - struct serializer_t> + Context& serialize(const where_data_t& t, Context& context) { - using _serialize_check = serialize_check_of; - using T = where_data_t; - - static Context& _(const T& t, Context& context) + context << " WHERE "; + serialize(t._expression, context); + if (not t._dynamic_expressions.empty()) { - context << " WHERE "; - serialize(t._expression, context); - if (not t._dynamic_expressions.empty()) - { - context << " AND "; - } - interpret_list(t._dynamic_expressions, " AND ", context); - return context; + context << " AND "; } - }; + interpret_list(t._dynamic_expressions, " AND ", context); + return context; + } template - struct serializer_t> + Context& serialize(const where_data_t& t, Context& context) { - using _serialize_check = consistent_t; - using T = where_data_t; - - static Context& _(const T& t, Context& context) + if (t._dynamic_expressions.empty()) { - if (t._dynamic_expressions.empty()) - { - return context; - } - context << " WHERE "; - interpret_list(t._dynamic_expressions, " AND ", context); return context; } - }; + context << " WHERE "; + interpret_list(t._dynamic_expressions, " AND ", context); + return context; + } template - struct serializer_t> + Context& serialize(const where_data_t&, Context& context) { - using _serialize_check = consistent_t; - using T = where_data_t; - - static Context& _(const T& /*unused*/, Context& context) - { - return context; - } - }; + return context; + } template auto where(T&& t) -> decltype(statement_t>().where(std::forward(t))) diff --git a/tests/MockDb.h b/tests/MockDb.h index 6732c4a1..a344514d 100644 --- a/tests/MockDb.h +++ b/tests/MockDb.h @@ -89,14 +89,14 @@ struct MockDb : public sqlpp::connection template static _serializer_context_t& _serialize_interpretable(const T& t, _serializer_context_t& context) { - sqlpp::serialize(t, context); + serialize(t, context); return context; } template static _serializer_context_t& _interpret_interpretable(const T& t, _interpreter_context_t& context) { - sqlpp::serialize(t, context); + serialize(t, context); return context; } @@ -142,7 +142,7 @@ struct MockDb : public sqlpp::connection size_t execute(const Statement& x) { _serializer_context_t context; - ::sqlpp::serialize(x, context); + serialize(x, context); std::cout << "Running execute call with\n" << context.str() << std::endl; return execute(context.str()); } @@ -151,7 +151,7 @@ struct MockDb : public sqlpp::connection size_t insert(const Insert& x) { _serializer_context_t context; - ::sqlpp::serialize(x, context); + serialize(x, context); std::cout << "Running insert call with\n" << context.str() << std::endl; return 0; } @@ -160,7 +160,7 @@ struct MockDb : public sqlpp::connection size_t update(const Update& x) { _serializer_context_t context; - ::sqlpp::serialize(x, context); + serialize(x, context); std::cout << "Running update call with\n" << context.str() << std::endl; return 0; } @@ -169,7 +169,7 @@ struct MockDb : public sqlpp::connection size_t remove(const Remove& x) { _serializer_context_t context; - ::sqlpp::serialize(x, context); + serialize(x, context); std::cout << "Running remove call with\n" << context.str() << std::endl; return 0; } @@ -178,7 +178,7 @@ struct MockDb : public sqlpp::connection result_t select(const Select& x) { _serializer_context_t context; - ::sqlpp::serialize(x, context); + serialize(x, context); std::cout << "Running select call with\n" << context.str() << std::endl; return {}; } @@ -205,7 +205,7 @@ struct MockDb : public sqlpp::connection _prepared_statement_t prepare_execute(Statement& x) { _serializer_context_t context; - ::sqlpp::serialize(x, context); + serialize(x, context); std::cout << "Running prepare execute call with\n" << context.str() << std::endl; return nullptr; } @@ -214,7 +214,7 @@ struct MockDb : public sqlpp::connection _prepared_statement_t prepare_insert(Insert& x) { _serializer_context_t context; - ::sqlpp::serialize(x, context); + serialize(x, context); std::cout << "Running prepare insert call with\n" << context.str() << std::endl; return nullptr; } @@ -235,7 +235,7 @@ struct MockDb : public sqlpp::connection _prepared_statement_t prepare_select(Select& x) { _serializer_context_t context; - ::sqlpp::serialize(x, context); + serialize(x, context); std::cout << "Running prepare select call with\n" << context.str() << std::endl; return nullptr; } @@ -303,14 +303,14 @@ struct MockSizeDb : public sqlpp::connection template static _serializer_context_t& _serialize_interpretable(const T& t, _serializer_context_t& context) { - sqlpp::serialize(t, context); + serialize(t, context); return context; } template static _serializer_context_t& _interpret_interpretable(const T& t, _interpreter_context_t& context) { - sqlpp::serialize(t, context); + serialize(t, context); return context; } @@ -350,7 +350,7 @@ struct MockSizeDb : public sqlpp::connection size_t execute(const Statement& x) { _serializer_context_t context; - ::sqlpp::serialize(x, context); + serialize(x, context); std::cout << "Running execute call with\n" << context.str() << std::endl; return execute(context.str()); } @@ -359,7 +359,7 @@ struct MockSizeDb : public sqlpp::connection size_t insert(const Insert& x) { _serializer_context_t context; - ::sqlpp::serialize(x, context); + serialize(x, context); std::cout << "Running insert call with\n" << context.str() << std::endl; return 0; } @@ -368,7 +368,7 @@ struct MockSizeDb : public sqlpp::connection size_t update(const Update& x) { _serializer_context_t context; - ::sqlpp::serialize(x, context); + serialize(x, context); std::cout << "Running update call with\n" << context.str() << std::endl; return 0; } @@ -377,7 +377,7 @@ struct MockSizeDb : public sqlpp::connection size_t remove(const Remove& x) { _serializer_context_t context; - ::sqlpp::serialize(x, context); + serialize(x, context); std::cout << "Running remove call with\n" << context.str() << std::endl; return 0; } @@ -386,7 +386,7 @@ struct MockSizeDb : public sqlpp::connection result_t select(const Select& x) { _serializer_context_t context; - ::sqlpp::serialize(x, context); + serialize(x, context); std::cout << "Running select call with\n" << context.str() << std::endl; return {}; } @@ -413,7 +413,7 @@ struct MockSizeDb : public sqlpp::connection _prepared_statement_t prepare_execute(Statement& x) { _serializer_context_t context; - ::sqlpp::serialize(x, context); + serialize(x, context); std::cout << "Running prepare execute call with\n" << context.str() << std::endl; return nullptr; } @@ -422,7 +422,7 @@ struct MockSizeDb : public sqlpp::connection _prepared_statement_t prepare_insert(Insert& x) { _serializer_context_t context; - ::sqlpp::serialize(x, context); + serialize(x, context); std::cout << "Running prepare insert call with\n" << context.str() << std::endl; return nullptr; } @@ -443,7 +443,7 @@ struct MockSizeDb : public sqlpp::connection _prepared_statement_t prepare_select(Select& x) { _serializer_context_t context; - ::sqlpp::serialize(x, context); + serialize(x, context); std::cout << "Running prepare select call with\n" << context.str() << std::endl; return nullptr; } diff --git a/tests/Select.cpp b/tests/Select.cpp index 79529c4f..a2aaca60 100644 --- a/tests/Select.cpp +++ b/tests/Select.cpp @@ -73,6 +73,8 @@ int Select(int, char*[]) getColumn(db, t.alpha); select(count(t.alpha)); + std::cerr << serialize(select(sqlpp::value(false).as(sqlpp::alias::a)), printer).str() << std::endl; + /* for (const auto& row : db(select(sqlpp::value(false).as(sqlpp::alias::a)))) { std::cout << row.a << std::endl; @@ -208,6 +210,7 @@ int Select(int, char*[]) std::cout << "Error: transaction isolation level does not match default level" << std::endl; } } + */ return 0; }