diff --git a/include/sqlpp11/basic_expression_operators.h b/include/sqlpp11/basic_expression_operators.h index 98e9bae2..ffa56525 100644 --- a/include/sqlpp11/basic_expression_operators.h +++ b/include/sqlpp11/basic_expression_operators.h @@ -187,14 +187,19 @@ namespace sqlpp return {*static_cast(this)}; } - auto asc() const -> sort_order_t + auto asc() const -> sort_order_t { - return {*static_cast(this)}; + return {*static_cast(this), sort_type::asc}; } - auto desc() const -> sort_order_t + auto desc() const -> sort_order_t { - return {*static_cast(this)}; + return {*static_cast(this), sort_type::desc}; + } + + auto order(sort_type s) const -> sort_order_t + { + return {*static_cast(this), s}; } template diff --git a/include/sqlpp11/sort_order.h b/include/sqlpp11/sort_order.h index 391898dd..4ef59e5e 100644 --- a/include/sqlpp11/sort_order.h +++ b/include/sqlpp11/sort_order.h @@ -39,25 +39,26 @@ namespace sqlpp desc }; - template + template struct sort_order_t { using _traits = make_traits; using _nodes = detail::type_vector; Expression _expression; + sort_type _sort_type; }; - template - struct serializer_t> + template + struct serializer_t> { using _serialize_check = serialize_check_of; - using T = sort_order_t; + using T = sort_order_t; static Context& _(const T& t, Context& context) { serialize_operand(t._expression, context); - switch (SortType) + switch (t._sort_type) { case sort_type::asc: context << " ASC"; diff --git a/test_serializer/CustomQuery.cpp b/test_serializer/CustomQuery.cpp index e4afaeb2..4c00aec5 100644 --- a/test_serializer/CustomQuery.cpp +++ b/test_serializer/CustomQuery.cpp @@ -57,9 +57,11 @@ int CustomQuery(int, char* []) custom_query(sqlpp::select(), dynamic_select_flags(db, sqlpp::distinct), dynamic_select_columns(db, foo.omega), dynamic_from(db, foo.join(bar).on(foo.omega == bar.alpha)), dynamic_where(db, bar.alpha > 17), dynamic_group_by(db, foo.omega), dynamic_having(db, avg(bar.alpha) > 19), - dynamic_order_by(db, foo.omega.asc()), sqlpp::dynamic_limit(db), sqlpp::dynamic_offset(db)), + dynamic_order_by(db, foo.omega.asc(), foo.psi.order(sqlpp::sort_type::desc)), + sqlpp::dynamic_limit(db), sqlpp::dynamic_offset(db)), "SELECT DISTINCT tab_foo.omega FROM tab_foo INNER JOIN tab_bar ON (tab_foo.omega=tab_bar.alpha) WHERE " - "(tab_bar.alpha>17) GROUP BY tab_foo.omega HAVING (AVG(tab_bar.alpha)>19) ORDER BY tab_foo.omega ASC "); + "(tab_bar.alpha>17) GROUP BY tab_foo.omega HAVING (AVG(tab_bar.alpha)>19) ORDER BY tab_foo.omega " + "ASC,tab_foo.psi DESC "); // A pragma query for sqlite compare(__LINE__, diff --git a/tests/Select.cpp b/tests/Select.cpp index 4b99b3a7..268488f2 100644 --- a/tests/Select.cpp +++ b/tests/Select.cpp @@ -160,6 +160,7 @@ int Select(int, char* []) s.offset.set(3u); s.group_by.add(t.beta); s.order_by.add(t.beta.asc()); + s.order_by.add(t.delta.order(sqlpp::sort_type::desc)); for (const auto& row : db(s)) { int64_t a = row.alpha;