0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 04:47:18 +08:00

Moved flag-methods to select_flag classes

This commit is contained in:
rbock 2014-04-08 22:45:19 +02:00
parent 7af13937bf
commit 5e0c1cff48
5 changed files with 38 additions and 30 deletions

View File

@ -130,6 +130,7 @@ namespace sqlpp
typename Offset typename Offset
> >
struct select_t: public detail::select_helper_t<ColumnList, From>::_value_type::template expression_operators<select_t<Database, FlagList, ColumnList, From, Where, GroupBy, Having, OrderBy, Limit, Offset>>, struct select_t: public detail::select_helper_t<ColumnList, From>::_value_type::template expression_operators<select_t<Database, FlagList, ColumnList, From, Where, GroupBy, Having, OrderBy, Limit, Offset>>,
FlagList::template _methods_t<detail::select_policies_t<Database, FlagList, ColumnList, From, Where, GroupBy, Having, OrderBy, Limit, Offset>>,
Where::template _methods_t<detail::select_policies_t<Database, FlagList, ColumnList, From, Where, GroupBy, Having, OrderBy, Limit, Offset>>, Where::template _methods_t<detail::select_policies_t<Database, FlagList, ColumnList, From, Where, GroupBy, Having, OrderBy, Limit, Offset>>,
GroupBy::template _methods_t<detail::select_policies_t<Database, FlagList, ColumnList, From, Where, GroupBy, Having, OrderBy, Limit, Offset>>, GroupBy::template _methods_t<detail::select_policies_t<Database, FlagList, ColumnList, From, Where, GroupBy, Having, OrderBy, Limit, Offset>>,
Having::template _methods_t<detail::select_policies_t<Database, FlagList, ColumnList, From, Where, GroupBy, Having, OrderBy, Limit, Offset>>, Having::template _methods_t<detail::select_policies_t<Database, FlagList, ColumnList, From, Where, GroupBy, Having, OrderBy, Limit, Offset>>,
@ -188,23 +189,6 @@ namespace sqlpp
~select_t() = default; ~select_t() = default;
// type update functions // type update functions
template<typename... Args>
auto flags(Args... args)
-> _policies_update_t<vendor::no_select_flag_list_t, vendor::select_flag_list_t<void, Args...>>
{
static_assert(is_noop_t<FlagList>::value, "flags()/dynamic_flags() must not be called twice");
return { *this, vendor::select_flag_list_t<void, Args...>{args...} };
}
template<typename... Args>
auto dynamic_flags(Args... args)
-> _policies_update_t<vendor::no_select_flag_list_t, vendor::select_flag_list_t<_database_t, Args...>>
{
static_assert(is_noop_t<FlagList>::value, "flags()/dynamic_flags() must not be called twice");
static_assert(_is_dynamic::value, "dynamic_flags must not be called in a static statement");
return { *this, vendor::select_flag_list_t<_database_t, Args...>{args...} };
}
template<typename... Args> template<typename... Args>
auto columns(Args... args) auto columns(Args... args)
-> _policies_update_t<vendor::no_select_column_list_t, vendor::select_column_list_t<void, Args...>> -> _policies_update_t<vendor::no_select_column_list_t, vendor::select_column_list_t<void, Args...>>
@ -238,14 +222,6 @@ namespace sqlpp
} }
// value adding methods // value adding methods
template<typename... Args>
void add_flag(Args... args)
{
static_assert(is_select_flag_list_t<FlagList>::value, "cannot call add_flag() before dynamic_flags()");
static_assert(is_dynamic_t<FlagList>::value, "cannot call add_flag() before dynamic_flags()");
return _flag_list.add_flag(*this, args...);
}
template<typename... Args> template<typename... Args>
void add_column(Args... args) void add_column(Args... args)
{ {

View File

@ -71,6 +71,7 @@ namespace sqlpp
template<typename Expression> template<typename Expression>
void add_group_by(Expression expression) void add_group_by(Expression expression)
{ {
static_assert(_is_dynamic::value, "add_group_by must not be called for static group_by");
static_assert(is_expression_t<Expression>::value, "invalid expression argument in add_group_by()"); static_assert(is_expression_t<Expression>::value, "invalid expression argument in add_group_by()");
#warning: Need to dispatch to actual add method to prevent error messages from being generated #warning: Need to dispatch to actual add method to prevent error messages from being generated
return static_cast<typename Policies::_select_t*>(this)->_group_by._dynamic_expressions.emplace_back(expression); return static_cast<typename Policies::_select_t*>(this)->_group_by._dynamic_expressions.emplace_back(expression);

View File

@ -69,6 +69,7 @@ namespace sqlpp
template<typename Expression> template<typename Expression>
void add_having(Expression expression) void add_having(Expression expression)
{ {
static_assert(_is_dynamic::value, "add_having must not be called for static having");
static_assert(is_expression_t<Expression>::value, "invalid expression argument in add_having()"); static_assert(is_expression_t<Expression>::value, "invalid expression argument in add_having()");
#warning: Need to dispatch to actual add method to prevent error messages from being generated #warning: Need to dispatch to actual add method to prevent error messages from being generated
return static_cast<typename Policies::_select_t*>(this)->_having._dynamic_expressions.emplace_back(expression); return static_cast<typename Policies::_select_t*>(this)->_having._dynamic_expressions.emplace_back(expression);

View File

@ -70,6 +70,7 @@ namespace sqlpp
template<typename Expression> template<typename Expression>
void add_order_by(Expression expression) void add_order_by(Expression expression)
{ {
static_assert(_is_dynamic::value, "add_order_by must not be called for static order_by");
static_assert(is_sort_order_t<Expression>::value, "invalid expression argument in add_order_by()"); static_assert(is_sort_order_t<Expression>::value, "invalid expression argument in add_order_by()");
#warning: Need to dispatch to actual add method to prevent error messages from being generated #warning: Need to dispatch to actual add method to prevent error messages from being generated
return static_cast<typename Policies::_select_t*>(this)->_order_by._dynamic_expressions.emplace_back(expression); return static_cast<typename Policies::_select_t*>(this)->_order_by._dynamic_expressions.emplace_back(expression);

View File

@ -61,12 +61,18 @@ namespace sqlpp
select_flag_list_t& operator=(select_flag_list_t&&) = default; select_flag_list_t& operator=(select_flag_list_t&&) = default;
~select_flag_list_t() = default; ~select_flag_list_t() = default;
template<typename Select, typename Flag> template<typename Policies>
void add_flag(const Select&, Flag flag) struct _methods_t
{ {
static_assert(is_select_flag_t<Flag>::value, "flag arguments require to be select flags"); template<typename Flag>
_dynamic_flags.emplace_back(flag); void add_flag(Flag flag)
} {
static_assert(_is_dynamic::value, "add_flag must not be called for static select flags");
static_assert(is_select_flag_t<Flag>::value, "invalid select flag argument in add_flag()");
#warning: Need to dispatch to actual add method to prevent error messages from being generated
return static_cast<typename Policies::_select_t*>(this)->_flag_list._dynamic_flags.emplace_back(flag);
}
};
const select_flag_list_t& _flag_list() const { return *this; } const select_flag_list_t& _flag_list() const { return *this; }
_parameter_tuple_t _flags; _parameter_tuple_t _flags;
@ -76,6 +82,29 @@ namespace sqlpp
struct no_select_flag_list_t struct no_select_flag_list_t
{ {
using _is_noop = std::true_type; using _is_noop = std::true_type;
template<typename Policies>
struct _methods_t
{
using _database_t = typename Policies::_database_t;
template<typename T>
using _new_select_t = typename Policies::template _policies_update_t<no_select_flag_list_t, T>;
template<typename... Args>
auto flags(Args... args)
-> _new_select_t<select_flag_list_t<void, Args...>>
{
return { *static_cast<typename Policies::_select_t*>(this), select_flag_list_t<void, Args...>{args...} };
}
template<typename... Args>
auto dynamic_flags(Args... args)
-> _new_select_t<select_flag_list_t<_database_t, Args...>>
{
static_assert(not std::is_same<_database_t, void>::value, "dynamic_flags must not be called in a static statement");
return { *static_cast<typename Policies::_select_t*>(this), vendor::select_flag_list_t<_database_t, Args...>{args...} };
}
};
}; };