From 075e63c48680f014bfecb49363368cd1dc6ce468 Mon Sep 17 00:00:00 2001 From: rbock Date: Mon, 20 Jan 2014 23:17:07 +0100 Subject: [PATCH] Added test for (empty) dynamic select flag list --- include/sqlpp11/select.h | 18 +++++++++--------- include/sqlpp11/vendor/select_flag_list.h | 18 ++++++++++++++++-- tests/InterpretTest.cpp | 2 +- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 51a4bdab..3e78758c 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -151,12 +151,12 @@ namespace sqlpp // select functions template auto flags(Flag&&... flag) - -> set_flag_list_t::type...>> + -> set_flag_list_t::type...>>> { - static_assert(vendor::is_noop::value, "cannot call flags() after specifying them the first time"); - static_assert(vendor::is_noop::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::type...>{std::forward(flag)...}}, _column_list, _from, _where, @@ -170,13 +170,13 @@ namespace sqlpp template auto dynamic_flags(Flag&&... flag) - -> set_flag_list_t::type...>> + -> set_flag_list_t::type...>>> { static_assert(not std::is_same::value, "cannot call dynamic_flags() in a non-dynamic select"); - static_assert(vendor::is_noop::value, "cannot call dynamic_flags() after specifying them the first time"); - static_assert(vendor::is_noop::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::type...>{std::forward(flag)...}}, _column_list, _from, _where, @@ -190,7 +190,7 @@ namespace sqlpp template auto columns(Column&&... column) - -> set_column_list_t::type...>> + -> set_column_list_t::type...>>> { static_assert(not ColumnList::size::value, "cannot call columns() after specifying them the first time"); return { diff --git a/include/sqlpp11/vendor/select_flag_list.h b/include/sqlpp11/vendor/select_flag_list.h index bf281a22..83cdef0d 100644 --- a/include/sqlpp11/vendor/select_flag_list.h +++ b/include/sqlpp11/vendor/select_flag_list.h @@ -114,6 +114,11 @@ namespace sqlpp template struct select_flag_list_t> { + using _is_select_flag_list = std::true_type; + using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; + using _parameter_tuple_t = std::tuple; + using size = std::tuple_size<_parameter_tuple_t>; + // check for duplicate order expressions static_assert(not detail::has_duplicates::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::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 + void add(E&& expr) + { + static_assert(is_select_flag_t::type>::value, "flag arguments require to be select flags"); + _dynamic_flags.push_back(std::forward(expr)); + } - std::tuple _flags; + _parameter_tuple_t _flags; + vendor::interpretable_list_t _dynamic_flags; }; template @@ -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; } }; diff --git a/tests/InterpretTest.cpp b/tests/InterpretTest.cpp index 74904e21..2ce6e37a 100644 --- a/tests/InterpretTest.cpp +++ b/tests/InterpretTest.cpp @@ -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; }