diff --git a/include/sqlpp11/vendor/limit.h b/include/sqlpp11/vendor/limit.h index be74b7c5..1a8426a2 100644 --- a/include/sqlpp11/vendor/limit.h +++ b/include/sqlpp11/vendor/limit.h @@ -42,7 +42,7 @@ namespace sqlpp using _is_limit = std::true_type; static_assert(is_integral_t::value, "limit requires an integral value or integral parameter"); - limit_t(size_t value): + limit_t(Limit value): _value(value) {} @@ -62,9 +62,17 @@ namespace sqlpp using _is_limit = std::true_type; using _is_dynamic = std::true_type; - dynamic_limit_t(size_t value): - _value(value) - {} + dynamic_limit_t(): + _value(noop()) + { + } + + template + dynamic_limit_t(Limit value): + _initialized(true), + _value(typename wrap_operand::type(value)) + { + } dynamic_limit_t(const dynamic_limit_t&) = default; dynamic_limit_t(dynamic_limit_t&&) = default; @@ -72,13 +80,19 @@ namespace sqlpp dynamic_limit_t& operator=(dynamic_limit_t&&) = default; ~dynamic_limit_t() = default; - void set_limit(std::size_t limit) - { - _value = limit; - } + template + void set_limit(Limit value) + { + using arg_t = typename wrap_operand::type; + _value = arg_t(value); + _initialized = true; + } +#warning this is stupid! Will get dangling references when copying dynamic_limit_t& _limit = *this; - std::size_t _value; // FIXME: This should be a serializable! + + bool _initialized = false; + interpretable_t _value; }; struct no_limit_t @@ -101,7 +115,7 @@ namespace sqlpp template struct crtp_wrapper_t { - template + template struct delayed_get_database_t { using type = get_database_t; @@ -109,17 +123,19 @@ namespace sqlpp template auto limit(Arg arg) - -> vendor::update_policies_t> + -> vendor::update_policies_t::type>> { - return { static_cast(*this), limit_t(arg) }; + typename wrap_operand::type value = {arg}; + return { static_cast(*this), limit_t::type>(value) }; } - template - auto dynamic_limit(Arg arg) - -> vendor::update_policies_t::type>> + template + auto dynamic_limit(Args... args) + -> vendor::update_policies_t::type>> { + static_assert(sizeof...(Args) < 2, "dynamic_limit must be called with zero or one arguments"); static_assert(not std::is_same, void>::value, "dynamic_limit must not be called in a static statement"); - return { static_cast(*this), dynamic_limit_t::type>(arg) }; + return { static_cast(*this), dynamic_limit_t::type>(args...) }; } }; @@ -131,8 +147,8 @@ namespace sqlpp static Context& _(const T& t, Context& context) { - if (t._value > 0) - context << " LIMIT " << t._limit; + if (t._initialized) + interpret(t._value, context); return context; } }; diff --git a/include/sqlpp11/vendor/offset.h b/include/sqlpp11/vendor/offset.h index 5af2ee84..c8f1f119 100644 --- a/include/sqlpp11/vendor/offset.h +++ b/include/sqlpp11/vendor/offset.h @@ -42,7 +42,7 @@ namespace sqlpp using _is_offset = std::true_type; static_assert(is_integral_t::value, "offset requires an integral value or integral parameter"); - offset_t(size_t value): + offset_t(Offset value): _value(value) {} @@ -53,6 +53,7 @@ namespace sqlpp ~offset_t() = default; offset_t& _offset = *this; + Offset _value; }; @@ -62,9 +63,17 @@ namespace sqlpp using _is_offset = std::true_type; using _is_dynamic = std::true_type; - dynamic_offset_t(size_t value): - _value(value) - {} + dynamic_offset_t(): + _value(noop()) + { + } + + template + dynamic_offset_t(Offset value): + _initialized(true), + _value(typename wrap_operand::type(value)) + { + } dynamic_offset_t(const dynamic_offset_t&) = default; dynamic_offset_t(dynamic_offset_t&&) = default; @@ -72,13 +81,17 @@ namespace sqlpp dynamic_offset_t& operator=(dynamic_offset_t&&) = default; ~dynamic_offset_t() = default; - void set_offset(std::size_t offset) - { - _value = offset; - } + template + void set_offset(Offset value) + { + using arg_t = typename wrap_operand::type; + _value = arg_t(value); + _initialized = true; + } dynamic_offset_t& _offset = *this; - std::size_t _value; // FIXME: This should be a serializable! + bool _initialized = false; + interpretable_t _value; }; struct no_offset_t @@ -88,8 +101,8 @@ namespace sqlpp }; // CRTP Wrappers - template - struct crtp_wrapper_t> + template + struct crtp_wrapper_t> { }; @@ -101,7 +114,7 @@ namespace sqlpp template struct crtp_wrapper_t { - template + template struct delayed_get_database_t { using type = get_database_t; @@ -109,17 +122,19 @@ namespace sqlpp template auto offset(Arg arg) - -> vendor::update_policies_t> + -> vendor::update_policies_t::type>> { - return { static_cast(*this), offset_t(arg) }; + typename wrap_operand::type value = {arg}; + return { static_cast(*this), offset_t::type>(value) }; } - template - auto dynamic_offset(Arg arg) - -> vendor::update_policies_t::type>> + template + auto dynamic_offset(Args... args) + -> vendor::update_policies_t::type>> { + static_assert(sizeof...(Args) < 2, "dynamic_offset must be called with zero or one arguments"); static_assert(not std::is_same, void>::value, "dynamic_offset must not be called in a static statement"); - return { static_cast(*this), dynamic_offset_t>(arg) }; + return { static_cast(*this), dynamic_offset_t::type>(args...) }; } }; @@ -132,7 +147,7 @@ namespace sqlpp static Context& _(const T& t, Context& context) { context << " OFFSET "; - interpret(t._offset, context); + interpret(t._value, context); return context; } }; @@ -144,7 +159,7 @@ namespace sqlpp static Context& _(const T& t, Context& context) { - if (t._value > 0) + if (t._initialized) context << " OFFSET " << t._offset; return context; }