diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 18657a47..f102fc0b 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>, + GroupBy::template _methods_t>, Having::template _methods_t>, OrderBy::template _methods_t>, Limit::template _methods_t>, @@ -236,23 +237,6 @@ namespace sqlpp return { *this, vendor::from_t<_database_t, Args...>{args...} }; } - template - auto group_by(Args... args) - -> _policies_update_t> - { - static_assert(is_noop_t::value, "cannot call group_by()/dynamic_group_by() twice"); - return { *this, vendor::group_by_t{args...} }; - } - - template - auto dynamic_group_by(Args... args) - -> _policies_update_t> - { - static_assert(is_noop_t::value, "cannot call group_by()/dynamic_group_by() twice"); - static_assert(not std::is_same<_database_t, void>::value, "dynamic_group_by must not be called in a static statement"); - return { *this, vendor::group_by_t<_database_t, Args...>{args...} }; - } - // value adding methods template void add_flag(Args... args) @@ -278,14 +262,6 @@ namespace sqlpp return _from.add_from(*this, args...); } - template - void add_group_by(Args... args) - { - static_assert(is_group_by_t::value, "cannot call add_group_by() before dynamic_group_by()"); - static_assert(is_dynamic_t::value, "cannot call add_group_by() before dynamic_group_by()"); - return _group_by.add_group_by(*this, args...); - } - // PseudoTable template struct _pseudo_table_t diff --git a/include/sqlpp11/vendor/group_by.h b/include/sqlpp11/vendor/group_by.h index 5491a6e8..8c6bba6f 100644 --- a/include/sqlpp11/vendor/group_by.h +++ b/include/sqlpp11/vendor/group_by.h @@ -46,6 +46,8 @@ namespace sqlpp using _is_group_by = std::true_type; using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; using _parameter_tuple_t = std::tuple; +#warning Has no parameter_list? + using _table_set = typename ::sqlpp::detail::make_joined_set::type; static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression (e.g. a column) required in group_by()"); @@ -63,12 +65,17 @@ namespace sqlpp group_by_t& operator=(group_by_t&&) = default; ~group_by_t() = default; - template - void add_group_by(const Statement&, Expression expression) + template + struct _methods_t { - static_assert(is_table_t::value, "from arguments require to be tables or joins"); - _dynamic_expressions.emplace_back(expression); - } + template + void add_group_by(Expression expression) + { + static_assert(is_expression_t::value, "invalid expression argument in add_group_by()"); +#warning: Need to dispatch to actual add method to prevent error messages from being generated + return static_cast(this)->_group_by._dynamic_expressions.emplace_back(expression); + } + }; const group_by_t& _group_by() const { return *this; } _parameter_tuple_t _expressions; @@ -79,6 +86,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 group_by(Args... args) + -> _new_select_t> + { + return { *static_cast(this), group_by_t{args...} }; + } + + template + auto dynamic_group_by(Args... args) + -> _new_select_t> + { + static_assert(not std::is_same<_database_t, void>::value, "dynamic_group_by must not be called in a static statement"); + return { *static_cast(this), vendor::group_by_t<_database_t, Args...>{args...} }; + } + }; }; // Interpreters