diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index fd93479e..18657a47 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -131,6 +131,7 @@ namespace sqlpp > struct select_t: public detail::select_helper_t::_value_type::template expression_operators>, Where::template _methods_t>, + Having::template _methods_t>, OrderBy::template _methods_t>, Limit::template _methods_t>, Offset::template _methods_t> @@ -252,23 +253,6 @@ namespace sqlpp return { *this, vendor::group_by_t<_database_t, Args...>{args...} }; } - template - auto having(Args... args) - -> _policies_update_t> - { - static_assert(is_noop_t::value, "cannot call having()/dynamic_having() twice"); - return { *this, vendor::having_t{args...} }; - } - - template - auto dynamic_having(Args... args) - -> _policies_update_t> - { - static_assert(is_noop_t::value, "cannot call having()/dynamic_having() twice"); - static_assert(not std::is_same<_database_t, void>::value, "dynamic_having must not be called in a static statement"); - return { *this, vendor::having_t<_database_t, Args...>{args...} }; - } - // value adding methods template void add_flag(Args... args) @@ -302,14 +286,6 @@ namespace sqlpp return _group_by.add_group_by(*this, args...); } - template - void add_having(Args... args) - { - static_assert(is_having_t::value, "cannot call add_having() before dynamic_having()"); - static_assert(is_dynamic_t::value, "cannot call add_having() before dynamic_having()"); - return _having.add_having(*this, args...); - } - // PseudoTable template struct _pseudo_table_t diff --git a/include/sqlpp11/vendor/having.h b/include/sqlpp11/vendor/having.h index 7572b205..ad29d987 100644 --- a/include/sqlpp11/vendor/having.h +++ b/include/sqlpp11/vendor/having.h @@ -51,6 +51,8 @@ namespace sqlpp using _parameter_list_t = typename make_parameter_list_t<_parameter_tuple_t>::type; + using _table_set = typename ::sqlpp::detail::make_joined_set::type; + having_t(Expressions... expressions): _expressions(expressions...) {} @@ -61,12 +63,17 @@ namespace sqlpp having_t& operator=(having_t&&) = default; ~having_t() = default; - template - void add(Expression expr) + template + struct _methods_t { - static_assert(is_expression_t::value, "invalid expression argument in add_having()"); - _dynamic_expressions.emplace_back(expr); - } + template + void add_having(Expression expression) + { + static_assert(is_expression_t::value, "invalid expression argument in add_having()"); +#warning: Need to dispatch to actual add method to prevent error messages from being generated + return static_cast(this)->_having._dynamic_expressions.emplace_back(expression); + } + }; _parameter_tuple_t _expressions; vendor::interpretable_list_t _dynamic_expressions; @@ -76,6 +83,29 @@ namespace sqlpp { using _is_noop = std::true_type; using _table_set = ::sqlpp::detail::type_set<>; + + template + struct _methods_t + { + using _database_t = typename Policies::_database_t; + template + using _new_select_t = typename Policies::template _policies_update_t; + + template + auto having(Args... args) + -> _new_select_t> + { + return { *static_cast(this), having_t{args...} }; + } + + template + auto dynamic_having(Args... args) + -> _new_select_t> + { + static_assert(not std::is_same<_database_t, void>::value, "dynamic_having must not be called in a static statement"); + return { *static_cast(this), vendor::having_t<_database_t, Args...>{args...} }; + } + }; }; // Interpreters