diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 3e78758c..40c90ff9 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -131,7 +131,7 @@ namespace sqlpp Where where, GroupBy group_by, Having having, OrderBy order_by, Limit limit, Offset offset): _flags(flag_list), - _column_list(column_list), + _columns(column_list), _from(from), _where(where), _group_by(group_by), @@ -157,7 +157,7 @@ namespace sqlpp static_assert(not ColumnList::size::value, "cannot call columns() after specifying them the first time"); return { {std::tuple::type...>{std::forward(flag)...}}, - _column_list, + _columns, _from, _where, _group_by, @@ -177,7 +177,7 @@ namespace sqlpp static_assert(not ColumnList::size::value, "cannot call columns() after specifying them the first time"); return { {std::tuple::type...>{std::forward(flag)...}}, - _column_list, + _columns, _from, _where, _group_by, @@ -188,6 +188,16 @@ namespace sqlpp }; } + template + select_t& add_flag(Flag&& flag) + { + static_assert(is_dynamic_t::value, "cannot call add_flag() in a non-dynamic column list"); + + _flags.add(std::forward(flag)); + + return *this; + } + template auto columns(Column&&... column) -> set_column_list_t::type...>>> @@ -230,7 +240,7 @@ namespace sqlpp { static_assert(is_dynamic_t::value, "cannot call add_column() in a non-dynamic column list"); - _column_list.add(std::forward(namedExpr)); + _columns.add(std::forward(namedExpr)); return *this; } @@ -243,7 +253,7 @@ namespace sqlpp static_assert(vendor::is_noop::value, "cannot call from() twice for a single select"); return { _flags, - _column_list, + _columns, {std::tuple::type...>{std::forward(table)...}}, _where, _group_by, @@ -263,7 +273,7 @@ namespace sqlpp static_assert(vendor::is_noop::value, "cannot call from() twice for a single select"); return { _flags, - _column_list, + _columns, {std::tuple::type...>{std::forward
(table)...}}, _where, _group_by, @@ -293,7 +303,7 @@ namespace sqlpp static_assert(vendor::is_noop::value, "cannot call where() or dynamic_where() twice for a single select"); return { _flags, - _column_list, + _columns, _from, {std::tuple::type...>{std::forward(expr)...}}, _group_by, @@ -312,7 +322,7 @@ namespace sqlpp static_assert(vendor::is_noop::value, "cannot call where() or dynamic_where() twice for a single select"); return { _flags, - _column_list, + _columns, _from, {std::tuple::type...>{std::forward(expr)...}}, _group_by, @@ -341,7 +351,7 @@ namespace sqlpp static_assert(vendor::is_noop::value, "cannot call group_by() twice for a single select"); return { _flags, - _column_list, + _columns, _from, _where, {std::tuple::type...>{std::forward(column)...}}, @@ -360,7 +370,7 @@ namespace sqlpp static_assert(vendor::is_noop::value, "cannot call group_by() twice for a single select"); return { _flags, - _column_list, + _columns, _from, _where, {std::tuple::type...>{std::forward(column)...}}, @@ -389,7 +399,7 @@ namespace sqlpp static_assert(vendor::is_noop::value, "cannot call having() twice for a single select"); return { _flags, - _column_list, + _columns, _from, _where, _group_by, @@ -408,7 +418,7 @@ namespace sqlpp static_assert(vendor::is_noop::value, "cannot call having() twice for a single select"); return { _flags, - _column_list, + _columns, _from, _where, _group_by, @@ -437,7 +447,7 @@ namespace sqlpp static_assert(vendor::is_noop::value, "cannot call order_by() twice for a single select"); return { _flags, - _column_list, + _columns, _from, _where, _group_by, @@ -456,7 +466,7 @@ namespace sqlpp static_assert(vendor::is_noop::value, "cannot call order_by() twice for a single select"); return { _flags, - _column_list, + _columns, _from, _where, _group_by, @@ -485,7 +495,7 @@ namespace sqlpp static_assert(vendor::is_noop::value, "cannot call limit() twice for a single select"); return { _flags, - _column_list, + _columns, _from, _where, _group_by, @@ -503,7 +513,7 @@ namespace sqlpp static_assert(vendor::is_noop::value, "cannot call limit() twice for a single select"); return { _flags, - _column_list, + _columns, _from, _where, _group_by, @@ -531,7 +541,7 @@ namespace sqlpp static_assert(vendor::is_noop::value, "cannot call offset() twice for a single select"); return { _flags, - _column_list, + _columns, _from, _where, _group_by, @@ -549,7 +559,7 @@ namespace sqlpp static_assert(vendor::is_noop::value, "cannot call offset() twice for a single select"); return { _flags, - _column_list, + _columns, _from, _where, _group_by, @@ -585,7 +595,7 @@ namespace sqlpp const typename ColumnList::_dynamic_names_t& get_dynamic_names() const { - return _column_list._dynamic_expressions._dynamic_expression_names; + return _columns._dynamic_expressions._dynamic_expression_names; } static constexpr size_t _get_static_no_of_parameters() @@ -631,7 +641,7 @@ namespace sqlpp } FlagList _flags; - ColumnList _column_list; + ColumnList _columns; From _from; Where _where; GroupBy _group_by; @@ -682,7 +692,7 @@ namespace sqlpp context << "SELECT "; interpret(t._flags, context); - interpret(t._column_list, context); + interpret(t._columns, context); interpret(t._from, context); interpret(t._where, context); interpret(t._group_by, context); diff --git a/include/sqlpp11/vendor/select_column_list.h b/include/sqlpp11/vendor/select_column_list.h index e71f961f..36efb557 100644 --- a/include/sqlpp11/vendor/select_column_list.h +++ b/include/sqlpp11/vendor/select_column_list.h @@ -102,8 +102,13 @@ namespace sqlpp static Context& _(const T& t, Context& context) { + bool first = true; for (const auto column : t._dynamic_columns) { + if (first) + first = false; + else + context << ','; interpret(column, context); } return context; @@ -182,18 +187,18 @@ namespace sqlpp dynamic_select_column_list _dynamic_columns; }; - template - struct interpreter_t> + template + struct interpreter_t> { - using T = select_column_list_t; + using T = select_column_list_t; static Context& _(const T& t, Context& context) { // check for at least one expression - static_assert(T::_is_dynamic::value or sizeof...(NamedExpr), "at least one select expression required"); + static_assert(T::_is_dynamic::value or T::size::value, "at least one select expression required"); interpret_tuple(t._columns, ',', context); - if (sizeof...(NamedExpr) and not t._dynamic_columns.empty()) + if (T::size::value and not t._dynamic_columns.empty()) context << ','; interpret(t._dynamic_columns, context); return context; diff --git a/include/sqlpp11/vendor/select_flag_list.h b/include/sqlpp11/vendor/select_flag_list.h index 83cdef0d..d0aaaedf 100644 --- a/include/sqlpp11/vendor/select_flag_list.h +++ b/include/sqlpp11/vendor/select_flag_list.h @@ -130,7 +130,7 @@ namespace sqlpp 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)); + _dynamic_flags.emplace_back(std::forward(expr)); } _parameter_tuple_t _flags; diff --git a/tests/InterpretTest.cpp b/tests/InterpretTest.cpp index 2ce6e37a..b3d66de5 100644 --- a/tests/InterpretTest.cpp +++ b/tests/InterpretTest.cpp @@ -111,6 +111,8 @@ int main() // dynamic select interpret(dynamic_select(db).dynamic_flags().dynamic_columns(t.alpha).add_column(t.beta), printer).flush(); + interpret(dynamic_select(db).dynamic_flags().dynamic_columns().add_column(t.gamma).add_column(t.beta), printer).flush(); + interpret(dynamic_select(db).dynamic_flags(sqlpp::distinct).add_flag(sqlpp::all).dynamic_columns(t.alpha).add_column(t.beta), printer).flush(); return 0; }