diff --git a/include/sqlpp11/group_by.h b/include/sqlpp11/group_by.h index c25e462b..24d8ad9d 100644 --- a/include/sqlpp11/group_by.h +++ b/include/sqlpp11/group_by.h @@ -62,29 +62,29 @@ namespace sqlpp _dynamic_expressions.emplace_back(std::forward(expr)); } - template - void serialize(std::ostream& os, Db& db) const - { - static_assert(Db::_supports_group_by, "group_by() not supported by current database"); - if (sizeof...(Expr) == 0 and _dynamic_expressions.empty()) - return; - - os << " GROUP BY "; - detail::serialize_tuple(os, db, _expressions, ','); - _dynamic_expressions.serialize(os, db, sizeof...(Expr) == 0); - } - - size_t _set_parameter_index(size_t index) - { - index = set_parameter_index(_expressions, index); - return index; - } - _parameter_tuple_t _expressions; detail::serializable_list _dynamic_expressions; }; + template + struct interpreter_t> + { + using T = group_by_t; + + static Context& _(const T& t, Context& context) + { + if (sizeof...(Expr) == 0 and t._dynamic_expressions.empty()) + return context; + context << " GROUP BY "; + interpret_tuple(t._expressions, ',', context); + if (sizeof...(Expr) and not t._dynamic_expressions.empty()) + context << ','; + interpret_serializable_list(t._dynamic_expressions, ',', context); + return context; + } + }; + } #endif diff --git a/include/sqlpp11/having.h b/include/sqlpp11/having.h index fe9927e3..60d65b05 100644 --- a/include/sqlpp11/having.h +++ b/include/sqlpp11/having.h @@ -57,28 +57,29 @@ namespace sqlpp _dynamic_expressions.emplace_back(std::forward(expr)); } - template - void serialize(std::ostream& os, Db& db) const - { - static_assert(Db::_supports_having, "having() not supported by current database"); - - if (sizeof...(Expr) == 0 and _dynamic_expressions.empty()) - return; - os << " HAVING "; - detail::serialize_tuple(os, db, _expressions, " AND "); - _dynamic_expressions.serialize(os, db, " AND ", sizeof...(Expr) == 0); - } - - size_t _set_parameter_index(size_t index) - { - index = set_parameter_index(_expressions, index); - return index; - } - _parameter_tuple_t _expressions; detail::serializable_list _dynamic_expressions; }; + template + struct interpreter_t> + { + using T = having_t; + + static Context& _(const T& t, Context& context) + { + if (sizeof...(Expr) == 0 and t._dynamic_expressions.empty()) + return context; + context << " HAVING "; + interpret_tuple(t._expressions, " AND ", context); + if (sizeof...(Expr) and not t._dynamic_expressions.empty()) + context << " AND "; + interpret_serializable_list(t._dynamic_expressions, " AND ", context); + return context; + } + }; + + } #endif diff --git a/include/sqlpp11/like.h b/include/sqlpp11/like.h index 1043d4d6..e3b74e13 100644 --- a/include/sqlpp11/like.h +++ b/include/sqlpp11/like.h @@ -33,8 +33,6 @@ namespace sqlpp { - namespace detail - { // The ValueType should be boolean, this is a hack because boolean is not fully defined when the compiler first gets here... template struct like_t: public ValueType::_base_value_type::template operators> @@ -74,13 +72,6 @@ namespace sqlpp like_t& operator=(like_t&&) = default; ~like_t() = default; - size_t _set_parameter_index(size_t index) - { - index = set_parameter_index(_operand, index); - index = set_parameter_index(_pattern, index); - return index; - } - template void serialize(std::ostream& os, Db& db) const { @@ -91,11 +82,25 @@ namespace sqlpp os << ")"; } - private: Operand _operand; Pattern _pattern; }; - } + + template + struct interpreter_t> + { + using T = like_t; + + static Context& _(const T& t, Context& context) + { + interpret(t._operand, context); + context << " LIKE("; + interpret(t._pattern, context); + context << ")"; + return context; + } + }; + } #endif diff --git a/include/sqlpp11/text.h b/include/sqlpp11/text.h index da31c35b..2902bfa6 100644 --- a/include/sqlpp11/text.h +++ b/include/sqlpp11/text.h @@ -203,10 +203,10 @@ namespace sqlpp } template - detail::like_t::type> like(T&& t) const + like_t::type> like(T&& t) const { static_assert(not is_multi_expression_t::value, "multi-expression cannot be used as left hand side operand"); - return { *static_cast(this), std::forward(t) }; + return { *static_cast(this), {std::forward(t)} }; } }; diff --git a/tests/InterpretTest.cpp b/tests/InterpretTest.cpp index bd80f178..c3f3d8b0 100644 --- a/tests/InterpretTest.cpp +++ b/tests/InterpretTest.cpp @@ -46,6 +46,8 @@ int main() interpret(select(sqlpp::distinct, t.alpha, t.beta), printer).flush(); interpret(select(sqlpp::distinct, t.alpha, t.beta).from(t), printer).flush(); interpret(select(sqlpp::distinct, t.alpha, t.beta).from(t).where(t.alpha == 3), printer).flush(); + interpret(select(sqlpp::distinct, t.alpha, t.beta).from(t).where(t.alpha == 3).group_by(t.gamma), printer).flush(); + interpret(select(sqlpp::distinct, t.alpha, t.beta).from(t).where(t.alpha == 3).group_by(t.gamma).having(t.beta.like("%kuchen")), printer).flush(); return 0; }