diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 2ed6bc3d..3274422d 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -131,7 +131,8 @@ namespace sqlpp > struct select_t: public detail::select_helper_t::_value_type::template expression_operators>, Where::template _methods_t>, - Limit::template _methods_t> + Limit::template _methods_t>, + Offset::template _methods_t> { using _database_t = Database; using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; @@ -284,22 +285,6 @@ namespace sqlpp return { *this, vendor::order_by_t<_database_t, Args...>{args...} }; } - template - auto offset(Arg arg) - -> _policies_update_t::type>> - { - static_assert(is_noop_t::value, "cannot call offset()/dynamic_offset() twice"); - return { *this, vendor::offset_t::type>{{arg}} }; - } - - auto dynamic_offset() - -> _policies_update_t> - { - static_assert(is_noop_t::value, "cannot call offset()/dynamic_offset() twice"); - static_assert(not std::is_same<_database_t, void>::value, "dynamic_offset must not be called in a static statement"); - return { *this, vendor::dynamic_offset_t<_database_t>{} }; - } - // value adding methods template void add_flag(Args... args) @@ -349,22 +334,6 @@ namespace sqlpp return _order_by.add_order_by(*this, args...); } - template - void set_limit(Arg arg) - { - static_assert(is_limit_t::value, "cannot call add_limit() before dynamic_limit()"); - static_assert(is_dynamic_t::value, "cannot call add_limit() before dynamic_limit()"); - return _limit.set_limit(arg); - } - - template - void set_offset(Arg arg) - { - static_assert(is_offset_t::value, "cannot call add_offset() before dynamic_offset()"); - static_assert(is_dynamic_t::value, "cannot call add_offset() before dynamic_offset()"); - return _offset.set_offset(arg); - } - // PseudoTable template struct _pseudo_table_t diff --git a/include/sqlpp11/vendor/limit.h b/include/sqlpp11/vendor/limit.h index 5e6437ca..c6b1034a 100644 --- a/include/sqlpp11/vendor/limit.h +++ b/include/sqlpp11/vendor/limit.h @@ -86,23 +86,15 @@ namespace sqlpp dynamic_limit_t& operator=(dynamic_limit_t&&) = default; ~dynamic_limit_t() = default; - template - void set_limit(Limit value) - { - using arg_t = typename wrap_operand::type; - _value = arg_t{value}; - _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; + using arg_t = typename wrap_operand::type; + static_cast(this)->_limit._value = arg_t{value}; + static_cast(this)->_limit._initialized = true; } }; diff --git a/include/sqlpp11/vendor/offset.h b/include/sqlpp11/vendor/offset.h index 35f43bfc..0c3ad9e1 100644 --- a/include/sqlpp11/vendor/offset.h +++ b/include/sqlpp11/vendor/offset.h @@ -40,6 +40,7 @@ namespace sqlpp struct offset_t { using _is_offset = std::true_type; + using _table_set = ::sqlpp::detail::type_set<>; static_assert(is_integral_t::value, "offset requires an integral value or integral parameter"); offset_t(Offset value): @@ -52,6 +53,11 @@ namespace sqlpp offset_t& operator=(offset_t&&) = default; ~offset_t() = default; + template + struct _methods_t + { + }; + Offset _value; }; @@ -60,6 +66,7 @@ namespace sqlpp { using _is_offset = std::true_type; using _is_dynamic = std::true_type; + using _table_set = ::sqlpp::detail::type_set<>; dynamic_offset_t(): _value(noop()) @@ -79,13 +86,17 @@ namespace sqlpp dynamic_offset_t& operator=(dynamic_offset_t&&) = default; ~dynamic_offset_t() = default; - template - void set_offset(Offset value) + template + struct _methods_t { - using arg_t = typename wrap_operand::type; - _value = arg_t(value); - _initialized = true; - } + template + void set_offset(Offset value) + { + using arg_t = typename wrap_operand::type; + static_cast(this)->_offset._value = arg_t{value}; + static_cast(this)->_offset._initialized = true; + } + }; bool _initialized = false; interpretable_t _value; @@ -95,6 +106,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 offset(Arg arg) + -> _new_select_t::type>> + { + return { *static_cast(this), offset_t::type>{{arg}} }; + } + + auto dynamic_offset() + -> _new_select_t> + { + static_assert(not std::is_same<_database_t, void>::value, "dynamic_offset must not be called in a static statement"); + return { *static_cast(this), dynamic_offset_t<_database_t>{} }; + } + }; }; // Interpreters