From bf2744d5f7b5270049ae52b7d34e00242f8ab3fe Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 27 Nov 2014 23:18:23 +0100 Subject: [PATCH] Reduced error messages for order_by --- include/sqlpp11/order_by.h | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/include/sqlpp11/order_by.h b/include/sqlpp11/order_by.h index e9929aef..cc893efb 100644 --- a/include/sqlpp11/order_by.h +++ b/include/sqlpp11/order_by.h @@ -178,34 +178,45 @@ namespace sqlpp struct _methods_t { using _database_t = typename Policies::_database_t; - template - using _new_statement_t = new_statement; + + template + using _check = detail::all_t::value...>; + + template + using _new_statement_t = new_statement_t; using _consistency_check = consistent_t; template auto order_by(Expressions... expressions) const - -> _new_statement_t> + -> _new_statement_t<_check, order_by_t> { static_assert(sizeof...(Expressions), "at least one expression (e.g. a column) required in order_by()"); - return _order_by_impl(expressions...); + static_assert(detail::all_t::value...>::value, "at least one argument is not an expression in order_by()"); + + return _order_by_impl(_check{}, expressions...); } template auto dynamic_order_by(Expressions... expressions) const - -> _new_statement_t> + -> _new_statement_t<_check, order_by_t<_database_t, Expressions...>> { static_assert(not std::is_same<_database_t, void>::value, "dynamic_order_by must not be called in a static statement"); - return _order_by_impl<_database_t>(expressions...); + static_assert(detail::all_t::value...>::value, "at least one argument is not an expression in order_by()"); + + return _order_by_impl<_database_t>(_check{}, expressions...); } private: template - auto _order_by_impl(Expressions... expressions) const - -> _new_statement_t> + auto _order_by_impl(const std::false_type&, Expressions... expressions) const + -> bad_statement; + + template + auto _order_by_impl(const std::true_type&, Expressions... expressions) const + -> _new_statement_t> { static_assert(not detail::has_duplicates::value, "at least one duplicate argument detected in order_by()"); - static_assert(detail::all_t::value...>::value, "at least one argument is not an expression in order_by()"); return { static_cast&>(*this), order_by_data_t{expressions...} }; };