0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-15 20:31:16 +08:00

Added test for (empty) dynamic select flag list

This commit is contained in:
rbock 2014-01-20 23:17:07 +01:00
parent ee7cda0a5d
commit 075e63c486
3 changed files with 26 additions and 12 deletions

View File

@ -151,12 +151,12 @@ namespace sqlpp
// select functions
template<typename... Flag>
auto flags(Flag&&... flag)
-> set_flag_list_t<vendor::select_flag_list_t<void, typename std::decay<Flag>::type...>>
-> set_flag_list_t<vendor::select_flag_list_t<void, std::tuple<typename std::decay<Flag>::type...>>>
{
static_assert(vendor::is_noop<FlagList>::value, "cannot call flags() after specifying them the first time");
static_assert(vendor::is_noop<ColumnList>::value, "cannot call dynamic_flags() after specifying columns");
static_assert(not FlagList::size::value, "cannot call dynamic_flags() after specifying them the first time");
static_assert(not ColumnList::size::value, "cannot call columns() after specifying them the first time");
return {
{flag...},
{std::tuple<typename std::decay<Flag>::type...>{std::forward<Flag>(flag)...}},
_column_list,
_from,
_where,
@ -170,13 +170,13 @@ namespace sqlpp
template<typename... Flag>
auto dynamic_flags(Flag&&... flag)
-> set_flag_list_t<vendor::select_flag_list_t<Database, typename std::decay<Flag>::type...>>
-> set_flag_list_t<vendor::select_flag_list_t<Database, std::tuple<typename std::decay<Flag>::type...>>>
{
static_assert(not std::is_same<Database, void>::value, "cannot call dynamic_flags() in a non-dynamic select");
static_assert(vendor::is_noop<FlagList>::value, "cannot call dynamic_flags() after specifying them the first time");
static_assert(vendor::is_noop<ColumnList>::value, "cannot call dynamic_flags() after specifying columns");
static_assert(not FlagList::size::value, "cannot call dynamic_flags() after specifying them the first time");
static_assert(not ColumnList::size::value, "cannot call columns() after specifying them the first time");
return {
{flag...},
{std::tuple<typename std::decay<Flag>::type...>{std::forward<Flag>(flag)...}},
_column_list,
_from,
_where,
@ -190,7 +190,7 @@ namespace sqlpp
template<typename... Column>
auto columns(Column&&... column)
-> set_column_list_t<vendor::select_column_list_t<void, typename std::decay<Column>::type...>>
-> set_column_list_t<vendor::select_column_list_t<void, std::tuple<typename std::decay<Column>::type...>>>
{
static_assert(not ColumnList::size::value, "cannot call columns() after specifying them the first time");
return {

View File

@ -114,6 +114,11 @@ namespace sqlpp
template<typename Database, typename... Flag>
struct select_flag_list_t<Database, std::tuple<Flag...>>
{
using _is_select_flag_list = std::true_type;
using _is_dynamic = typename std::conditional<std::is_same<Database, void>::value, std::false_type, std::true_type>::type;
using _parameter_tuple_t = std::tuple<Flag...>;
using size = std::tuple_size<_parameter_tuple_t>;
// check for duplicate order expressions
static_assert(not detail::has_duplicates<Flag...>::value, "at least one duplicate argument detected in select flag list");
@ -121,9 +126,15 @@ namespace sqlpp
using _valid_flags = typename detail::make_set_if<is_select_flag_t, Flag...>::type;
static_assert(_valid_flags::size::value == sizeof...(Flag), "at least one argument is not a select flag in select flag list");
using _is_select_flag_list = std::true_type;
template<typename E>
void add(E&& expr)
{
static_assert(is_select_flag_t<typename std::decay<E>::type>::value, "flag arguments require to be select flags");
_dynamic_flags.push_back(std::forward<E>(expr));
}
std::tuple<Flag...> _flags;
_parameter_tuple_t _flags;
vendor::interpretable_list_t<Database> _dynamic_flags;
};
template<typename Context, typename Database, typename... Flag>
@ -136,6 +147,9 @@ namespace sqlpp
interpret_tuple(t._flags, ' ', context);
if (sizeof...(Flag))
context << ' ';
interpret_list(t._dynamic_flags, ',', context);
if (not t._dynamic_flags.empty())
context << ' ';
return context;
}
};

View File

@ -110,7 +110,7 @@ int main()
interpret(multi_column(t.alpha, t.alpha, (t.beta + "cake").as(t.gamma)), printer).flush();
// dynamic select
interpret(dynamic_select(db).dynamic_columns(t.alpha).add_column(t.beta), printer).flush();
interpret(dynamic_select(db).dynamic_flags().dynamic_columns(t.alpha).add_column(t.beta), printer).flush();
return 0;
}