0
0
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:
rbock 2016-03-15 09:07:30 +01:00
parent 84d281ebb9
commit fc076464e1

View File

@ -37,10 +37,10 @@
namespace sqlpp namespace sqlpp
{ {
// HAVING DATA // HAVING DATA
template <typename Database, typename... Expressions> template <typename Database, typename Expression>
struct having_data_t 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& operator=(having_data_t&&) = default;
~having_data_t() = default; ~having_data_t() = default;
std::tuple<Expressions...> _expressions; Expression _expression;
interpretable_list_t<Database> _dynamic_expressions; 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"); "at least one having-expression requires a table which is otherwise not known in the statement");
// HAVING // HAVING
template <typename Database, typename... Expressions> template <typename Database, typename Expression>
struct having_t struct having_t
{ {
using _traits = make_traits<no_value_t, tag::is_having>; 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>; using _is_dynamic = is_database<Database>;
// Data // Data
using _data_t = having_data_t<Database, Expressions...>; using _data_t = having_data_t<Database, Expression>;
// Member implementation with data and methods // Member implementation with data and methods
template <typename Policies> template <typename Policies>
@ -80,36 +80,36 @@ namespace sqlpp
{ {
} }
template <typename Expression> template <typename Expr>
void add_ntc(Expression expression) 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> template <typename Expr, typename TableCheckRequired = std::true_type>
void add(Expression expression) void add(Expr expression)
{ {
static_assert(_is_dynamic::value, "having::add() can only be called for dynamic_having"); 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(is_expression_t<Expr>::value, "invalid expression argument in having::add()");
static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables<Expression>::value, static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables<Expr>::value,
"expression uses tables unknown to this statement in having::add()"); "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::_(); _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 _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
} }
private: private:
template <typename Expression> template <typename Expr>
void _add_impl(Expression expression, const std::true_type&) void _add_impl(Expr expression, const std::true_type&)
{ {
return _data._dynamic_expressions.emplace_back(expression); return _data._dynamic_expressions.emplace_back(expression);
} }
template <typename Expression> template <typename Expr>
void _add_impl(Expression expression, const std::false_type&); void _add_impl(Expr expression, const std::false_type&);
public: public:
_data_t _data; _data_t _data;
@ -119,7 +119,7 @@ namespace sqlpp
template <typename Policies> template <typename Policies>
struct _base_t 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 // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069
template <typename... Args> template <typename... Args>
@ -216,54 +216,50 @@ namespace sqlpp
using _consistency_check = consistent_t; using _consistency_check = consistent_t;
template <typename... Expressions> template <typename Expression>
auto having(Expressions... expressions) const auto having(Expression expression) const -> _new_statement_t<_check<Expression>, having_t<void, Expression>>
-> _new_statement_t<_check<Expressions...>, having_t<void, Expressions...>>
{ {
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(sizeof...(Expressions), "at least one expression argument required in having()");
return _having_impl<void>(_check<Expressions...>{}, expressions...); return _having_impl<void>(_check<Expression>{}, expression);
} }
template <typename... Expressions> template <typename Expression>
auto dynamic_having(Expressions... expressions) const auto dynamic_having(Expression expression) const
-> _new_statement_t<_check<Expressions...>, having_t<_database_t, Expressions...>> -> _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, static_assert(not std::is_same<_database_t, void>::value,
"dynamic_having must not be called in a static statement"); "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: private:
template <typename Database, typename... Expressions> template <typename Database, typename Expression>
auto _having_impl(const std::false_type&, Expressions... expressions) const -> bad_statement; auto _having_impl(const std::false_type&, Expression expression) const -> bad_statement;
template <typename Database, typename... Expressions> template <typename Database, typename Expression>
auto _having_impl(const std::true_type&, Expressions... expressions) const auto _having_impl(const std::true_type&, Expression expression) const
-> _new_statement_t<std::true_type, having_t<Database, Expressions...>> -> _new_statement_t<std::true_type, having_t<Database, Expression>>
{ {
return {static_cast<const derived_statement_t<Policies>&>(*this), return {static_cast<const derived_statement_t<Policies>&>(*this),
having_data_t<Database, Expressions...>{expressions...}}; having_data_t<Database, Expression>{expression}};
} }
}; };
}; };
// Interpreters // Interpreters
template <typename Context, typename Database, typename... Expressions> template <typename Context, typename Database, typename Expression>
struct serializer_t<Context, having_data_t<Database, Expressions...>> struct serializer_t<Context, having_data_t<Database, Expression>>
{ {
using _serialize_check = serialize_check_of<Context, Expressions...>; using _serialize_check = serialize_check_of<Context, Expression>;
using T = having_data_t<Database, Expressions...>; using T = having_data_t<Database, Expression>;
static Context& _(const T& t, Context& context) static Context& _(const T& t, Context& context)
{ {
if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty())
return context;
context << " HAVING "; context << " HAVING ";
interpret_tuple(t._expressions, " AND ", context); serialize(t._expression, context);
if (sizeof...(Expressions) and not t._dynamic_expressions.empty()) if (not t._dynamic_expressions.empty())
context << " AND "; context << " AND ";
interpret_list(t._dynamic_expressions, " AND ", context); interpret_list(t._dynamic_expressions, " AND ", context);
return context; return context;