mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 04:47:18 +08:00
Removed multi-argument option for having
This commit is contained in:
parent
84d281ebb9
commit
fc076464e1
@ -37,10 +37,10 @@
|
||||
namespace sqlpp
|
||||
{
|
||||
// HAVING DATA
|
||||
template <typename Database, typename... Expressions>
|
||||
template <typename Database, typename Expression>
|
||||
struct having_data_t
|
||||
{
|
||||
having_data_t(Expressions... expressions) : _expressions(expressions...)
|
||||
having_data_t(Expression expression) : _expression(expression)
|
||||
{
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ namespace sqlpp
|
||||
having_data_t& operator=(having_data_t&&) = default;
|
||||
~having_data_t() = default;
|
||||
|
||||
std::tuple<Expressions...> _expressions;
|
||||
Expression _expression;
|
||||
interpretable_list_t<Database> _dynamic_expressions;
|
||||
};
|
||||
|
||||
@ -59,16 +59,16 @@ namespace sqlpp
|
||||
"at least one having-expression requires a table which is otherwise not known in the statement");
|
||||
|
||||
// HAVING
|
||||
template <typename Database, typename... Expressions>
|
||||
template <typename Database, typename Expression>
|
||||
struct having_t
|
||||
{
|
||||
using _traits = make_traits<no_value_t, tag::is_having>;
|
||||
using _nodes = detail::type_vector<Expressions...>;
|
||||
using _nodes = detail::type_vector<Expression>;
|
||||
|
||||
using _is_dynamic = is_database<Database>;
|
||||
|
||||
// Data
|
||||
using _data_t = having_data_t<Database, Expressions...>;
|
||||
using _data_t = having_data_t<Database, Expression>;
|
||||
|
||||
// Member implementation with data and methods
|
||||
template <typename Policies>
|
||||
@ -80,36 +80,36 @@ namespace sqlpp
|
||||
{
|
||||
}
|
||||
|
||||
template <typename Expression>
|
||||
void add_ntc(Expression expression)
|
||||
template <typename Expr>
|
||||
void add_ntc(Expr expression)
|
||||
{
|
||||
add<Expression, std::false_type>(expression);
|
||||
add<Expr, std::false_type>(expression);
|
||||
}
|
||||
|
||||
template <typename Expression, typename TableCheckRequired = std::true_type>
|
||||
void add(Expression expression)
|
||||
template <typename Expr, typename TableCheckRequired = std::true_type>
|
||||
void add(Expr expression)
|
||||
{
|
||||
static_assert(_is_dynamic::value, "having::add() can only be called for dynamic_having");
|
||||
static_assert(is_expression_t<Expression>::value, "invalid expression argument in having::add()");
|
||||
static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables<Expression>::value,
|
||||
static_assert(is_expression_t<Expr>::value, "invalid expression argument in having::add()");
|
||||
static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables<Expr>::value,
|
||||
"expression uses tables unknown to this statement in having::add()");
|
||||
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Expression>;
|
||||
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Expr>;
|
||||
_serialize_check::_();
|
||||
|
||||
using ok = logic::all_t<_is_dynamic::value, is_expression_t<Expression>::value, _serialize_check::type::value>;
|
||||
using ok = logic::all_t<_is_dynamic::value, is_expression_t<Expr>::value, _serialize_check::type::value>;
|
||||
|
||||
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename Expression>
|
||||
void _add_impl(Expression expression, const std::true_type&)
|
||||
template <typename Expr>
|
||||
void _add_impl(Expr expression, const std::true_type&)
|
||||
{
|
||||
return _data._dynamic_expressions.emplace_back(expression);
|
||||
}
|
||||
|
||||
template <typename Expression>
|
||||
void _add_impl(Expression expression, const std::false_type&);
|
||||
template <typename Expr>
|
||||
void _add_impl(Expr expression, const std::false_type&);
|
||||
|
||||
public:
|
||||
_data_t _data;
|
||||
@ -119,7 +119,7 @@ namespace sqlpp
|
||||
template <typename Policies>
|
||||
struct _base_t
|
||||
{
|
||||
using _data_t = having_data_t<Database, Expressions...>;
|
||||
using _data_t = having_data_t<Database, Expression>;
|
||||
|
||||
// workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069
|
||||
template <typename... Args>
|
||||
@ -216,54 +216,50 @@ namespace sqlpp
|
||||
|
||||
using _consistency_check = consistent_t;
|
||||
|
||||
template <typename... Expressions>
|
||||
auto having(Expressions... expressions) const
|
||||
-> _new_statement_t<_check<Expressions...>, having_t<void, Expressions...>>
|
||||
template <typename Expression>
|
||||
auto having(Expression expression) const -> _new_statement_t<_check<Expression>, having_t<void, Expression>>
|
||||
{
|
||||
static_assert(_check<Expressions...>::value, "at least one argument is not an expression in having()");
|
||||
static_assert(sizeof...(Expressions), "at least one expression argument required in having()");
|
||||
static_assert(_check<Expression>::value, "at least one argument is not an expression in having()");
|
||||
|
||||
return _having_impl<void>(_check<Expressions...>{}, expressions...);
|
||||
return _having_impl<void>(_check<Expression>{}, expression);
|
||||
}
|
||||
|
||||
template <typename... Expressions>
|
||||
auto dynamic_having(Expressions... expressions) const
|
||||
-> _new_statement_t<_check<Expressions...>, having_t<_database_t, Expressions...>>
|
||||
template <typename Expression>
|
||||
auto dynamic_having(Expression expression) const
|
||||
-> _new_statement_t<_check<Expression>, having_t<_database_t, Expression>>
|
||||
{
|
||||
static_assert(_check<Expressions...>::value, "at least one argument is not an expression in having()");
|
||||
static_assert(_check<Expression>::value, "at least one argument is not an expression in having()");
|
||||
static_assert(not std::is_same<_database_t, void>::value,
|
||||
"dynamic_having must not be called in a static statement");
|
||||
return _having_impl<_database_t>(_check<Expressions...>{}, expressions...);
|
||||
return _having_impl<_database_t>(_check<Expression>{}, expression);
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename Database, typename... Expressions>
|
||||
auto _having_impl(const std::false_type&, Expressions... expressions) const -> bad_statement;
|
||||
template <typename Database, typename Expression>
|
||||
auto _having_impl(const std::false_type&, Expression expression) const -> bad_statement;
|
||||
|
||||
template <typename Database, typename... Expressions>
|
||||
auto _having_impl(const std::true_type&, Expressions... expressions) const
|
||||
-> _new_statement_t<std::true_type, having_t<Database, Expressions...>>
|
||||
template <typename Database, typename Expression>
|
||||
auto _having_impl(const std::true_type&, Expression expression) const
|
||||
-> _new_statement_t<std::true_type, having_t<Database, Expression>>
|
||||
{
|
||||
return {static_cast<const derived_statement_t<Policies>&>(*this),
|
||||
having_data_t<Database, Expressions...>{expressions...}};
|
||||
having_data_t<Database, Expression>{expression}};
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Interpreters
|
||||
template <typename Context, typename Database, typename... Expressions>
|
||||
struct serializer_t<Context, having_data_t<Database, Expressions...>>
|
||||
template <typename Context, typename Database, typename Expression>
|
||||
struct serializer_t<Context, having_data_t<Database, Expression>>
|
||||
{
|
||||
using _serialize_check = serialize_check_of<Context, Expressions...>;
|
||||
using T = having_data_t<Database, Expressions...>;
|
||||
using _serialize_check = serialize_check_of<Context, Expression>;
|
||||
using T = having_data_t<Database, Expression>;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
{
|
||||
if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty())
|
||||
return context;
|
||||
context << " HAVING ";
|
||||
interpret_tuple(t._expressions, " AND ", context);
|
||||
if (sizeof...(Expressions) and not t._dynamic_expressions.empty())
|
||||
serialize(t._expression, context);
|
||||
if (not t._dynamic_expressions.empty())
|
||||
context << " AND ";
|
||||
interpret_list(t._dynamic_expressions, " AND ", context);
|
||||
return context;
|
||||
|
Loading…
Reference in New Issue
Block a user