diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index da7c4749..2ed6bc3d 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -130,7 +130,8 @@ namespace sqlpp typename Offset > struct select_t: public detail::select_helper_t::_value_type::template expression_operators>, - Where::template _methods_t> + Where::template _methods_t>, + Limit::template _methods_t> { using _database_t = Database; using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; @@ -283,22 +284,6 @@ namespace sqlpp return { *this, vendor::order_by_t<_database_t, Args...>{args...} }; } - template - auto limit(Arg arg) - -> _policies_update_t::type>> - { - static_assert(is_noop_t::value, "cannot call limit()/dynamic_limit() twice"); - return { *this, vendor::limit_t::type>{{arg}} }; - } - - auto dynamic_limit() - -> _policies_update_t> - { - static_assert(is_noop_t::value, "cannot call limit()/dynamic_limit() twice"); - static_assert(not std::is_same<_database_t, void>::value, "dynamic_limit must not be called in a static statement"); - return { *this, vendor::dynamic_limit_t<_database_t>{} }; - } - template auto offset(Arg arg) -> _policies_update_t::type>> diff --git a/include/sqlpp11/vendor/limit.h b/include/sqlpp11/vendor/limit.h index 4e91e312..5e6437ca 100644 --- a/include/sqlpp11/vendor/limit.h +++ b/include/sqlpp11/vendor/limit.h @@ -53,6 +53,11 @@ namespace sqlpp limit_t& operator=(limit_t&&) = default; ~limit_t() = default; + template + struct _methods_t + { + }; + Limit _value; }; @@ -61,6 +66,7 @@ namespace sqlpp { using _is_limit = std::true_type; using _is_dynamic = std::true_type; + using _table_set = ::sqlpp::detail::type_set<>; dynamic_limit_t(): _value(noop()) @@ -88,6 +94,18 @@ namespace sqlpp _initialized = true; } + template + struct _methods_t + { + template + void set_limit(Limit value) + { + using arg_t = typename wrap_operand::type; + static_cast(this)->_limit._value = arg_t{value}; + static_cast(this)->_limit._initialized = true; + } + }; + bool _initialized = false; interpretable_t _value; }; @@ -96,6 +114,28 @@ 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 limit(Arg arg) + -> _new_select_t::type>> + { + return { *static_cast(this), limit_t::type>{{arg}} }; + } + + auto dynamic_limit() + -> _new_select_t> + { + static_assert(not std::is_same<_database_t, void>::value, "dynamic_limit must not be called in a static statement"); + return { *static_cast(this), dynamic_limit_t<_database_t>{} }; + } + }; }; // Interpreters diff --git a/include/sqlpp11/vendor/where.h b/include/sqlpp11/vendor/where.h index aef0d5f5..8dfc8199 100644 --- a/include/sqlpp11/vendor/where.h +++ b/include/sqlpp11/vendor/where.h @@ -116,6 +116,7 @@ namespace sqlpp using _database_t = typename Policies::_database_t; template using _new_select_t = typename Policies::template _policies_update_t; + template auto where(Args... args) -> _new_select_t>