From cf83978118c8193962b62afcd4df52bc1c874fc6 Mon Sep 17 00:00:00 2001 From: rbock Date: Wed, 31 Aug 2016 21:15:54 +0200 Subject: [PATCH 01/11] Migrated select clauses to returning wrapped asserts This helps a lot in testing static asserts (and debuging expressions with MSVC) --- include/sqlpp11/all_of.h | 4 +- include/sqlpp11/case.h | 26 ++++----- include/sqlpp11/custom_query.h | 4 +- include/sqlpp11/dynamic_pre_join.h | 19 +++---- include/sqlpp11/from.h | 43 +++++++-------- include/sqlpp11/group_by.h | 58 ++++++++++---------- include/sqlpp11/having.h | 26 ++++----- include/sqlpp11/insert_value_list.h | 28 +++++----- include/sqlpp11/interpretable_list.h | 2 +- include/sqlpp11/limit.h | 43 +++++++-------- include/sqlpp11/offset.h | 43 +++++++-------- include/sqlpp11/order_by.h | 55 ++++++++++--------- include/sqlpp11/policy_update.h | 18 +++---- include/sqlpp11/portable_static_assert.h | 8 +-- include/sqlpp11/pre_join.h | 48 ++++++++--------- include/sqlpp11/rhs_wrap.h | 2 +- include/sqlpp11/select_column_list.h | 69 ++++++++++++------------ include/sqlpp11/select_flag_list.h | 56 ++++++++++--------- include/sqlpp11/serializer.h | 4 +- include/sqlpp11/statement.h | 20 ++++--- include/sqlpp11/tvin.h | 4 +- include/sqlpp11/update_list.h | 10 ++-- include/sqlpp11/using.h | 14 +++-- include/sqlpp11/where.h | 18 +++---- include/sqlpp11/with.h | 20 ++++--- tests/CMakeLists.txt | 28 +++++----- tests/MockDb.h | 20 ++++--- tests/Select.cpp | 4 +- 28 files changed, 326 insertions(+), 368 deletions(-) diff --git a/include/sqlpp11/all_of.h b/include/sqlpp11/all_of.h index 32dacf55..b7a2ea85 100644 --- a/include/sqlpp11/all_of.h +++ b/include/sqlpp11/all_of.h @@ -27,8 +27,8 @@ #ifndef SQLPP_ALL_OF_H #define SQLPP_ALL_OF_H -#include #include +#include #include #include @@ -62,7 +62,7 @@ namespace sqlpp static Context& _(const T&, const Context&) { - _serialize_check::_(); + _serialize_check{}; } }; } diff --git a/include/sqlpp11/case.h b/include/sqlpp11/case.h index 99a22e4b..b536d432 100644 --- a/include/sqlpp11/case.h +++ b/include/sqlpp11/case.h @@ -27,10 +27,10 @@ #ifndef SQLPP_CASE_H #define SQLPP_CASE_H -#include #include #include #include +#include namespace sqlpp { @@ -87,13 +87,13 @@ namespace sqlpp class case_then_t { template - auto _else_impl(const std::true_type&, Else else_) -> case_t + auto _else_impl(consistent_t, Else else_) -> case_t { return {_when, _then, else_}; } - template - auto _else_impl(const std::false_type&, Else else_) -> void; + template + auto _else_impl(Check, Else else_) -> Check; public: case_then_t(When when, Then then) : _when(when), _then(then) @@ -109,7 +109,6 @@ namespace sqlpp template auto else_(Else else_) -> decltype(this->_else_impl(check_case_else_t{}, else_)) { - check_case_else_t::_(); return _else_impl(check_case_else_t{}, else_); } @@ -122,13 +121,13 @@ namespace sqlpp class case_when_t { template - auto _then_impl(const std::true_type&, Then t) -> case_then_t> + auto _then_impl(consistent_t, Then t) -> case_then_t> { return {_when, t}; } - template - auto _then_impl(const std::false_type&, Then t) -> void; + template + auto _then_impl(Check, Then t) -> Check; public: case_when_t(When when) : _when(when) @@ -144,7 +143,6 @@ namespace sqlpp template auto then(Then t) -> decltype(this->_then_impl(check_case_then_t{}, t)) { - check_case_then_t::_(); return _then_impl(check_case_then_t{}, t); } @@ -174,21 +172,19 @@ namespace sqlpp namespace detail { template - auto case_when_impl(const std::true_type&, When when) -> case_when_t> + auto case_when_impl(consistent_t, When when) -> case_when_t> { return {when}; } - template - auto case_when_impl(const std::false_type&, When when) -> void; + template + auto case_when_impl(Check, When when) -> Check; } template auto case_when(When when) -> decltype(detail::case_when_impl(check_case_when_t{}, when)) { - check_case_when_t::_(); - - return detail::case_when_impl(typename check_case_when_t::type{}, when); + return detail::case_when_impl(check_case_when_t{}, when); } } diff --git a/include/sqlpp11/custom_query.h b/include/sqlpp11/custom_query.h index e5079968..abaf0df9 100644 --- a/include/sqlpp11/custom_query.h +++ b/include/sqlpp11/custom_query.h @@ -92,14 +92,14 @@ namespace sqlpp template auto _run(Db& db) const -> decltype(std::declval<_methods_t>()._run(db, *this)) { - _run_check::_(); + _run_check{}; // FIXME: dispatch here? return _methods_t::_run(db, *this); } template auto _prepare(Db& db) const -> decltype(std::declval<_methods_t>()._prepare(db, *this)) { - _prepare_check::_(); + _prepare_check{}; // FIXME: dispatch here? return _methods_t::_prepare(db, *this); } diff --git a/include/sqlpp11/dynamic_pre_join.h b/include/sqlpp11/dynamic_pre_join.h index 88aa9f84..da698e6c 100644 --- a/include/sqlpp11/dynamic_pre_join.h +++ b/include/sqlpp11/dynamic_pre_join.h @@ -91,10 +91,8 @@ namespace sqlpp template auto on(Expr expr) const -> typename std::conditional::value, dynamic_join_t>, - bad_statement>::type + check_dynamic_join_on_t>::type { - check_dynamic_join_on_t::_(); - return {*this, {expr}}; } @@ -119,40 +117,40 @@ namespace sqlpp template using make_dynamic_pre_join_t = typename std::conditional::value, dynamic_pre_join_t, - bad_statement>::type; + check_dynamic_pre_join_t>::type; template auto dynamic_join(Table table) -> make_dynamic_pre_join_t { - check_dynamic_pre_join_t
::_(); + check_dynamic_pre_join_t
{}; // FIXME: Failure return type? return {table}; } template auto dynamic_inner_join(Table table) -> make_dynamic_pre_join_t { - check_dynamic_pre_join_t
::_(); + check_dynamic_pre_join_t
{}; return {table}; } template auto dynamic_left_outer_join(Table table) -> make_dynamic_pre_join_t { - check_dynamic_pre_join_t
::_(); + check_dynamic_pre_join_t
{}; return {table}; } template auto dynamic_right_outer_join(Table table) -> make_dynamic_pre_join_t { - check_dynamic_pre_join_t
::_(); + check_dynamic_pre_join_t
{}; return {table}; } template auto dynamic_outer_join(Table table) -> make_dynamic_pre_join_t { - check_dynamic_pre_join_t
::_(); + check_dynamic_pre_join_t
{}; return {table}; } @@ -160,9 +158,8 @@ namespace sqlpp auto dynamic_cross_join(Table table) -> typename std::conditional::value, dynamic_join_t, on_t>, - bad_statement>::type + check_dynamic_pre_join_t
>::type { - check_dynamic_pre_join_t
::_(); return {dynamic_pre_join_t{table}, {}}; } } diff --git a/include/sqlpp11/from.h b/include/sqlpp11/from.h index 4968acbe..a226d81d 100644 --- a/include/sqlpp11/from.h +++ b/include/sqlpp11/from.h @@ -27,15 +27,15 @@ #ifndef SQLPP_FROM_H #define SQLPP_FROM_H +#include +#include +#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include -#include -#include -#include namespace sqlpp { @@ -116,23 +116,22 @@ namespace sqlpp } template - auto add(DynamicJoin dynamicJoin) -> - typename std::conditional::value, void, bad_statement>::type + auto add(DynamicJoin dynamicJoin) -> typename std:: + conditional::value, void, check_from_add_t<_impl_t, DynamicJoin>>::type { using Check = check_from_add_t<_impl_t, DynamicJoin>; - Check::_(); return _add_impl(dynamicJoin, Check{}); } private: template - auto _add_impl(DynamicJoin dynamicJoin, const std::true_type&) -> void + auto _add_impl(DynamicJoin dynamicJoin, consistent_t) -> void { _data._dynamic_tables.emplace_back(from_table(dynamicJoin)); } - template - auto _add_impl(DynamicJoin dynamicJoin, const std::false_type&) -> bad_statement; + template + auto _add_impl(DynamicJoin dynamicJoin, Check) -> Check; public: _data_t _data; @@ -146,8 +145,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 template - _base_t(Args&&... args) - : from{std::forward(args)...} + _base_t(Args&&... args) : from{std::forward(args)...} { } @@ -234,8 +232,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 template - _base_t(Args&&... args) - : no_from{std::forward(args)...} + _base_t(Args&&... args) : no_from{std::forward(args)...} { } @@ -258,7 +255,7 @@ namespace sqlpp using _database_t = typename Policies::_database_t; template - using _new_statement_t = new_statement_t; + using _new_statement_t = new_statement_t; using _consistency_check = consistent_t; @@ -266,7 +263,6 @@ namespace sqlpp auto from(Table table) const -> _new_statement_t, from_t>> { using Check = check_from_static_t
; - Check{}._(); return _from_impl(Check{}, table); } @@ -275,17 +271,16 @@ namespace sqlpp -> _new_statement_t, from_t<_database_t, from_table_t
>> { using Check = check_from_dynamic_t<_database_t, Table>; - Check{}._(); return _from_impl<_database_t>(Check{}, table); } private: - template - auto _from_impl(const std::false_type&, Table table) const -> bad_statement; + template + auto _from_impl(Check, Table table) const -> Check; template - auto _from_impl(const std::true_type&, Table table) const - -> _new_statement_t>> + auto _from_impl(consistent_t, Table table) const + -> _new_statement_t>> { return {static_cast&>(*this), from_data_t>{from_table(table)}}; diff --git a/include/sqlpp11/group_by.h b/include/sqlpp11/group_by.h index 8dd9deb1..34210ec8 100644 --- a/include/sqlpp11/group_by.h +++ b/include/sqlpp11/group_by.h @@ -27,13 +27,13 @@ #ifndef SQLPP_GROUP_BY_H #define SQLPP_GROUP_BY_H -#include -#include #include #include #include -#include #include +#include +#include +#include namespace sqlpp { @@ -67,9 +67,8 @@ namespace sqlpp using _nodes = detail::type_vector; using _is_dynamic = is_database; - using _provided_aggregates = typename std::conditional<_is_dynamic::value, - detail::type_set<>, - detail::make_type_set_t>::type; + using _provided_aggregates = typename std:: + conditional<_is_dynamic::value, detail::type_set<>, detail::make_type_set_t>::type; // Data using _data_t = group_by_data_t; @@ -92,7 +91,7 @@ namespace sqlpp static_assert(Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in group_by::add()"); using _serialize_check = sqlpp::serialize_check_t; - _serialize_check::_(); + _serialize_check{}; using ok = logic::all_t<_is_dynamic::value, is_expression_t::value, _serialize_check::type::value>; @@ -121,8 +120,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 template - _base_t(Args&&... args) - : group_by{std::forward(args)...} + _base_t(Args&&... args) : group_by{std::forward(args)...} { } @@ -148,6 +146,17 @@ namespace sqlpp }; }; + SQLPP_PORTABLE_STATIC_ASSERT(assert_group_by_args_are_expressions_t, + "arguments for group_by() must be valid expressions"); + template + struct check_group_by + { + using type = static_combined_check_t< + static_check_t::value...>::value, assert_group_by_args_are_expressions_t>>; + }; + template + using check_group_by_t = typename check_group_by::type; + // NO GROUP BY YET struct no_group_by_t { @@ -178,8 +187,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 template - _base_t(Args&&... args) - : no_group_by{std::forward(args)...} + _base_t(Args&&... args) : no_group_by{std::forward(args)...} { } @@ -201,47 +209,37 @@ namespace sqlpp using _database_t = typename Policies::_database_t; - // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 - // template - // using _check = logic::all_t::value...>; - template - struct _check : logic::all_t::value...> - { - }; - template - using _new_statement_t = new_statement_t; + using _new_statement_t = new_statement_t; using _consistency_check = consistent_t; template auto group_by(Expressions... expressions) const - -> _new_statement_t<_check, group_by_t> + -> _new_statement_t, group_by_t> { static_assert(sizeof...(Expressions), "at least one expression (e.g. a column) required in group_by()"); - static_assert(_check::value, "at least one argument is not an expression in group_by()"); - return _group_by_impl(_check{}, expressions...); + return _group_by_impl(check_group_by_t{}, expressions...); } template auto dynamic_group_by(Expressions... expressions) const - -> _new_statement_t<_check, group_by_t<_database_t, Expressions...>> + -> _new_statement_t, group_by_t<_database_t, Expressions...>> { static_assert(not std::is_same<_database_t, void>::value, "dynamic_group_by must not be called in a static statement"); - static_assert(_check::value, "at least one argument is not an expression in group_by()"); - return _group_by_impl<_database_t>(_check{}, expressions...); + return _group_by_impl<_database_t>(check_group_by_t{}, expressions...); } private: - template - auto _group_by_impl(const std::false_type&, Expressions... expressions) const -> bad_statement; + template + auto _group_by_impl(Check, Expressions... expressions) const -> Check; template - auto _group_by_impl(const std::true_type&, Expressions... expressions) const - -> _new_statement_t> + auto _group_by_impl(consistent_t, Expressions... expressions) const + -> _new_statement_t> { static_assert(not detail::has_duplicates::value, "at least one duplicate argument detected in group_by()"); diff --git a/include/sqlpp11/having.h b/include/sqlpp11/having.h index 4e768845..08905356 100644 --- a/include/sqlpp11/having.h +++ b/include/sqlpp11/having.h @@ -27,13 +27,13 @@ #ifndef SQLPP_HAVING_H #define SQLPP_HAVING_H -#include -#include #include #include #include -#include #include +#include +#include +#include namespace sqlpp { @@ -92,7 +92,7 @@ namespace sqlpp static_assert(Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in having::add()"); using _serialize_check = sqlpp::serialize_check_t; - _serialize_check::_(); + _serialize_check{}; using ok = logic::all_t<_is_dynamic::value, is_expression_t::value, _serialize_check::type::value>; @@ -121,8 +121,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 template - _base_t(Args&&... args) - : having{std::forward(args)...} + _base_t(Args&&... args) : having{std::forward(args)...} { } @@ -212,8 +211,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 template - _base_t(Args&&... args) - : no_having{std::forward(args)...} + _base_t(Args&&... args) : no_having{std::forward(args)...} { } @@ -244,7 +242,7 @@ namespace sqlpp }; template - using _new_statement_t = new_statement_t; + using _new_statement_t = new_statement_t; using _consistency_check = consistent_t; @@ -253,7 +251,6 @@ namespace sqlpp -> _new_statement_t, having_t> { using Check = check_having_static_t; - Check{}._(); return _having_impl(Check{}, expression); } @@ -263,7 +260,6 @@ namespace sqlpp -> _new_statement_t, having_t<_database_t, Expression>> { using Check = check_having_dynamic_t<_database_t, Expression>; - Check{}._(); return _having_impl<_database_t>(Check{}, expression); } @@ -275,12 +271,12 @@ namespace sqlpp } private: - template - auto _having_impl(const std::false_type&, Expression expression) const -> bad_statement; + template + auto _having_impl(Check, Expression expression) const -> Check; template - auto _having_impl(const std::true_type&, Expression expression) const - -> _new_statement_t> + auto _having_impl(consistent_t, Expression expression) const + -> _new_statement_t> { return {static_cast&>(*this), having_data_t{expression}}; diff --git a/include/sqlpp11/insert_value_list.h b/include/sqlpp11/insert_value_list.h index 2cae2a63..18bfde95 100644 --- a/include/sqlpp11/insert_value_list.h +++ b/include/sqlpp11/insert_value_list.h @@ -27,19 +27,19 @@ #ifndef SQLPP_INSERT_VALUE_LIST_H #define SQLPP_INSERT_VALUE_LIST_H -#include -#include -#include +#include #include #include -#include -#include -#include #include -#include +#include +#include +#include #include #include +#include +#include #include +#include namespace sqlpp { @@ -96,8 +96,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 template - _base_t(Args&&... args) - : default_values{std::forward(args)...} + _base_t(Args&&... args) : default_values{std::forward(args)...} { } @@ -264,7 +263,7 @@ namespace sqlpp static_assert(Policies::template _no_unknown_tables::value, "add() contains a column from a foreign table"); using _serialize_check = sqlpp::serialize_check_t; - _serialize_check::_(); + _serialize_check{}; using ok = logic::all_t<_is_dynamic::value, is_assignment_t::value, _serialize_check::type::value>; @@ -294,8 +293,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 template - _base_t(Args&&... args) - : insert_list{std::forward(args)...} + _base_t(Args&&... args) : insert_list{std::forward(args)...} { } @@ -400,8 +398,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 template - _base_t(Args&&... args) - : values{std::forward(args)...} + _base_t(Args&&... args) : values{std::forward(args)...} { } @@ -459,8 +456,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 template - _base_t(Args&&... args) - : no_insert_values{std::forward(args)...} + _base_t(Args&&... args) : no_insert_values{std::forward(args)...} { } diff --git a/include/sqlpp11/interpretable_list.h b/include/sqlpp11/interpretable_list.h index b91f82a9..dc11d0ae 100644 --- a/include/sqlpp11/interpretable_list.h +++ b/include/sqlpp11/interpretable_list.h @@ -27,8 +27,8 @@ #ifndef SQLPP_INTERPRETABLE_LIST_H #define SQLPP_INTERPRETABLE_LIST_H -#include #include +#include namespace sqlpp { diff --git a/include/sqlpp11/limit.h b/include/sqlpp11/limit.h index 2682ab87..d2fcb4ae 100644 --- a/include/sqlpp11/limit.h +++ b/include/sqlpp11/limit.h @@ -27,9 +27,9 @@ #ifndef SQLPP_LIMIT_H #define SQLPP_LIMIT_H -#include -#include #include +#include +#include namespace sqlpp { @@ -81,8 +81,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 template - _base_t(Args&&... args) - : limit{std::forward(args)...} + _base_t(Args&&... args) : limit{std::forward(args)...} { } @@ -115,8 +114,7 @@ namespace sqlpp } template - dynamic_limit_data_t(Limit value) - : _initialized(true), _value(wrap_operand_t(value)) + dynamic_limit_data_t(Limit value) : _initialized(true), _value(wrap_operand_t(value)) { } @@ -172,8 +170,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 template - _base_t(Args&&... args) - : limit{std::forward(args)...} + _base_t(Args&&... args) : limit{std::forward(args)...} { } @@ -197,6 +194,15 @@ namespace sqlpp }; }; + SQLPP_PORTABLE_STATIC_ASSERT(assert_limit_is_integral, "argument for limit() must be an integral expressions"); + template + struct check_limit + { + using type = static_combined_check_t::value, assert_limit_is_integral>>; + }; + template + using check_limit_t = typename check_limit>::type; + struct no_limit_t { using _traits = make_traits; @@ -226,8 +232,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 template - _base_t(Args&&... args) - : no_limit{std::forward(args)...} + _base_t(Args&&... args) : no_limit{std::forward(args)...} { } @@ -249,32 +254,28 @@ namespace sqlpp using _database_t = typename Policies::_database_t; - template - using _check = is_integral_t>; - template - using _new_statement_t = new_statement_t; + using _new_statement_t = new_statement_t; using _consistency_check = consistent_t; template - auto limit(Arg arg) const -> _new_statement_t<_check, limit_t>> + auto limit(Arg arg) const -> _new_statement_t, limit_t>> { - static_assert(_check::value, "limit requires an integral value or integral parameter"); - return _limit_impl(_check{}, wrap_operand_t{arg}); + return _limit_impl(check_limit_t{}, wrap_operand_t{arg}); } - auto dynamic_limit() const -> _new_statement_t> + auto dynamic_limit() const -> _new_statement_t> { return {static_cast&>(*this), dynamic_limit_data_t<_database_t>{}}; } private: - template - auto _limit_impl(const std::false_type&, Arg arg) const -> bad_statement; + template + auto _limit_impl(Check, Arg arg) const -> Check; template - auto _limit_impl(const std::true_type&, Arg arg) const -> _new_statement_t> + auto _limit_impl(consistent_t, Arg arg) const -> _new_statement_t> { return {static_cast&>(*this), limit_data_t{arg}}; } diff --git a/include/sqlpp11/offset.h b/include/sqlpp11/offset.h index 9251a6d2..8f1fd3e6 100644 --- a/include/sqlpp11/offset.h +++ b/include/sqlpp11/offset.h @@ -27,9 +27,9 @@ #ifndef SQLPP_OFFSET_H #define SQLPP_OFFSET_H -#include -#include #include +#include +#include namespace sqlpp { @@ -83,8 +83,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 template - _base_t(Args&&... args) - : offset{std::forward(args)...} + _base_t(Args&&... args) : offset{std::forward(args)...} { } @@ -117,8 +116,7 @@ namespace sqlpp } template - dynamic_offset_data_t(Offset value) - : _initialized(true), _value(wrap_operand_t(value)) + dynamic_offset_data_t(Offset value) : _initialized(true), _value(wrap_operand_t(value)) { } @@ -174,8 +172,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 template - _base_t(Args&&... args) - : offset{std::forward(args)...} + _base_t(Args&&... args) : offset{std::forward(args)...} { } @@ -211,6 +208,15 @@ namespace sqlpp interpretable_t _value; }; + SQLPP_PORTABLE_STATIC_ASSERT(assert_offset_is_integral, "argument for offset() must be an integral expressions"); + template + struct check_offset + { + using type = static_combined_check_t::value, assert_offset_is_integral>>; + }; + template + using check_offset_t = typename check_offset>::type; + struct no_offset_t { using _traits = make_traits; @@ -240,8 +246,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 template - _base_t(Args&&... args) - : no_offset{std::forward(args)...} + _base_t(Args&&... args) : no_offset{std::forward(args)...} { } @@ -263,22 +268,18 @@ namespace sqlpp using _database_t = typename Policies::_database_t; - template - using _check = is_integral_t>; - template - using _new_statement_t = new_statement_t; + using _new_statement_t = new_statement_t; using _consistency_check = consistent_t; template - auto offset(Arg arg) const -> _new_statement_t<_check, offset_t>> + auto offset(Arg arg) const -> _new_statement_t, offset_t>> { - static_assert(_check::value, "offset requires an integral value or integral parameter"); - return _offset_impl(_check{}, wrap_operand_t{arg}); + return _offset_impl(check_offset_t{}, wrap_operand_t{arg}); } - auto dynamic_offset() const -> _new_statement_t> + auto dynamic_offset() const -> _new_statement_t> { static_assert(not std::is_same<_database_t, void>::value, "dynamic_offset must not be called in a static statement"); @@ -286,11 +287,11 @@ namespace sqlpp } private: - template - auto _offset_impl(const std::false_type&, Arg arg) const -> bad_statement; + template + auto _offset_impl(Check, Arg arg) const -> Check; template - auto _offset_impl(const std::true_type&, Arg arg) const -> _new_statement_t> + auto _offset_impl(consistent_t, Arg arg) const -> _new_statement_t> { return {static_cast&>(*this), offset_data_t{arg}}; } diff --git a/include/sqlpp11/order_by.h b/include/sqlpp11/order_by.h index 4ac698bf..509d0950 100644 --- a/include/sqlpp11/order_by.h +++ b/include/sqlpp11/order_by.h @@ -27,13 +27,13 @@ #ifndef SQLPP_ORDER_BY_H #define SQLPP_ORDER_BY_H -#include -#include +#include #include #include -#include #include -#include +#include +#include +#include namespace sqlpp { @@ -89,7 +89,7 @@ namespace sqlpp static_assert(Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in order_by::add()"); using _serialize_check = sqlpp::serialize_check_t; - _serialize_check::_(); + _serialize_check{}; using ok = logic::all_t<_is_dynamic::value, is_sort_order_t::value, _serialize_check::type::value>; @@ -118,8 +118,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 template - _base_t(Args&&... args) - : order_by{std::forward(args)...} + _base_t(Args&&... args) : order_by{std::forward(args)...} { } @@ -145,6 +144,17 @@ namespace sqlpp }; }; + SQLPP_PORTABLE_STATIC_ASSERT(assert_order_by_args_are_sort_order_expressions_t, + "arguments for order_by() must be sort order expressions"); + template + struct check_order_by + { + using type = static_combined_check_t::value...>::value, + assert_order_by_args_are_sort_order_expressions_t>>; + }; + template + using check_order_by_t = typename check_order_by::type; + // NO ORDER BY YET struct no_order_by_t { @@ -175,8 +185,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 template - _base_t(Args&&... args) - : no_order_by{std::forward(args)...} + _base_t(Args&&... args) : no_order_by{std::forward(args)...} { } @@ -198,47 +207,37 @@ namespace sqlpp using _database_t = typename Policies::_database_t; - // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 - // template - // using _check = logic::all_t::value...>; - template - struct _check : logic::all_t::value...> - { - }; - template - using _new_statement_t = new_statement_t; + using _new_statement_t = new_statement_t; using _consistency_check = consistent_t; template auto order_by(Expressions... expressions) const - -> _new_statement_t<_check, order_by_t> + -> _new_statement_t, order_by_t> { static_assert(sizeof...(Expressions), "at least one expression (e.g. a column) required in order_by()"); - static_assert(_check::value, "at least one argument is not a sort order in order_by()"); - return _order_by_impl(_check{}, expressions...); + return _order_by_impl(check_order_by_t{}, expressions...); } template auto dynamic_order_by(Expressions... expressions) const - -> _new_statement_t<_check, order_by_t<_database_t, Expressions...>> + -> _new_statement_t, 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"); - static_assert(_check::value, "at least one argument is not a sort order in order_by()"); - return _order_by_impl<_database_t>(_check{}, expressions...); + return _order_by_impl<_database_t>(check_order_by_t{}, expressions...); } private: - template - auto _order_by_impl(const std::false_type&, Expressions... expressions) const -> bad_statement; + template + auto _order_by_impl(Check, Expressions... expressions) const -> Check; template - auto _order_by_impl(const std::true_type&, Expressions... expressions) const - -> _new_statement_t> + auto _order_by_impl(consistent_t, Expressions... expressions) const + -> _new_statement_t> { static_assert(not detail::has_duplicates::value, "at least one duplicate argument detected in order_by()"); diff --git a/include/sqlpp11/policy_update.h b/include/sqlpp11/policy_update.h index 4996e67a..b1cafabc 100644 --- a/include/sqlpp11/policy_update.h +++ b/include/sqlpp11/policy_update.h @@ -27,8 +27,8 @@ #ifndef SQLPP_POLICY_UPDATE_H #define SQLPP_POLICY_UPDATE_H -#include #include +#include namespace sqlpp { @@ -54,19 +54,19 @@ namespace sqlpp template using new_statement = typename Policies::template _new_statement_t; - template + template struct new_statement_impl + { + using type = Check; + }; + + template + struct new_statement_impl { using type = typename Policies::template _new_statement_t; }; - template - struct new_statement_impl - { - using type = bad_statement; - }; - - template + template using new_statement_t = typename new_statement_impl::type; } diff --git a/include/sqlpp11/portable_static_assert.h b/include/sqlpp11/portable_static_assert.h index bf7d3e22..dc3b94a2 100644 --- a/include/sqlpp11/portable_static_assert.h +++ b/include/sqlpp11/portable_static_assert.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2015, Roland Bock + * Copyright (c) 2015-2016, Roland Bock * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -34,10 +34,10 @@ namespace sqlpp #define SQLPP_PORTABLE_STATIC_ASSERT(name, message) \ struct name : std::false_type \ { \ - template \ - static void _() \ + template \ + name(T&&...) \ { \ - static_assert(wrong_t::value, message); \ + static_assert(wrong_t::value, message); \ } \ } diff --git a/include/sqlpp11/pre_join.h b/include/sqlpp11/pre_join.h index 1c765493..d0c68070 100644 --- a/include/sqlpp11/pre_join.h +++ b/include/sqlpp11/pre_join.h @@ -29,8 +29,8 @@ #include #include -#include #include +#include namespace sqlpp { @@ -106,20 +106,19 @@ namespace sqlpp template auto on(Expr expr) const -> typename std::conditional::value, join_t>, - bad_statement>::type + check_join_on_t>::type { using Check = check_join_on_t; - Check::_(); return on_impl(Check{}, expr); } private: - template - auto on_impl(const std::false_type&, const Expr&) const -> bad_statement; + template + auto on_impl(Check, const Expr&) const -> Check; template - auto on_impl(const std::true_type&, const Expr& expr) const -> join_t> + auto on_impl(consistent_t, const Expr& expr) const -> join_t> { return {*this, {expr}}; } @@ -146,51 +145,46 @@ namespace sqlpp }; template - auto join(Lhs lhs, Rhs rhs) -> typename std::conditional::value, - pre_join_t, - bad_statement>::type + auto join(Lhs lhs, Rhs rhs) -> typename std:: + conditional::value, pre_join_t, bad_statement>::type { - check_pre_join_t::_(); + check_pre_join_t{}; // FIXME: Failure return type? return {lhs, rhs}; } template - auto inner_join(Lhs lhs, Rhs rhs) -> typename std::conditional::value, - pre_join_t, - bad_statement>::type + auto inner_join(Lhs lhs, Rhs rhs) -> typename std:: + conditional::value, pre_join_t, bad_statement>::type { - check_pre_join_t::_(); + check_pre_join_t{}; return {lhs, rhs}; } template - auto left_outer_join(Lhs lhs, Rhs rhs) -> typename std::conditional::value, - pre_join_t, - bad_statement>::type + auto left_outer_join(Lhs lhs, Rhs rhs) -> typename std:: + conditional::value, pre_join_t, bad_statement>::type { - check_pre_join_t::_(); + check_pre_join_t{}; return {lhs, rhs}; } template - auto right_outer_join(Lhs lhs, Rhs rhs) -> typename std::conditional::value, - pre_join_t, - bad_statement>::type + auto right_outer_join(Lhs lhs, Rhs rhs) -> typename std:: + conditional::value, pre_join_t, bad_statement>::type { - check_pre_join_t::_(); + check_pre_join_t{}; return {lhs, rhs}; } template - auto outer_join(Lhs lhs, Rhs rhs) -> typename std::conditional::value, - pre_join_t, - bad_statement>::type + auto outer_join(Lhs lhs, Rhs rhs) -> typename std:: + conditional::value, pre_join_t, bad_statement>::type { - check_pre_join_t::_(); + check_pre_join_t{}; return {lhs, rhs}; } @@ -201,7 +195,7 @@ namespace sqlpp join_t, on_t>, bad_statement>::type { - check_pre_join_t::_(); + check_pre_join_t{}; return {pre_join_t{lhs, rhs}, {}}; } diff --git a/include/sqlpp11/rhs_wrap.h b/include/sqlpp11/rhs_wrap.h index 15573b4b..4e136afe 100644 --- a/include/sqlpp11/rhs_wrap.h +++ b/include/sqlpp11/rhs_wrap.h @@ -27,9 +27,9 @@ #ifndef SQLPP_RHS_WRAP_H #define SQLPP_RHS_WRAP_H -#include #include #include +#include namespace sqlpp { diff --git a/include/sqlpp11/select_column_list.h b/include/sqlpp11/select_column_list.h index 19f79eac..e6c3c3d2 100644 --- a/include/sqlpp11/select_column_list.h +++ b/include/sqlpp11/select_column_list.h @@ -27,19 +27,19 @@ #ifndef SQLPP_SELECT_COLUMN_LIST_H #define SQLPP_SELECT_COLUMN_LIST_H -#include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace sqlpp { @@ -135,7 +135,7 @@ namespace sqlpp static_assert(not detail::is_element_of::value, "a column of this name is present in the select already"); using _serialize_check = sqlpp::serialize_check_t; - _serialize_check::_(); + _serialize_check{}; using ok = logic::all_t<_is_dynamic::value, is_selectable_t::value, _serialize_check::type::value>; @@ -165,8 +165,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 template - _base_t(Args&&... args) - : selected_columns{std::forward(args)...} + _base_t(Args&&... args) : selected_columns{std::forward(args)...} { } @@ -249,7 +248,7 @@ namespace sqlpp template _alias_t as(const AliasProvider& aliasProvider) const { - consistency_check_t<_statement_t>::_(); + consistency_check_t<_statement_t>{}; static_assert(_statement_t::_can_be_used_as_table(), "statement cannot be used as table, e.g. due to missing tables"); static_assert(logic::none_t::value...>::value, @@ -302,6 +301,17 @@ namespace sqlpp copy_tuple_args_t()...))>; } + SQLPP_PORTABLE_STATIC_ASSERT(assert_selected_colums_are_selectable_t, "selected columns must be selectable"); + template + struct check_selected_columns + { + using type = static_combined_check_t< + static_check_t::value or is_multi_column_t::value)...>::value, + assert_selected_colums_are_selectable_t>>; + }; + template + using check_selected_columns_t = typename check_selected_columns::type; + struct no_select_column_list_t { using _traits = make_traits; @@ -335,8 +345,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 template - _base_t(Args&&... args) - : no_selected_columns{std::forward(args)...} + _base_t(Args&&... args) : no_selected_columns{std::forward(args)...} { } @@ -358,16 +367,8 @@ namespace sqlpp using _database_t = typename Policies::_database_t; - // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 - // template - // using _check = logic::all_t<(is_selectable_t::value or is_multi_column_t::value)...>; template - struct _check : logic::all_t<(is_selectable_t::value or is_multi_column_t::value)...> - { - }; - - template - static constexpr auto _check_tuple(std::tuple) -> _check + static constexpr auto _check_tuple(std::tuple) -> check_selected_columns_t { return {}; } @@ -375,11 +376,11 @@ namespace sqlpp template static constexpr auto _check_args(T... args) -> decltype(_check_tuple(detail::column_tuple_merge(args...))) { - return _check_tuple(detail::column_tuple_merge(args...)); + return {}; } template - using _new_statement_t = new_statement_t; + using _new_statement_t = new_statement_t; using _consistency_check = consistent_t; @@ -391,7 +392,7 @@ namespace sqlpp static_assert(decltype(_check_args(args...))::value, "at least one argument is not a selectable expression in columns()"); - return _columns_impl(_check_args(args...), detail::column_tuple_merge(args...)); + return _columns_impl(decltype(_check_args(args...)){}, detail::column_tuple_merge(args...)); } template @@ -403,16 +404,16 @@ namespace sqlpp static_assert(decltype(_check_args(args...))::value, "at least one argument is not a selectable expression in columns()"); - return _columns_impl<_database_t>(_check_args(args...), detail::column_tuple_merge(args...)); + return _columns_impl<_database_t>(decltype(_check_args(args...)){}, detail::column_tuple_merge(args...)); } private: - template - auto _columns_impl(const std::false_type&, std::tuple args) const -> bad_statement; + template + auto _columns_impl(Check, std::tuple args) const -> Check; template - auto _columns_impl(const std::true_type&, std::tuple args) const - -> _new_statement_t<_check, select_column_list_t> + auto _columns_impl(consistent_t, std::tuple args) const + -> _new_statement_t> { static_assert(not detail::has_duplicates::value, "at least one duplicate argument detected"); static_assert(not detail::has_duplicates::value, diff --git a/include/sqlpp11/select_flag_list.h b/include/sqlpp11/select_flag_list.h index 250c5e4d..4c87168c 100644 --- a/include/sqlpp11/select_flag_list.h +++ b/include/sqlpp11/select_flag_list.h @@ -27,13 +27,13 @@ #ifndef SQLPP_SELECT_FLAG_LIST_H #define SQLPP_SELECT_FLAG_LIST_H -#include -#include -#include -#include #include #include +#include #include +#include +#include +#include namespace sqlpp { @@ -85,7 +85,7 @@ namespace sqlpp static_assert(Policies::template _no_unknown_tables::value, "flag uses tables unknown to this statement in select_flags::add()"); using _serialize_check = sqlpp::serialize_check_t; - _serialize_check::_(); + _serialize_check{}; using ok = logic::all_t<_is_dynamic::value, is_select_flag_t::value, _serialize_check::type::value>; @@ -114,8 +114,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 template - _base_t(Args&&... args) - : select_flags{std::forward(args)...} + _base_t(Args&&... args) : select_flags{std::forward(args)...} { } @@ -139,6 +138,16 @@ namespace sqlpp }; }; + SQLPP_PORTABLE_STATIC_ASSERT(assert_select_flags_are_flags_t, "arguments for flags() must be known select flags"); + template + struct check_select_flags + { + using type = static_combined_check_t< + static_check_t::value...>::value, assert_select_flags_are_flags_t>>; + }; + template + using check_select_flags_t = typename check_select_flags::type; + struct no_select_flag_list_t { using _traits = make_traits; @@ -168,8 +177,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 template - _base_t(Args&&... args) - : no_select_flags{std::forward(args)...} + _base_t(Args&&... args) : no_select_flags{std::forward(args)...} { } @@ -191,45 +199,35 @@ namespace sqlpp using _database_t = typename Policies::_database_t; - // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 - // template - // using _check = logic::all_t::value...>; - template - struct _check : logic::all_t::type::value...> - { - }; - template - using _new_statement_t = new_statement_t; + using _new_statement_t = new_statement_t; using _consistency_check = consistent_t; template - auto flags(Flags... flgs) const -> _new_statement_t<_check, select_flag_list_t> + auto flags(Flags... flgs) const + -> _new_statement_t, select_flag_list_t> { - static_assert(_check::value, "at least one argument is not a select flag in select flag list"); - - return _flags_impl(_check{}, flgs...); + return _flags_impl(check_select_flags_t{}, flgs...); } template auto dynamic_flags(Flags... flgs) const - -> _new_statement_t<_check, select_flag_list_t<_database_t, Flags...>> + -> _new_statement_t, select_flag_list_t<_database_t, Flags...>> { static_assert(not std::is_same<_database_t, void>::value, "dynamic_flags must not be called in a static statement"); - static_assert(_check::value, "at least one argument is not a select flag in select flag list"); - return _flags_impl<_database_t>(_check{}, flgs...); + return _flags_impl<_database_t>(check_select_flags_t{}, flgs...); } private: - template - auto _flags_impl(const std::false_type&, Flags... flgs) const -> bad_statement; + template + auto _flags_impl(Check, Flags... flgs) const -> Check; template - auto _flags_impl(const std::true_type&, Flags... flgs) const - -> _new_statement_t> + auto _flags_impl(consistent_t, Flags... flgs) const + -> _new_statement_t> { static_assert(not detail::has_duplicates::value, "at least one duplicate argument detected in select flag list"); diff --git a/include/sqlpp11/serializer.h b/include/sqlpp11/serializer.h index 14f9a884..301d95af 100644 --- a/include/sqlpp11/serializer.h +++ b/include/sqlpp11/serializer.h @@ -27,8 +27,8 @@ #ifndef SQLPP_SERIALIZER_H #define SQLPP_SERIALIZER_H -#include #include +#include namespace sqlpp { @@ -41,7 +41,7 @@ namespace sqlpp static void _(const T&, Context&) { - _serialize_check::_(); + _serialize_check{}; } }; } diff --git a/include/sqlpp11/statement.h b/include/sqlpp11/statement.h index 286e6cec..34af1dcc 100644 --- a/include/sqlpp11/statement.h +++ b/include/sqlpp11/statement.h @@ -27,12 +27,12 @@ #ifndef SQLPP_STATEMENT_H #define SQLPP_STATEMENT_H -#include -#include -#include -#include #include +#include #include +#include +#include +#include #include #include @@ -142,9 +142,8 @@ namespace sqlpp typename std::conditional<_required_ctes::size::value == 0, consistent_t, assert_no_unknown_ctes_t>::type; using _table_check = typename std::conditional<_required_tables::size::value == 0, consistent_t, assert_no_unknown_tables_t>::type; - using _parameter_check = typename std::conditional::value == 0, - consistent_t, - assert_no_parameters_t>::type; + using _parameter_check = typename std:: + conditional::value == 0, consistent_t, assert_no_parameters_t>::type; }; } @@ -235,14 +234,14 @@ namespace sqlpp template auto _run(Database& db) const -> decltype(std::declval<_result_methods_t>()._run(db)) { - _run_check::_(); + _run_check{}; // FIXME: Dispatch? return _result_methods_t::_run(db); } template auto _prepare(Database& db) const -> decltype(std::declval<_result_methods_t>()._prepare(db)) { - _prepare_check::_(); + _prepare_check{}; // FIXME: Dispatch? return _result_methods_t::_prepare(db); } }; @@ -294,8 +293,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 template - _base_t(Args&&... args) - : statement_name{std::forward(args)...} + _base_t(Args&&... args) : statement_name{std::forward(args)...} { } diff --git a/include/sqlpp11/tvin.h b/include/sqlpp11/tvin.h index 40e01e1c..efe0f2b1 100644 --- a/include/sqlpp11/tvin.h +++ b/include/sqlpp11/tvin.h @@ -29,9 +29,9 @@ // TVIN: Trivial value is NULL -#include #include #include +#include #include namespace sqlpp @@ -67,7 +67,7 @@ namespace sqlpp static Context& _(const T&, Context&) { - _serialize_check::_(); + _serialize_check{}; } }; diff --git a/include/sqlpp11/update_list.h b/include/sqlpp11/update_list.h index c7dc360c..40610f12 100644 --- a/include/sqlpp11/update_list.h +++ b/include/sqlpp11/update_list.h @@ -27,10 +27,10 @@ #ifndef SQLPP_UPDATE_LIST_H #define SQLPP_UPDATE_LIST_H -#include #include #include #include +#include namespace sqlpp { @@ -89,7 +89,7 @@ namespace sqlpp static_assert(Policies::template _no_unknown_tables::value, "assignment uses tables unknown to this statement in add()"); using _serialize_check = sqlpp::serialize_check_t; - _serialize_check::_(); + _serialize_check{}; using ok = logic::all_t<_is_dynamic::value, is_assignment_t::value, _serialize_check::type::value>; @@ -118,8 +118,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 template - _base_t(Args&&... args) - : assignments{std::forward(args)...} + _base_t(Args&&... args) : assignments{std::forward(args)...} { } @@ -228,8 +227,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 template - _base_t(Args&&... args) - : no_assignments{std::forward(args)...} + _base_t(Args&&... args) : no_assignments{std::forward(args)...} { } diff --git a/include/sqlpp11/using.h b/include/sqlpp11/using.h index 4f9e7dbe..23090f57 100644 --- a/include/sqlpp11/using.h +++ b/include/sqlpp11/using.h @@ -27,11 +27,11 @@ #ifndef SQLPP_USING_H #define SQLPP_USING_H -#include -#include -#include #include +#include +#include #include +#include namespace sqlpp { @@ -81,7 +81,7 @@ namespace sqlpp static_assert(_is_dynamic::value, "add must not be called for static using()"); static_assert(is_table_t
::value, "invalid table argument in add()"); using _serialize_check = sqlpp::serialize_check_t; - _serialize_check::_(); + _serialize_check{}; using ok = logic::all_t<_is_dynamic::value, is_table_t
::value, _serialize_check::type::value>; @@ -110,8 +110,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 template - _base_t(Args&&... args) - : using_{std::forward(args)...} + _base_t(Args&&... args) : using_{std::forward(args)...} { } @@ -166,8 +165,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 template - _base_t(Args&&... args) - : no_using{std::forward(args)...} + _base_t(Args&&... args) : no_using{std::forward(args)...} { } diff --git a/include/sqlpp11/where.h b/include/sqlpp11/where.h index 4d41f2b8..93b7e45a 100644 --- a/include/sqlpp11/where.h +++ b/include/sqlpp11/where.h @@ -94,7 +94,7 @@ namespace sqlpp static_assert(not contains_aggregate_function_t::value, "where expression must not contain aggregate functions"); using _serialize_check = sqlpp::serialize_check_t; - _serialize_check::_(); + _serialize_check{}; using ok = logic::all_t<_is_dynamic::value, is_expression_t::value, _serialize_check::type::value>; @@ -307,14 +307,14 @@ namespace sqlpp using _database_t = typename Policies::_database_t; template - using _new_statement_t = new_statement_t; + using _new_statement_t = new_statement_t; using _consistency_check = typename std::conditional 0), assert_where_t, consistent_t>::type; - auto unconditionally() const -> _new_statement_t> + auto unconditionally() const -> _new_statement_t> { return {static_cast&>(*this), where_data_t{}}; } @@ -324,8 +324,6 @@ namespace sqlpp -> _new_statement_t, where_t> { using Check = check_where_static_t; - Check{}._(); - return _where_impl(Check{}, expression); } @@ -334,8 +332,6 @@ namespace sqlpp -> _new_statement_t, where_t<_database_t, Expression>> { using Check = check_where_dynamic_t<_database_t, Expression>; - Check{}._(); - return _where_impl<_database_t>(Check{}, expression); } @@ -346,12 +342,12 @@ namespace sqlpp } private: - template - auto _where_impl(const std::false_type&, Expression expression) const -> bad_statement; + template + auto _where_impl(Check, Expression expression) const -> Check; template - auto _where_impl(const std::true_type&, Expression expression) const - -> _new_statement_t> + auto _where_impl(consistent_t, Expression expression) const + -> _new_statement_t> { return {static_cast&>(*this), where_data_t{expression}}; diff --git a/include/sqlpp11/with.h b/include/sqlpp11/with.h index 4f7e3042..a9880af3 100644 --- a/include/sqlpp11/with.h +++ b/include/sqlpp11/with.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2013-2016, Roland Bock * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -29,15 +29,15 @@ #include #include -#include -#include -#include -#include -#include #include #include #include #include +#include +#include +#include +#include +#include #include @@ -96,8 +96,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 template - _base_t(Args&&... args) - : with{std::forward(args)...} + _base_t(Args&&... args) : with{std::forward(args)...} { } @@ -151,8 +150,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 template - _base_t(Args&&... args) - : no_with{std::forward(args)...} + _base_t(Args&&... args) : no_with{std::forward(args)...} { } @@ -183,7 +181,7 @@ namespace sqlpp template auto operator()(Statement statement) - -> new_statement_t> + -> new_statement_t> { // FIXME need checks here // check that no cte refers to any of the ctes to the right diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index df9335c6..57887c34 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -30,21 +30,21 @@ target_compile_options(sqlpp11_testing INTERFACE -Wall -Wextra -pedantic) endif () set(test_names - BooleanExpression - CustomQuery - DateTime - Interpret - Insert - Remove - Update + #BooleanExpression + #CustomQuery + #DateTime + #Interpret + #Insert + #Remove + #Update Select - SelectType - Function - Prepared - Minimalistic - Result - Union - With + #SelectType + #Function + #Prepared + #Minimalistic + #Result + #Union + #With ) create_test_sourcelist(test_sources test_main.cpp ${test_names}) diff --git a/tests/MockDb.h b/tests/MockDb.h index de055377..6e9dece4 100644 --- a/tests/MockDb.h +++ b/tests/MockDb.h @@ -26,13 +26,13 @@ #ifndef SQLPP_MOCK_DB_H #define SQLPP_MOCK_DB_H -#include #include -#include +#include #include +#include #include #include -#include +#include template struct MockDbT : public sqlpp::connection @@ -111,18 +111,17 @@ struct MockDbT : public sqlpp::connection // Directly executed statements start here template - auto _run(const T& t, const std::true_type&) -> decltype(t._run(*this)) + auto _run(const T& t, ::sqlpp::consistent_t) -> decltype(t._run(*this)) { return t._run(*this); } - template - auto _run(const T& t, const std::false_type&) -> void; + template + auto _run(const T& t, Check) -> Check; template auto operator()(const T& t) -> decltype(this->_run(t, sqlpp::run_check_t<_serializer_context_t, T>{})) { - sqlpp::run_check_t<_serializer_context_t, T>::_(); return _run(t, sqlpp::run_check_t<_serializer_context_t, T>{}); } @@ -182,18 +181,17 @@ struct MockDbT : public sqlpp::connection using _prepared_statement_t = std::nullptr_t; template - auto _prepare(const T& t, const std::true_type&) -> decltype(t._prepare(*this)) + auto _prepare(const T& t, ::sqlpp::consistent_t) -> decltype(t._prepare(*this)) { return t._prepare(*this); } - template - auto _prepare(const T& t, const std::false_type&) -> void; + template + auto _prepare(const T& t, Check) -> Check; template auto prepare(const T& t) -> decltype(this->_prepare(t, sqlpp::prepare_check_t<_serializer_context_t, T>{})) { - sqlpp::prepare_check_t<_serializer_context_t, T>::_(); return _prepare(t, sqlpp::prepare_check_t<_serializer_context_t, T>{}); } diff --git a/tests/Select.cpp b/tests/Select.cpp index f8ccd287..c60fb4e4 100644 --- a/tests/Select.cpp +++ b/tests/Select.cpp @@ -122,8 +122,8 @@ int Select(int, char* []) .group_by(t.alpha) .order_by(t.gamma.asc()) .having(t.gamma) - .limit(7) - .offset(19); + .offset(19) + .limit(7); printer.reset(); std::cerr << serialize(stat, printer).str() << std::endl; From 36afa04bcd9dbe17cf737fbd48314e36d4e94460 Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 1 Sep 2016 12:51:04 +0200 Subject: [PATCH 02/11] Adjusted insert to use wrapped asserts as failure return --- include/sqlpp11/insert_value_list.h | 49 ++++++++++++++--------------- include/sqlpp11/into.h | 37 ++++++++++++---------- tests/CMakeLists.txt | 4 +-- tests/Insert.cpp | 6 ++-- 4 files changed, 48 insertions(+), 48 deletions(-) diff --git a/include/sqlpp11/insert_value_list.h b/include/sqlpp11/insert_value_list.h index 18bfde95..5e16bfe5 100644 --- a/include/sqlpp11/insert_value_list.h +++ b/include/sqlpp11/insert_value_list.h @@ -426,6 +426,16 @@ namespace sqlpp SQLPP_PORTABLE_STATIC_ASSERT(assert_insert_values_t, "insert values required, e.g. set(...) or default_values()"); + SQLPP_PORTABLE_STATIC_ASSERT(assert_insert_columns_are_columns, "arguments for columns() must be table columns"); + template + struct check_insert_columns + { + using type = static_combined_check_t< + static_check_t::value...>::value, assert_insert_columns_are_columns>>; + }; + template + using check_insert_columns_t = typename check_insert_columns::type; + // NO INSERT COLUMNS/VALUES YET struct no_insert_value_list_t { @@ -478,32 +488,23 @@ namespace sqlpp using _database_t = typename Policies::_database_t; - // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 - // template - // using _column_check = logic::all_t::value...>; - template - struct _column_check : logic::all_t::value...> - { - }; - template - using _new_statement_t = new_statement_t; + using _new_statement_t = new_statement_t; using _consistency_check = assert_insert_values_t; - auto default_values() const -> _new_statement_t + auto default_values() const -> _new_statement_t { return {static_cast&>(*this), insert_default_values_data_t{}}; } template - auto columns(Columns... cols) const -> _new_statement_t<_column_check, column_list_t> + auto columns(Columns... cols) const + -> _new_statement_t, column_list_t> { - static_assert(logic::all_t::value...>::value, - "at least one argument is not a column in columns()"); static_assert(sizeof...(Columns), "at least one column required in columns()"); - return _columns_impl(_column_check{}, cols...); + return _columns_impl(check_insert_columns_t{}, cols...); } template @@ -511,8 +512,6 @@ namespace sqlpp -> _new_statement_t, insert_list_t> { using Check = check_insert_static_set_t; - Check{}._(); - return _set_impl(Check{}, assignments...); } @@ -522,18 +521,16 @@ namespace sqlpp insert_list_t<_database_t, Assignments...>> { using Check = check_insert_dynamic_set_t<_database_t, Assignments...>; - Check{}._(); - return _set_impl<_database_t>(Check{}, assignments...); } private: - template - auto _columns_impl(const std::false_type&, Columns... cols) const -> bad_statement; + template + auto _columns_impl(Check, Columns... cols) const -> Check; template - auto _columns_impl(const std::true_type&, Columns... cols) const - -> _new_statement_t> + auto _columns_impl(consistent_t, Columns... cols) const + -> _new_statement_t> { static_assert(not detail::has_duplicates::value, "at least one duplicate argument detected in columns()"); @@ -548,12 +545,12 @@ namespace sqlpp return {static_cast&>(*this), column_list_data_t{cols...}}; } - template - auto _set_impl(std::false_type, Assignments... assignments) const -> bad_statement; + template + auto _set_impl(Check, Assignments... assignments) const -> Check; template - auto _set_impl(std::true_type, Assignments... assignments) const - -> _new_statement_t> + auto _set_impl(consistent_t, Assignments... assignments) const + -> _new_statement_t> { return {static_cast&>(*this), insert_list_data_t{assignments...}}; diff --git a/include/sqlpp11/into.h b/include/sqlpp11/into.h index 308dec6b..e0489443 100644 --- a/include/sqlpp11/into.h +++ b/include/sqlpp11/into.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2013-2016, Roland Bock * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -27,13 +27,13 @@ #ifndef SQLPP_INTO_H #define SQLPP_INTO_H -#include -#include #include +#include #include #include #include -#include +#include +#include namespace sqlpp { @@ -88,8 +88,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 template - _base_t(Args&&... args) - : into{std::forward(args)...} + _base_t(Args&&... args) : into{std::forward(args)...} { } @@ -115,6 +114,15 @@ namespace sqlpp SQLPP_PORTABLE_STATIC_ASSERT(assert_into_t, "into() required"); + SQLPP_PORTABLE_STATIC_ASSERT(assert_into_arg_is_table, "argument for into() must be a table"); + template + struct check_into + { + using type = static_combined_check_t::value, assert_into_arg_is_table>>; + }; + template + using check_into_t = typename check_into>::type; + // NO INTO YET struct no_into_t { @@ -155,28 +163,23 @@ namespace sqlpp using _database_t = typename Policies::_database_t; - template - using _check = logic::all_t::value>; - template - using _new_statement_t = new_statement_t; + using _new_statement_t = new_statement_t; using _consistency_check = assert_into_t; template - auto into(Table table) const -> _new_statement_t<_check
, into_t> + auto into(Table table) const -> _new_statement_t, into_t> { - static_assert(_check
::value, "argument is not a raw table in into()"); - return _into_impl(_check
{}, table); + return _into_impl(check_into_t
{}, table); } private: - template - auto _into_impl(const std::false_type&, Table table) const -> bad_statement; + template + auto _into_impl(Check, Table table) const -> Check; template - auto _into_impl(const std::true_type&, Table table) const - -> _new_statement_t> + auto _into_impl(consistent_t, Table table) const -> _new_statement_t> { static_assert(required_tables_of>::size::value == 0, "argument depends on another table in into()"); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 57887c34..032bf09a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -34,10 +34,10 @@ set(test_names #CustomQuery #DateTime #Interpret - #Insert + Insert #Remove #Update - Select + #Select #SelectType #Function #Prepared diff --git a/tests/Insert.cpp b/tests/Insert.cpp index 0635f564..0c6e61b7 100644 --- a/tests/Insert.cpp +++ b/tests/Insert.cpp @@ -23,12 +23,12 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "Sample.h" #include "MockDb.h" +#include "Sample.h" #include "is_regular.h" -#include -#include #include +#include +#include int Insert(int, char* []) { From 637e0ad4d97e07db5c76798128ba8707b517120c Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 1 Sep 2016 18:22:19 +0200 Subject: [PATCH 03/11] Better failure return types for update and remove --- include/sqlpp11/select_pseudo_table.h | 3 +- include/sqlpp11/single_table.h | 41 ++++++++++++--------- include/sqlpp11/update_list.h | 14 +++---- include/sqlpp11/using.h | 53 ++++++++++++++------------- tests/CMakeLists.txt | 4 +- 5 files changed, 59 insertions(+), 56 deletions(-) diff --git a/include/sqlpp11/select_pseudo_table.h b/include/sqlpp11/select_pseudo_table.h index 196c5e10..679019e2 100644 --- a/include/sqlpp11/select_pseudo_table.h +++ b/include/sqlpp11/select_pseudo_table.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2013-2016, Roland Bock * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -28,6 +28,7 @@ #define SQLPP_SELECT_PSEUDO_TABLE_H #include +#include namespace sqlpp { diff --git a/include/sqlpp11/single_table.h b/include/sqlpp11/single_table.h index 1823346d..ee16289e 100644 --- a/include/sqlpp11/single_table.h +++ b/include/sqlpp11/single_table.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2013-2016, Roland Bock * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -27,12 +27,12 @@ #ifndef SQLPP_SINGLE_TABLE_H #define SQLPP_SINGLE_TABLE_H -#include #include -#include -#include -#include #include +#include +#include +#include +#include namespace sqlpp { @@ -90,8 +90,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 template - _base_t(Args&&... args) - : from{std::forward(args)...} + _base_t(Args&&... args) : from{std::forward(args)...} { } @@ -115,7 +114,16 @@ namespace sqlpp }; }; - // NO INTO YET + SQLPP_PORTABLE_STATIC_ASSERT(assert_update_table_arg_is_table_t, "argument for update() must be a table"); + template + struct check_update_table + { + using type = static_combined_check_t::value, assert_update_table_arg_is_table_t>>; + }; + template + using check_update_table_t = typename check_update_table
::type; + + // NO TABLE YET struct no_single_table_t { using _traits = make_traits; @@ -154,28 +162,25 @@ namespace sqlpp } using _database_t = typename Policies::_database_t; - template - using _check = logic::all_t::value>; template - using _new_statement_t = new_statement_t; + using _new_statement_t = new_statement_t; using _consistency_check = consistent_t; template - auto single_table(Table table) const -> _new_statement_t<_check
, single_table_t> + auto single_table(Table table) const -> _new_statement_t, single_table_t> { - static_assert(_check
::value, "argument is not a table in single_table()"); - return _single_table_impl(_check
{}, table); + return _single_table_impl(check_update_table_t
{}, table); } private: - template - auto _single_table_impl(const std::false_type&, Table table) const -> bad_statement; + template + auto _single_table_impl(Check, Table table) const -> Check; template - auto _single_table_impl(const std::true_type&, Table table) const - -> _new_statement_t> + auto _single_table_impl(consistent_t, Table table) const + -> _new_statement_t> { static_assert(required_tables_of>::size::value == 0, "argument depends on another table in single_table()"); diff --git a/include/sqlpp11/update_list.h b/include/sqlpp11/update_list.h index 40610f12..63e19af9 100644 --- a/include/sqlpp11/update_list.h +++ b/include/sqlpp11/update_list.h @@ -250,7 +250,7 @@ namespace sqlpp using _database_t = typename Policies::_database_t; template - using _new_statement_t = new_statement_t; + using _new_statement_t = new_statement_t; using _consistency_check = assert_update_assignments_t; @@ -259,8 +259,6 @@ namespace sqlpp -> _new_statement_t, update_list_t> { using Check = check_update_static_set_t; - Check{}._(); - return _set_impl(Check{}, assignments...); } @@ -270,18 +268,16 @@ namespace sqlpp update_list_t<_database_t, Assignments...>> { using Check = check_update_dynamic_set_t<_database_t, Assignments...>; - Check{}._(); - return _set_impl<_database_t>(Check{}, assignments...); } private: - template - auto _set_impl(const std::false_type&, Assignments... assignments) const -> bad_statement; + template + auto _set_impl(Check, Assignments... assignments) const -> Check; template - auto _set_impl(const std::true_type&, Assignments... assignments) const - -> _new_statement_t> + auto _set_impl(consistent_t, Assignments... assignments) const + -> _new_statement_t> { return {static_cast&>(*this), update_list_data_t{assignments...}}; diff --git a/include/sqlpp11/using.h b/include/sqlpp11/using.h index 23090f57..e09c5f4b 100644 --- a/include/sqlpp11/using.h +++ b/include/sqlpp11/using.h @@ -135,6 +135,16 @@ namespace sqlpp }; }; + SQLPP_PORTABLE_STATIC_ASSERT(assert_using_args_are_tables_t, "arguments for using() must be tables"); + template + struct check_using + { + using type = static_combined_check_t< + static_check_t::value...>::value, assert_using_args_are_tables_t>>; + }; + template + using check_using_t = typename check_using::type; + // NO USING YET struct no_using_t { @@ -187,52 +197,43 @@ namespace sqlpp using _database_t = typename Policies::_database_t; - // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 - // template - // using _check = logic::all_t::value...>; - template - struct _check : logic::all_t::value...> - { - }; - template - using _new_statement_t = new_statement_t; + using _new_statement_t = new_statement_t; using _consistency_check = consistent_t; - template - auto using_(Args... args) const -> _new_statement_t<_check, using_t> + template + auto using_(Tables... tables) const -> _new_statement_t, using_t> { - static_assert(not detail::has_duplicates::value, + static_assert(not detail::has_duplicates::value, "at least one duplicate argument detected in using()"); - static_assert(sizeof...(Args), "at least one table required in using()"); - static_assert(_check::value, "at least one argument is not an table in using()"); + static_assert(sizeof...(Tables), "at least one table required in using()"); - return {_using_impl(_check{}, args...)}; + return {_using_impl(check_using_t{}, tables...)}; } - template - auto dynamic_using(Args... args) const -> _new_statement_t<_check, using_t<_database_t, Args...>> + template + auto dynamic_using(Tables... tables) const + -> _new_statement_t, using_t<_database_t, Tables...>> { static_assert(not std::is_same<_database_t, void>::value, "dynamic_using must not be called in a static statement"); - static_assert(_check::value, "at least one argument is not an table in using()"); - return {_using_impl<_database_t>(_check{}, args...)}; + return {_using_impl<_database_t>(check_using_t{}, tables...)}; } private: - template - auto _using_impl(const std::false_type&, Args... args) const -> bad_statement; + template + auto _using_impl(Check, Tables... tables) const -> Check; - template - auto _using_impl(const std::true_type&, Args... args) const - -> _new_statement_t> + template + auto _using_impl(consistent_t, Tables... tables) const + -> _new_statement_t> { - static_assert(not detail::has_duplicates::value, + static_assert(not detail::has_duplicates::value, "at least one duplicate argument detected in using()"); - return {static_cast&>(*this), using_data_t{args...}}; + return {static_cast&>(*this), using_data_t{tables...}}; } }; }; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 032bf09a..39fbad16 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -34,9 +34,9 @@ set(test_names #CustomQuery #DateTime #Interpret - Insert + #Insert #Remove - #Update + Update #Select #SelectType #Function From 1a0f0ea0abdfe4a2197787ab5f6a404e99f9f1bd Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 1 Sep 2016 21:38:36 +0200 Subject: [PATCH 04/11] Everything compiles again. --- include/sqlpp11/policy_update.h | 1 - include/sqlpp11/pre_join.h | 68 +++++++------- include/sqlpp11/union.h | 49 +++++----- test_static_asserts/aggregates.cpp | 121 ++++++++++++------------- test_static_asserts/case.cpp | 10 +- test_static_asserts/from.cpp | 11 +-- test_static_asserts/having.cpp | 10 +- test_static_asserts/insert.cpp | 12 +-- test_static_asserts/join.cpp | 36 +++----- test_static_asserts/unwrapped_bool.cpp | 7 +- test_static_asserts/update_list.cpp | 10 +- test_static_asserts/where.cpp | 10 +- tests/CMakeLists.txt | 4 +- 13 files changed, 162 insertions(+), 187 deletions(-) diff --git a/include/sqlpp11/policy_update.h b/include/sqlpp11/policy_update.h index b1cafabc..70070e13 100644 --- a/include/sqlpp11/policy_update.h +++ b/include/sqlpp11/policy_update.h @@ -27,7 +27,6 @@ #ifndef SQLPP_POLICY_UPDATE_H #define SQLPP_POLICY_UPDATE_H -#include #include namespace sqlpp diff --git a/include/sqlpp11/pre_join.h b/include/sqlpp11/pre_join.h index d0c68070..86b84c92 100644 --- a/include/sqlpp11/pre_join.h +++ b/include/sqlpp11/pre_join.h @@ -27,7 +27,6 @@ #ifndef SQLPP_PRE_JOIN_H #define SQLPP_PRE_JOIN_H -#include #include #include #include @@ -144,18 +143,38 @@ namespace sqlpp } }; - template - auto join(Lhs lhs, Rhs rhs) -> typename std:: - conditional::value, pre_join_t, bad_statement>::type + namespace detail { - check_pre_join_t{}; // FIXME: Failure return type? + template + auto join_impl(Check, Lhs lhs, Rhs rhs) -> Check; + template + auto join_impl(consistent_t, Lhs lhs, Rhs rhs) -> pre_join_t; + + template + auto join_impl(Lhs lhs, Rhs rhs) -> decltype(join_impl(check_pre_join_t{}, lhs, rhs)); + } + + template + auto join(Lhs lhs, Rhs rhs) -> decltype(detail::join_impl(lhs, rhs)) + { return {lhs, rhs}; } template - auto inner_join(Lhs lhs, Rhs rhs) -> typename std:: - conditional::value, pre_join_t, bad_statement>::type + auto inner_join(Lhs lhs, Rhs rhs) -> decltype(detail::join_impl(lhs, rhs)) + { + return {lhs, rhs}; + } + + template + auto left_outer_join(Lhs lhs, Rhs rhs) -> decltype(detail::join_impl(lhs, rhs)) + { + return {lhs, rhs}; + } + + template + auto right_outer_join(Lhs lhs, Rhs rhs) -> decltype(detail::join_impl(lhs, rhs)) { check_pre_join_t{}; @@ -163,40 +182,27 @@ namespace sqlpp } template - auto left_outer_join(Lhs lhs, Rhs rhs) -> typename std:: - conditional::value, pre_join_t, bad_statement>::type + auto outer_join(Lhs lhs, Rhs rhs) -> decltype(detail::join_impl(lhs, rhs)) { - check_pre_join_t{}; - return {lhs, rhs}; } - template - auto right_outer_join(Lhs lhs, Rhs rhs) -> typename std:: - conditional::value, pre_join_t, bad_statement>::type + namespace detail { - check_pre_join_t{}; + template + auto cross_join_impl(Check, Lhs lhs, Rhs rhs) -> Check; - return {lhs, rhs}; + template + auto cross_join_impl(consistent_t, Lhs lhs, Rhs rhs) + -> join_t, on_t>; + + template + auto cross_join_impl(Lhs lhs, Rhs rhs) -> decltype(cross_join_impl(check_pre_join_t{}, lhs, rhs)); } template - auto outer_join(Lhs lhs, Rhs rhs) -> typename std:: - conditional::value, pre_join_t, bad_statement>::type + auto cross_join(Lhs lhs, Rhs rhs) -> decltype(detail::cross_join_impl(lhs, rhs)) { - check_pre_join_t{}; - - return {lhs, rhs}; - } - - template - auto cross_join(Lhs lhs, Rhs rhs) -> - typename std::conditional::value, - join_t, on_t>, - bad_statement>::type - { - check_pre_join_t{}; - return {pre_join_t{lhs, rhs}, {}}; } } diff --git a/include/sqlpp11/union.h b/include/sqlpp11/union.h index 49dd128e..80070abd 100644 --- a/include/sqlpp11/union.h +++ b/include/sqlpp11/union.h @@ -27,16 +27,16 @@ #ifndef SQLPP_UNION_H #define SQLPP_UNION_H -#include -#include -#include -#include -#include #include #include #include -#include #include +#include +#include +#include +#include +#include +#include namespace sqlpp { @@ -45,19 +45,19 @@ namespace sqlpp using blank_union_t = statement_t; // There is no order by or limit or offset in union, use it as a pseudo table to do that. - template + template struct union_statement_impl + { + using type = Check; + }; + + template + struct union_statement_impl { using type = statement_t; }; - template - struct union_statement_impl - { - using type = bad_statement; - }; - - template + template using union_statement_t = typename union_statement_impl::type; // UNION(EXPR) @@ -95,8 +95,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 template - _base_t(Args&&... args) - : union_{std::forward(args)...} + _base_t(Args&&... args) : union_{std::forward(args)...} { } @@ -166,8 +165,7 @@ namespace sqlpp // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 template - _base_t(Args&&... args) - : no_union{std::forward(args)...} + _base_t(Args&&... args) : no_union{std::forward(args)...} { } @@ -196,7 +194,7 @@ namespace sqlpp using _check = typename logic::all::value...>::type; template - using _new_statement_t = union_statement_t; + using _new_statement_t = union_statement_t; using _consistency_check = consistent_t; @@ -237,16 +235,15 @@ namespace sqlpp } private: - template - auto _union_impl(const std::false_type&, Rhs rhs) const -> bad_statement; + template + auto _union_impl(Check, Rhs rhs) const -> Check; template - auto _union_impl(const std::true_type&, Rhs rhs) const - -> _new_statement_t, Rhs>> + auto _union_impl(consistent_t, Rhs rhs) const + -> _new_statement_t, Rhs>> { - return {blank_union_t{}, - union_data_t, Rhs>{ - static_cast&>(*this), rhs}}; + return {blank_union_t{}, union_data_t, Rhs>{ + static_cast&>(*this), rhs}}; } }; }; diff --git a/test_static_asserts/aggregates.cpp b/test_static_asserts/aggregates.cpp index ba458fe6..5566c00d 100644 --- a/test_static_asserts/aggregates.cpp +++ b/test_static_asserts/aggregates.cpp @@ -23,104 +23,95 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include "Sample.h" #include "MockDb.h" +#include "Sample.h" +#include #include -#include -#include #include - -namespace sqlpp -{ - namespace test - { - template - void print_type_on_error(std::true_type, const T&) - { - } - - template - void print_type_on_error(std::false_type, const T& t) - { - t._print_me_; - } - - template - void run_check(const Expression&) - { - using Context = MockDb::_serializer_context_t; - using CheckResult = std::is_same, Assert>; - static_assert(CheckResult::value, "Unexpected run_check result"); - print_type_on_error(CheckResult{}, sqlpp::run_check_t{}); - } - - template - void run_check(const Expression&) - { - using Context = MockDb::_serializer_context_t; - using CheckResult = std::is_same, consistent_t>; - static_assert(CheckResult::value, "Unexpected run_check result"); - print_type_on_error(CheckResult{}, sqlpp::run_check_t{}); - } - } -} +#include +#include namespace { + template + void print_type_on_error(std::true_type) + { + } + + template + void print_type_on_error(std::false_type) + { + T::_print_me_; + } + + template + void static_run_check(const Expression&) + { + using Context = MockDb::_serializer_context_t; + using CheckResult = sqlpp::run_check_t; + using ExpectedCheckResult = std::is_same; + print_type_on_error(ExpectedCheckResult{}); + static_assert(ExpectedCheckResult::value, "Unexpected check result"); + } + SQLPP_ALIAS_PROVIDER(whatever) - using sqlpp::test::run_check; static constexpr auto t = test::TabBar{}; // If there is no group_by, we can select whatever we want void no_group_by() { - run_check(select(all_of(t)).from(t).unconditionally()); - run_check(select(t.alpha).from(t).unconditionally()); - run_check(select(count(t.alpha)).from(t).unconditionally()); + static_run_check(select(all_of(t)).from(t).unconditionally()); + static_run_check(select(t.alpha).from(t).unconditionally()); + static_run_check(select(count(t.alpha)).from(t).unconditionally()); } // If there is a dynamic group_by, we can still select whatever we want // because there is no way of knowing which expressions might have been added dynamically void dynamic_group_by() { - run_check(select(all_of(t)).from(t).unconditionally()); - run_check(select(t.alpha).from(t).unconditionally()); - run_check(select(count(t.alpha)).from(t).unconditionally()); + static_run_check(select(all_of(t)).from(t).unconditionally()); + static_run_check(select(t.alpha).from(t).unconditionally()); + static_run_check(select(count(t.alpha)).from(t).unconditionally()); } // If there is a static group_by, selected columns must be made of group_by expressions, or aggregate expression (e.g. // count(t.id)) or values to be valid void static_group_by_ok() { - run_check(select(t.alpha).from(t).unconditionally().group_by(t.alpha)); - run_check(select((t.alpha + 42).as(whatever)).from(t).unconditionally().group_by(t.alpha)); - run_check(select((t.alpha + 42).as(whatever)).from(t).unconditionally().group_by(t.alpha, t.alpha + t.delta * 17)); - run_check(select((t.alpha + t.delta * 17).as(whatever)) - .from(t) - .unconditionally() - .group_by(t.alpha, t.alpha + t.delta * 17)); - run_check(select((t.beta + "fortytwo").as(whatever)).from(t).unconditionally().group_by(t.beta)); + static_run_check(select(t.alpha).from(t).unconditionally().group_by(t.alpha)); + static_run_check( + select((t.alpha + 42).as(whatever)).from(t).unconditionally().group_by(t.alpha)); + static_run_check( + select((t.alpha + 42).as(whatever)).from(t).unconditionally().group_by(t.alpha, t.alpha + t.delta * 17)); + static_run_check(select((t.alpha + t.delta * 17).as(whatever)) + .from(t) + .unconditionally() + .group_by(t.alpha, t.alpha + t.delta * 17)); + static_run_check( + select((t.beta + "fortytwo").as(whatever)).from(t).unconditionally().group_by(t.beta)); - run_check(select(avg(t.alpha)).from(t).unconditionally().group_by(t.beta)); - run_check(select(count(t.alpha)).from(t).unconditionally().group_by(t.beta)); - run_check(select(max(t.alpha)).from(t).unconditionally().group_by(t.beta)); - run_check(select(min(t.alpha)).from(t).unconditionally().group_by(t.beta)); - run_check(select(sum(t.alpha)).from(t).unconditionally().group_by(t.beta)); + static_run_check(select(avg(t.alpha)).from(t).unconditionally().group_by(t.beta)); + static_run_check(select(count(t.alpha)).from(t).unconditionally().group_by(t.beta)); + static_run_check(select(max(t.alpha)).from(t).unconditionally().group_by(t.beta)); + static_run_check(select(min(t.alpha)).from(t).unconditionally().group_by(t.beta)); + static_run_check(select(sum(t.alpha)).from(t).unconditionally().group_by(t.beta)); - run_check(select((t.alpha + count(t.delta)).as(whatever)).from(t).unconditionally().group_by(t.alpha)); + static_run_check( + select((t.alpha + count(t.delta)).as(whatever)).from(t).unconditionally().group_by(t.alpha)); - run_check(select(sqlpp::value(1).as(whatever)).from(t).unconditionally().group_by(t.alpha)); - run_check(select(sqlpp::value("whatever").as(whatever)).from(t).unconditionally().group_by(t.alpha)); + static_run_check( + select(sqlpp::value(1).as(whatever)).from(t).unconditionally().group_by(t.alpha)); + static_run_check( + select(sqlpp::value("whatever").as(whatever)).from(t).unconditionally().group_by(t.alpha)); } // Failures with static group_by and selected non-aggregates or incorrect aggregates void static_group_by_nok() { - run_check(select(t.beta).from(t).unconditionally().group_by(t.alpha)); - run_check( + static_run_check(select(t.beta).from(t).unconditionally().group_by(t.alpha)); + static_run_check( select((t.alpha + t.delta).as(whatever)).from(t).unconditionally().group_by(t.alpha)); - run_check( + static_run_check( select((t.alpha + t.delta).as(whatever)).from(t).unconditionally().group_by(t.alpha, t.alpha + t.delta * 17)); } } diff --git a/test_static_asserts/case.cpp b/test_static_asserts/case.cpp index 44506abb..d3d0eb6b 100644 --- a/test_static_asserts/case.cpp +++ b/test_static_asserts/case.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2015, Roland Bock + * Copyright (c) 2015-2016, Roland Bock * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -23,9 +23,9 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include "MockDb.h" #include "Sample.h" +#include #include namespace @@ -52,7 +52,7 @@ namespace static_assert(ExpectedCheckResult::value, "Unexpected check result"); using ReturnType = decltype(sqlpp::case_when(when)); - using ExpectedReturnType = sqlpp::logic::all_t::value>; + using ExpectedReturnType = sqlpp::logic::all_t::value>; print_type_on_error(ExpectedReturnType{}); static_assert(ExpectedReturnType::value, "Unexpected return type"); } @@ -66,7 +66,7 @@ namespace static_assert(ExpectedCheckResult::value, "Unexpected check result"); using ReturnType = decltype(sqlpp::case_when(when).then(then)); - using ExpectedReturnType = sqlpp::logic::all_t::value>; + using ExpectedReturnType = sqlpp::logic::all_t::value>; print_type_on_error(ExpectedReturnType{}); static_assert(ExpectedReturnType::value, "Unexpected return type"); } @@ -80,7 +80,7 @@ namespace static_assert(ExpectedCheckResult::value, "Unexpected check result"); using ReturnType = decltype(sqlpp::case_when(when).then(then).else_(else_)); - using ExpectedReturnType = sqlpp::logic::all_t::value>; + using ExpectedReturnType = sqlpp::logic::all_t::value>; print_type_on_error(ExpectedReturnType{}); static_assert(ExpectedReturnType::value, "Unexpected return type"); } diff --git a/test_static_asserts/from.cpp b/test_static_asserts/from.cpp index 53fc9231..c4acab06 100644 --- a/test_static_asserts/from.cpp +++ b/test_static_asserts/from.cpp @@ -23,9 +23,9 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include "MockDb.h" #include "Sample.h" +#include #include namespace @@ -53,8 +53,7 @@ namespace static_assert(ExpectedCheckResult::value, "Unexpected check result"); using ReturnType = decltype(select(t.alpha).from(expression)); - using ExpectedReturnType = - sqlpp::logic::all_t::value>; + using ExpectedReturnType = sqlpp::logic::all_t::value>; print_type_on_error(ExpectedReturnType{}); static_assert(ExpectedReturnType::value, "Unexpected return type"); } @@ -69,8 +68,7 @@ namespace static_assert(ExpectedCheckResult::value, "Unexpected check result"); using ReturnType = decltype(dynamic_select(db, t.alpha).dynamic_from(expression)); - using ExpectedReturnType = - sqlpp::logic::all_t::value>; + using ExpectedReturnType = sqlpp::logic::all_t::value>; print_type_on_error(ExpectedReturnType{}); static_assert(ExpectedReturnType::value, "Unexpected return type"); } @@ -120,8 +118,7 @@ namespace static_assert(ExpectedCheckResult::value, "Unexpected check result"); using ReturnType = decltype(from.add(expression)); - using ExpectedReturnType = - sqlpp::logic::all_t::value>; + using ExpectedReturnType = sqlpp::logic::all_t::value>; print_type_on_error(ExpectedReturnType{}); static_assert(ExpectedReturnType::value, "Unexpected return type"); } diff --git a/test_static_asserts/having.cpp b/test_static_asserts/having.cpp index b4998275..d7d9bc1b 100644 --- a/test_static_asserts/having.cpp +++ b/test_static_asserts/having.cpp @@ -23,9 +23,9 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include "MockDb.h" #include "Sample.h" +#include #include namespace @@ -53,8 +53,7 @@ namespace static_assert(ExpectedCheckResult::value, "Unexpected check result"); using ReturnType = decltype(select(all_of(t)).from(t).unconditionally().group_by(t.alpha).having(expression)); - using ExpectedReturnType = - sqlpp::logic::all_t::value>; + using ExpectedReturnType = sqlpp::logic::all_t::value>; print_type_on_error(ExpectedReturnType{}); static_assert(ExpectedReturnType::value, "Unexpected return type"); } @@ -70,8 +69,7 @@ namespace using ReturnType = decltype(dynamic_select(db, all_of(t)).from(t).unconditionally().group_by(t.alpha).dynamic_having(expression)); - using ExpectedReturnType = - sqlpp::logic::all_t::value>; + using ExpectedReturnType = sqlpp::logic::all_t::value>; print_type_on_error(ExpectedReturnType{}); static_assert(ExpectedReturnType::value, "Unexpected return type"); } @@ -140,7 +138,7 @@ namespace static_assert(ExpectedCheckResult::value, "Unexpected check result"); using ReturnType = decltype(select(all_of(t)).from(t).dynamic_having()); - using ExpectedReturnType = std::is_same; + using ExpectedReturnType = std::is_same; print_type_on_error(ExpectedReturnType{}); static_assert(ExpectedReturnType::value, "Unexpected return type"); } diff --git a/test_static_asserts/insert.cpp b/test_static_asserts/insert.cpp index 9a37014b..6df6d5c8 100644 --- a/test_static_asserts/insert.cpp +++ b/test_static_asserts/insert.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2015, Roland Bock + * Copyright (c) 2015-2016, Roland Bock * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -23,9 +23,9 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include "MockDb.h" #include "Sample.h" +#include #include namespace @@ -53,8 +53,7 @@ namespace static_assert(ExpectedCheckResult::value, "Unexpected check result"); using ReturnType = decltype(insert_into(t).set(assignments...)); - using ExpectedReturnType = - sqlpp::logic::all_t::value>; + using ExpectedReturnType = sqlpp::logic::all_t::value>; print_type_on_error(ExpectedReturnType{}); static_assert(ExpectedReturnType::value, "Unexpected return type"); } @@ -69,8 +68,7 @@ namespace print_type_on_error(ExpectedCheckResult{}); using ReturnType = decltype(dynamic_insert_into(db, t).dynamic_set(assignments...)); - using ExpectedReturnType = - sqlpp::logic::all_t::value>; + using ExpectedReturnType = sqlpp::logic::all_t::value>; static_assert(ExpectedReturnType::value, "Unexpected return type"); print_type_on_error(ExpectedReturnType{}); } @@ -162,7 +160,7 @@ namespace print_type_on_error(ExpectedCheckResult{}); using ReturnType = decltype(insert_into(t).dynamic_set()); - using ExpectedReturnType = std::is_same; + using ExpectedReturnType = std::is_same; static_assert(ExpectedReturnType::value, "Unexpected return type"); print_type_on_error(ExpectedReturnType{}); } diff --git a/test_static_asserts/join.cpp b/test_static_asserts/join.cpp index e25fef2d..2c4117ea 100644 --- a/test_static_asserts/join.cpp +++ b/test_static_asserts/join.cpp @@ -23,9 +23,9 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include "MockDb.h" #include "Sample.h" +#include #include namespace @@ -62,12 +62,9 @@ namespace (Assert::value and sqlpp::is_pre_join_t::value and sqlpp::is_pre_join_t::value and sqlpp::is_pre_join_t::value and sqlpp::is_pre_join_t::value and sqlpp::is_pre_join_t::value and sqlpp::is_join_t::value) xor - (std::is_same::value and - std::is_same::value and - std::is_same::value and - std::is_same::value and - std::is_same::value and - std::is_same::value)>; + (std::is_same::value and std::is_same::value and + std::is_same::value and std::is_same::value and + std::is_same::value and std::is_same::value)>; print_type_on_error(ExpectedReturnType{}); print_type_on_error(ExpectedReturnType{}); print_type_on_error(ExpectedReturnType{}); @@ -87,7 +84,7 @@ namespace using ResultType = decltype(lhs.on(rhs)); using ExpectedReturnType = sqlpp::logic::all_t<(Assert::value and sqlpp::is_join_t::value) xor - std::is_same::value>; + std::is_same::value>; print_type_on_error(ExpectedReturnType{}); static_assert(ExpectedReturnType::value, "Unexpected return type"); } @@ -190,18 +187,15 @@ namespace using RightOuterJoinType = decltype(sqlpp::dynamic_right_outer_join(table)); using OuterJoinType = decltype(sqlpp::dynamic_outer_join(table)); using CrossJoinType = decltype(sqlpp::dynamic_cross_join(table)); - using ExpectedReturnType = sqlpp::logic::all_t<(Assert::value and sqlpp::is_dynamic_pre_join_t::value and - sqlpp::is_dynamic_pre_join_t::value and - sqlpp::is_dynamic_pre_join_t::value and - sqlpp::is_dynamic_pre_join_t::value and - sqlpp::is_dynamic_pre_join_t::value and - sqlpp::is_dynamic_join_t::value) xor - (std::is_same::value and - std::is_same::value and - std::is_same::value and - std::is_same::value and - std::is_same::value and - std::is_same::value)>; + using ExpectedReturnType = sqlpp::logic::all_t< + (Assert::value and sqlpp::is_dynamic_pre_join_t::value and + sqlpp::is_dynamic_pre_join_t::value and + sqlpp::is_dynamic_pre_join_t::value and + sqlpp::is_dynamic_pre_join_t::value and + sqlpp::is_dynamic_pre_join_t::value and sqlpp::is_dynamic_join_t::value) xor + (std::is_same::value and std::is_same::value and + std::is_same::value and std::is_same::value and + std::is_same::value and std::is_same::value)>; print_type_on_error(ExpectedReturnType{}); print_type_on_error(ExpectedReturnType{}); print_type_on_error(ExpectedReturnType{}); @@ -221,7 +215,7 @@ namespace using ResultType = decltype(lhs.on(rhs)); using ExpectedReturnType = sqlpp::logic::all_t<(Assert::value and sqlpp::is_dynamic_join_t::value) xor - std::is_same::value>; + std::is_same::value>; print_type_on_error(ExpectedReturnType{}); static_assert(ExpectedReturnType::value, "Unexpected return type"); } diff --git a/test_static_asserts/unwrapped_bool.cpp b/test_static_asserts/unwrapped_bool.cpp index 431a5ea8..fe190c75 100644 --- a/test_static_asserts/unwrapped_bool.cpp +++ b/test_static_asserts/unwrapped_bool.cpp @@ -23,9 +23,9 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include "MockDb.h" #include "Sample.h" +#include #include namespace @@ -82,8 +82,7 @@ namespace void where_check(const Condition& condition) { using ReturnType = decltype(sqlpp::where(condition)); - using ExpectedReturnType = - sqlpp::logic::all_t::value>; + using ExpectedReturnType = sqlpp::logic::all_t::value>; print_type_on_error(ExpectedReturnType{}); static_assert(ExpectedReturnType::value, "Unexpected return type"); } @@ -104,7 +103,7 @@ namespace void where() { where_check(t.gamma); - where_check(true); + where_check(true); } } diff --git a/test_static_asserts/update_list.cpp b/test_static_asserts/update_list.cpp index 06838013..56cb666f 100644 --- a/test_static_asserts/update_list.cpp +++ b/test_static_asserts/update_list.cpp @@ -23,9 +23,9 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include "MockDb.h" #include "Sample.h" +#include #include namespace @@ -53,8 +53,7 @@ namespace static_assert(ExpectedCheckResult::value, "Unexpected check result"); using ReturnType = decltype(update(t).set(expressions...)); - using ExpectedReturnType = - sqlpp::logic::all_t::value>; + using ExpectedReturnType = sqlpp::logic::all_t::value>; print_type_on_error(ExpectedReturnType{}); static_assert(ExpectedReturnType::value, "Unexpected return type"); } @@ -69,8 +68,7 @@ namespace static_assert(ExpectedCheckResult::value, "Unexpected check result"); using ReturnType = decltype(dynamic_update(db, t).dynamic_set(expressions...)); - using ExpectedReturnType = - sqlpp::logic::all_t::value>; + using ExpectedReturnType = sqlpp::logic::all_t::value>; print_type_on_error(ExpectedReturnType{}); static_assert(ExpectedReturnType::value, "Unexpected return type"); } @@ -127,7 +125,7 @@ namespace static_assert(ExpectedCheckResult::value, "Unexpected check result"); using ReturnType = decltype(update(t).dynamic_set()); - using ExpectedReturnType = std::is_same; + using ExpectedReturnType = std::is_same; print_type_on_error(ExpectedReturnType{}); static_assert(ExpectedReturnType::value, "Unexpected return type"); } diff --git a/test_static_asserts/where.cpp b/test_static_asserts/where.cpp index d232adff..360a782c 100644 --- a/test_static_asserts/where.cpp +++ b/test_static_asserts/where.cpp @@ -23,9 +23,9 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include "MockDb.h" #include "Sample.h" +#include #include namespace @@ -52,8 +52,7 @@ namespace static_assert(ExpectedCheckResult::value, "Unexpected check result"); using ReturnType = decltype(remove_from(t).where(expression)); - using ExpectedReturnType = - sqlpp::logic::all_t::value>; + using ExpectedReturnType = sqlpp::logic::all_t::value>; print_type_on_error(ExpectedReturnType{}); static_assert(ExpectedReturnType::value, "Unexpected return type"); } @@ -68,8 +67,7 @@ namespace static_assert(ExpectedCheckResult::value, "Unexpected check result"); using ReturnType = decltype(dynamic_remove_from(db, t).dynamic_where(expression)); - using ExpectedReturnType = - sqlpp::logic::all_t::value>; + using ExpectedReturnType = sqlpp::logic::all_t::value>; print_type_on_error(ExpectedReturnType{}); static_assert(ExpectedReturnType::value, "Unexpected return type"); } @@ -140,7 +138,7 @@ namespace static_assert(ExpectedCheckResult::value, "Unexpected check result"); using ReturnType = decltype(remove_from(t).dynamic_where()); - using ExpectedReturnType = std::is_same; + using ExpectedReturnType = std::is_same; print_type_on_error(ExpectedReturnType{}); static_assert(ExpectedReturnType::value, "Unexpected return type"); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 39fbad16..de3f952b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -36,14 +36,14 @@ set(test_names #Interpret #Insert #Remove - Update + #Update #Select #SelectType #Function #Prepared #Minimalistic #Result - #Union + Union #With ) From 5d09b736b678244c21322a1c51840b7442ad782d Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 1 Sep 2016 21:57:15 +0200 Subject: [PATCH 05/11] Better failure return values for union There are still a lot of untestable static_assert, but one thing at a time... --- include/sqlpp11/union.h | 29 +++++++++++++++++------------ tests/CMakeLists.txt | 30 +++++++++++++++--------------- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/include/sqlpp11/union.h b/include/sqlpp11/union.h index 80070abd..2bac56c7 100644 --- a/include/sqlpp11/union.h +++ b/include/sqlpp11/union.h @@ -135,6 +135,16 @@ namespace sqlpp using _result_methods_t = typename Lhs::template _result_methods_t; }; + SQLPP_PORTABLE_STATIC_ASSERT(assert_union_args_are_statements_t, "arguments for union() must be statements"); + template + struct check_union + { + using type = static_combined_check_t< + static_check_t::value...>::value, assert_union_args_are_statements_t>>; + }; + template + using check_union_t = typename check_union::type; + // NO UNION YET struct no_union_t { @@ -187,12 +197,6 @@ namespace sqlpp using _database_t = typename Policies::_database_t; - // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 - // template - // using _check = logic::all_t::value...>; - template - using _check = typename logic::all::value...>::type; - template using _new_statement_t = union_statement_t; @@ -200,7 +204,8 @@ namespace sqlpp template auto union_distinct(Rhs rhs) const - -> _new_statement_t<_check, union_t, Rhs>> + -> _new_statement_t, Rhs>, + union_t, Rhs>> { static_assert(is_statement_t::value, "argument of union call has to be a statement"); static_assert(has_policy_t::value, "argument of union call has to be a select"); @@ -213,12 +218,12 @@ namespace sqlpp "both arguments in a union have to have the same result columns (type and name)"); static_assert(is_static_result_row_t<_result_row_t>::value, "unions must not have dynamically added columns"); - return _union_impl(_check, Rhs>{}, rhs); + return _union_impl(check_union_t, Rhs>{}, rhs); } template - auto union_all(Rhs rhs) const - -> _new_statement_t<_check, union_t, Rhs>> + auto union_all(Rhs rhs) const -> _new_statement_t, Rhs>, + union_t, Rhs>> { static_assert(is_statement_t::value, "argument of union call has to be a statement"); static_assert(has_policy_t::value, "argument of union call has to be a select"); @@ -231,11 +236,11 @@ namespace sqlpp "both arguments in a union have to have the same result columns (type and name)"); static_assert(is_static_result_row_t<_result_row_t>::value, "unions must not have dynamically added columns"); - return _union_impl(_check, Rhs>{}, rhs); + return _union_impl(check_union_t, Rhs>{}, rhs); } private: - template + template auto _union_impl(Check, Rhs rhs) const -> Check; template diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index de3f952b..359b38f3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2013-2015, Roland Bock +# Copyright (c) 2013-2016, Roland Bock # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, @@ -30,21 +30,21 @@ target_compile_options(sqlpp11_testing INTERFACE -Wall -Wextra -pedantic) endif () set(test_names - #BooleanExpression - #CustomQuery - #DateTime - #Interpret - #Insert - #Remove - #Update - #Select - #SelectType - #Function - #Prepared - #Minimalistic - #Result + BooleanExpression + CustomQuery + DateTime + Interpret + Insert + Remove + Update + Select + SelectType + Function + Prepared + Minimalistic + Result Union - #With + With ) create_test_sourcelist(test_sources test_main.cpp ${test_names}) From 39dec1ea39e5a7d1da0791f171b5f858d8c7aa2b Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 1 Sep 2016 22:15:52 +0200 Subject: [PATCH 06/11] Better failure return type for cte --- include/sqlpp11/cte.h | 71 ++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 28 deletions(-) diff --git a/include/sqlpp11/cte.h b/include/sqlpp11/cte.h index d5a93336..54a2d984 100644 --- a/include/sqlpp11/cte.h +++ b/include/sqlpp11/cte.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2013-2016, Roland Bock * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -27,16 +27,16 @@ #ifndef SQLPP_CTE_H #define SQLPP_CTE_H -#include -#include -#include -#include -#include -#include #include #include #include #include +#include +#include +#include +#include +#include +#include namespace sqlpp { @@ -133,6 +133,31 @@ namespace sqlpp using type = member_t, column_t>>; }; + template + struct union_cte_impl + { + using type = Check; + }; + + template + struct union_cte_impl + { + using type = Union; + }; + + template + using union_cte_impl_t = typename union_cte_impl::type; + + SQLPP_PORTABLE_STATIC_ASSERT(assert_cte_union_args_are_statements_t, "argument for union() must be a statement"); + template + struct check_cte_union + { + using type = static_combined_check_t< + static_check_t::value...>::value, assert_cte_union_args_are_statements_t>>; + }; + template + using check_cte_union_t = typename check_cte_union::type; + template struct cte_t : public cte_base::type... { @@ -146,21 +171,12 @@ namespace sqlpp using _column_tuple_t = std::tuple>...>; - // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2086629 - // template - // using _check = logic::all_t::value...>; - template - struct _check : logic::all_t::value...> - { - }; - using _result_row_t = result_row_t; template - auto union_distinct(Rhs rhs) const -> - typename std::conditional<_check::value, - cte_t, FieldSpecs...>, - bad_statement>::type + auto union_distinct(Rhs rhs) const + -> union_cte_impl_t, + cte_t, FieldSpecs...>> { static_assert(is_statement_t::value, "argument of union call has to be a statement"); static_assert(has_policy_t::value, "argument of union call has to be a select"); @@ -169,14 +185,13 @@ namespace sqlpp static_assert(std::is_same<_result_row_t, get_result_row_t>::value, "both select statements in a union have to have the same result columns (type and name)"); - return _union_impl(_check{}, rhs); + return _union_impl(check_cte_union_t{}, rhs); } template - auto union_all(Rhs rhs) const -> - typename std::conditional<_check::value, - cte_t, FieldSpecs...>, - bad_statement>::type + auto union_all(Rhs rhs) const + -> union_cte_impl_t, + cte_t, FieldSpecs...>> { static_assert(is_statement_t::value, "argument of union call has to be a statement"); static_assert(has_policy_t::value, "argument of union call has to be a select"); @@ -185,15 +200,15 @@ namespace sqlpp static_assert(std::is_same<_result_row_t, get_result_row_t>::value, "both select statements in a union have to have the same result columns (type and name)"); - return _union_impl(_check{}, rhs); + return _union_impl(check_cte_union_t{}, rhs); } private: - template - auto _union_impl(const std::false_type&, Rhs rhs) const -> bad_statement; + template + auto _union_impl(Check, Rhs rhs) const -> Check; template - auto _union_impl(const std::true_type&, Rhs rhs) const + auto _union_impl(consistent_t, Rhs rhs) const -> cte_t, FieldSpecs...> { return cte_union_t{_statement, rhs}; From 407718a8a49330852ec423e8a8fd898dcc6affe3 Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 1 Sep 2016 22:31:53 +0200 Subject: [PATCH 07/11] Eliminated bad_statement Using wrapped static asserts now as return types --- include/sqlpp11/bad_statement.h | 43 ----------------------------- include/sqlpp11/result_field_base.h | 8 ++++-- 2 files changed, 5 insertions(+), 46 deletions(-) delete mode 100644 include/sqlpp11/bad_statement.h diff --git a/include/sqlpp11/bad_statement.h b/include/sqlpp11/bad_statement.h deleted file mode 100644 index c8b78a5c..00000000 --- a/include/sqlpp11/bad_statement.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2013-2015, Roland Bock - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SQLPP_BAD_STATEMENT_H -#define SQLPP_BAD_STATEMENT_H - -namespace sqlpp -{ - struct bad_statement - { - static constexpr bool value = false; - - template - bad_statement(T&&...) - { - } - }; -} - -#endif diff --git a/include/sqlpp11/result_field_base.h b/include/sqlpp11/result_field_base.h index 01f66758..3f6d3992 100644 --- a/include/sqlpp11/result_field_base.h +++ b/include/sqlpp11/result_field_base.h @@ -28,7 +28,6 @@ #define SQLPP_RESULT_FIELD_BASE_H #include -#include #include #include #include @@ -37,6 +36,8 @@ namespace sqlpp { + SQLPP_PORTABLE_STATIC_ASSERT(assert_result_field_value_is_safe_t, "result field value needs to be checked for NULL"); + template ::_cpp_value_type> struct result_field_base { @@ -117,8 +118,9 @@ namespace sqlpp return _value; } - operator typename std::conditional<_null_is_trivial or (not _can_be_null::value), _cpp_value_type, bad_statement>:: - type() const + operator typename std::conditional<_null_is_trivial or (not _can_be_null::value), + _cpp_value_type, + assert_result_field_value_is_safe_t>::type() const { return value(); } From d841a7d8a5c6f98fd081e896814786fb867deaa2 Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 2 Sep 2016 11:17:30 +0200 Subject: [PATCH 08/11] Fixed gcc ambiguity bug See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77449 --- include/sqlpp11/group_by.h | 2 +- include/sqlpp11/inconsistent.h | 48 ++++++++++++++++++++++++ include/sqlpp11/insert_value_list.h | 4 +- include/sqlpp11/order_by.h | 2 +- include/sqlpp11/portable_static_assert.h | 1 + include/sqlpp11/select_flag_list.h | 2 +- include/sqlpp11/update_list.h | 2 +- include/sqlpp11/using.h | 2 +- 8 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 include/sqlpp11/inconsistent.h diff --git a/include/sqlpp11/group_by.h b/include/sqlpp11/group_by.h index 34210ec8..8d5a4696 100644 --- a/include/sqlpp11/group_by.h +++ b/include/sqlpp11/group_by.h @@ -235,7 +235,7 @@ namespace sqlpp private: template - auto _group_by_impl(Check, Expressions... expressions) const -> Check; + auto _group_by_impl(inconsistent, Expressions... expressions) const -> Check; template auto _group_by_impl(consistent_t, Expressions... expressions) const diff --git a/include/sqlpp11/inconsistent.h b/include/sqlpp11/inconsistent.h new file mode 100644 index 00000000..326be226 --- /dev/null +++ b/include/sqlpp11/inconsistent.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2016-2016, Roland Bock + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SQLPP_INCONSISTENT_H +#define SQLPP_INCONSISTENT_H + +namespace sqlpp +{ + template + struct inconsistent + { + inconsistent(Check) + { + } + }; + + // This specialization circumvents an ambiguity problem with gcc + // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77449 + template <> + struct inconsistent + { + }; +} + +#endif diff --git a/include/sqlpp11/insert_value_list.h b/include/sqlpp11/insert_value_list.h index 5e16bfe5..8eb718f6 100644 --- a/include/sqlpp11/insert_value_list.h +++ b/include/sqlpp11/insert_value_list.h @@ -526,7 +526,7 @@ namespace sqlpp private: template - auto _columns_impl(Check, Columns... cols) const -> Check; + auto _columns_impl(inconsistent, Columns... cols) const -> Check; template auto _columns_impl(consistent_t, Columns... cols) const @@ -546,7 +546,7 @@ namespace sqlpp } template - auto _set_impl(Check, Assignments... assignments) const -> Check; + auto _set_impl(inconsistent, Assignments... assignments) const -> Check; template auto _set_impl(consistent_t, Assignments... assignments) const diff --git a/include/sqlpp11/order_by.h b/include/sqlpp11/order_by.h index 509d0950..d13eb7a9 100644 --- a/include/sqlpp11/order_by.h +++ b/include/sqlpp11/order_by.h @@ -233,7 +233,7 @@ namespace sqlpp private: template - auto _order_by_impl(Check, Expressions... expressions) const -> Check; + auto _order_by_impl(inconsistent, Expressions... expressions) const -> Check; template auto _order_by_impl(consistent_t, Expressions... expressions) const diff --git a/include/sqlpp11/portable_static_assert.h b/include/sqlpp11/portable_static_assert.h index dc3b94a2..b0a8036c 100644 --- a/include/sqlpp11/portable_static_assert.h +++ b/include/sqlpp11/portable_static_assert.h @@ -28,6 +28,7 @@ #define SQLPP_PORTABLE_STATIC_ASSERT_H #include +#include namespace sqlpp { diff --git a/include/sqlpp11/select_flag_list.h b/include/sqlpp11/select_flag_list.h index 4c87168c..7f593055 100644 --- a/include/sqlpp11/select_flag_list.h +++ b/include/sqlpp11/select_flag_list.h @@ -223,7 +223,7 @@ namespace sqlpp private: template - auto _flags_impl(Check, Flags... flgs) const -> Check; + auto _flags_impl(inconsistent, Flags... flgs) const -> Check; template auto _flags_impl(consistent_t, Flags... flgs) const diff --git a/include/sqlpp11/update_list.h b/include/sqlpp11/update_list.h index 63e19af9..c79c17d0 100644 --- a/include/sqlpp11/update_list.h +++ b/include/sqlpp11/update_list.h @@ -273,7 +273,7 @@ namespace sqlpp private: template - auto _set_impl(Check, Assignments... assignments) const -> Check; + auto _set_impl(inconsistent, Assignments... assignments) const -> Check; template auto _set_impl(consistent_t, Assignments... assignments) const diff --git a/include/sqlpp11/using.h b/include/sqlpp11/using.h index e09c5f4b..84fede64 100644 --- a/include/sqlpp11/using.h +++ b/include/sqlpp11/using.h @@ -224,7 +224,7 @@ namespace sqlpp private: template - auto _using_impl(Check, Tables... tables) const -> Check; + auto _using_impl(inconsistent, Tables... tables) const -> Check; template auto _using_impl(consistent_t, Tables... tables) const From 827c8dbf61780b0e25facbf697cbcbfecc74b7d1 Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 2 Sep 2016 22:35:12 +0200 Subject: [PATCH 09/11] The previous fix wasn't. Found this via build-system tests of static asserts through MSVC. --- include/sqlpp11/case.h | 6 +++--- include/sqlpp11/cte.h | 2 +- include/sqlpp11/from.h | 4 ++-- include/sqlpp11/group_by.h | 2 +- include/sqlpp11/having.h | 2 +- include/sqlpp11/inconsistent.h | 21 +++++++++------------ include/sqlpp11/insert_value_list.h | 4 ++-- include/sqlpp11/into.h | 2 +- include/sqlpp11/limit.h | 2 +- include/sqlpp11/offset.h | 2 +- include/sqlpp11/order_by.h | 2 +- include/sqlpp11/pre_join.h | 6 +++--- include/sqlpp11/select_column_list.h | 2 +- include/sqlpp11/select_flag_list.h | 2 +- include/sqlpp11/single_table.h | 2 +- include/sqlpp11/union.h | 2 +- include/sqlpp11/update_list.h | 2 +- include/sqlpp11/using.h | 2 +- include/sqlpp11/where.h | 2 +- test_serializer/CustomQuery.cpp | 2 +- 20 files changed, 34 insertions(+), 37 deletions(-) diff --git a/include/sqlpp11/case.h b/include/sqlpp11/case.h index b536d432..c59ff791 100644 --- a/include/sqlpp11/case.h +++ b/include/sqlpp11/case.h @@ -93,7 +93,7 @@ namespace sqlpp } template - auto _else_impl(Check, Else else_) -> Check; + auto _else_impl(Check, Else else_) -> inconsistent; public: case_then_t(When when, Then then) : _when(when), _then(then) @@ -127,7 +127,7 @@ namespace sqlpp } template - auto _then_impl(Check, Then t) -> Check; + auto _then_impl(Check, Then t) -> inconsistent; public: case_when_t(When when) : _when(when) @@ -178,7 +178,7 @@ namespace sqlpp } template - auto case_when_impl(Check, When when) -> Check; + auto case_when_impl(Check, When when) -> inconsistent; } template diff --git a/include/sqlpp11/cte.h b/include/sqlpp11/cte.h index 54a2d984..cc7a8827 100644 --- a/include/sqlpp11/cte.h +++ b/include/sqlpp11/cte.h @@ -205,7 +205,7 @@ namespace sqlpp private: template - auto _union_impl(Check, Rhs rhs) const -> Check; + auto _union_impl(Check, Rhs rhs) const -> inconsistent; template auto _union_impl(consistent_t, Rhs rhs) const diff --git a/include/sqlpp11/from.h b/include/sqlpp11/from.h index a226d81d..afdc810f 100644 --- a/include/sqlpp11/from.h +++ b/include/sqlpp11/from.h @@ -131,7 +131,7 @@ namespace sqlpp } template - auto _add_impl(DynamicJoin dynamicJoin, Check) -> Check; + auto _add_impl(DynamicJoin dynamicJoin, Check) -> inconsistent; public: _data_t _data; @@ -276,7 +276,7 @@ namespace sqlpp private: template - auto _from_impl(Check, Table table) const -> Check; + auto _from_impl(Check, Table table) const -> inconsistent; template auto _from_impl(consistent_t, Table table) const diff --git a/include/sqlpp11/group_by.h b/include/sqlpp11/group_by.h index 8d5a4696..5a8c420b 100644 --- a/include/sqlpp11/group_by.h +++ b/include/sqlpp11/group_by.h @@ -235,7 +235,7 @@ namespace sqlpp private: template - auto _group_by_impl(inconsistent, Expressions... expressions) const -> Check; + auto _group_by_impl(Check, Expressions... expressions) const -> inconsistent; template auto _group_by_impl(consistent_t, Expressions... expressions) const diff --git a/include/sqlpp11/having.h b/include/sqlpp11/having.h index 08905356..f8e0cfb7 100644 --- a/include/sqlpp11/having.h +++ b/include/sqlpp11/having.h @@ -272,7 +272,7 @@ namespace sqlpp private: template - auto _having_impl(Check, Expression expression) const -> Check; + auto _having_impl(Check, Expression expression) const -> inconsistent; template auto _having_impl(consistent_t, Expression expression) const diff --git a/include/sqlpp11/inconsistent.h b/include/sqlpp11/inconsistent.h index 326be226..0a46c929 100644 --- a/include/sqlpp11/inconsistent.h +++ b/include/sqlpp11/inconsistent.h @@ -27,22 +27,19 @@ #ifndef SQLPP_INCONSISTENT_H #define SQLPP_INCONSISTENT_H +#include + namespace sqlpp { +#if defined(__clang__) || defined(_MSC_VER) template - struct inconsistent - { - inconsistent(Check) - { - } - }; - - // This specialization circumvents an ambiguity problem with gcc + using inconsistent = Check; +#else + // This version circumvents an ambiguity problem with gcc // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77449 - template <> - struct inconsistent - { - }; + template + using inconsistent = typename std::enable_if::value, Check>::type; +#endif } #endif diff --git a/include/sqlpp11/insert_value_list.h b/include/sqlpp11/insert_value_list.h index 8eb718f6..2eed4b1b 100644 --- a/include/sqlpp11/insert_value_list.h +++ b/include/sqlpp11/insert_value_list.h @@ -526,7 +526,7 @@ namespace sqlpp private: template - auto _columns_impl(inconsistent, Columns... cols) const -> Check; + auto _columns_impl(Check, Columns... cols) const -> inconsistent; template auto _columns_impl(consistent_t, Columns... cols) const @@ -546,7 +546,7 @@ namespace sqlpp } template - auto _set_impl(inconsistent, Assignments... assignments) const -> Check; + auto _set_impl(Check, Assignments... assignments) const -> inconsistent; template auto _set_impl(consistent_t, Assignments... assignments) const diff --git a/include/sqlpp11/into.h b/include/sqlpp11/into.h index e0489443..4f6ea14b 100644 --- a/include/sqlpp11/into.h +++ b/include/sqlpp11/into.h @@ -176,7 +176,7 @@ namespace sqlpp private: template - auto _into_impl(Check, Table table) const -> Check; + auto _into_impl(Check, Table table) const -> inconsistent; template auto _into_impl(consistent_t, Table table) const -> _new_statement_t> diff --git a/include/sqlpp11/limit.h b/include/sqlpp11/limit.h index d2fcb4ae..294c2ed0 100644 --- a/include/sqlpp11/limit.h +++ b/include/sqlpp11/limit.h @@ -272,7 +272,7 @@ namespace sqlpp private: template - auto _limit_impl(Check, Arg arg) const -> Check; + auto _limit_impl(Check, Arg arg) const -> inconsistent; template auto _limit_impl(consistent_t, Arg arg) const -> _new_statement_t> diff --git a/include/sqlpp11/offset.h b/include/sqlpp11/offset.h index 8f1fd3e6..458b974a 100644 --- a/include/sqlpp11/offset.h +++ b/include/sqlpp11/offset.h @@ -288,7 +288,7 @@ namespace sqlpp private: template - auto _offset_impl(Check, Arg arg) const -> Check; + auto _offset_impl(Check, Arg arg) const -> inconsistent; template auto _offset_impl(consistent_t, Arg arg) const -> _new_statement_t> diff --git a/include/sqlpp11/order_by.h b/include/sqlpp11/order_by.h index d13eb7a9..16d564cd 100644 --- a/include/sqlpp11/order_by.h +++ b/include/sqlpp11/order_by.h @@ -233,7 +233,7 @@ namespace sqlpp private: template - auto _order_by_impl(inconsistent, Expressions... expressions) const -> Check; + auto _order_by_impl(Check, Expressions... expressions) const -> inconsistent; template auto _order_by_impl(consistent_t, Expressions... expressions) const diff --git a/include/sqlpp11/pre_join.h b/include/sqlpp11/pre_join.h index 86b84c92..7cd8a9dc 100644 --- a/include/sqlpp11/pre_join.h +++ b/include/sqlpp11/pre_join.h @@ -114,7 +114,7 @@ namespace sqlpp private: template - auto on_impl(Check, const Expr&) const -> Check; + auto on_impl(Check, const Expr&) const -> inconsistent; template auto on_impl(consistent_t, const Expr& expr) const -> join_t> @@ -146,7 +146,7 @@ namespace sqlpp namespace detail { template - auto join_impl(Check, Lhs lhs, Rhs rhs) -> Check; + auto join_impl(Check, Lhs lhs, Rhs rhs) -> inconsistent; template auto join_impl(consistent_t, Lhs lhs, Rhs rhs) -> pre_join_t; @@ -190,7 +190,7 @@ namespace sqlpp namespace detail { template - auto cross_join_impl(Check, Lhs lhs, Rhs rhs) -> Check; + auto cross_join_impl(Check, Lhs lhs, Rhs rhs) -> inconsistent; template auto cross_join_impl(consistent_t, Lhs lhs, Rhs rhs) diff --git a/include/sqlpp11/select_column_list.h b/include/sqlpp11/select_column_list.h index e6c3c3d2..8059eef6 100644 --- a/include/sqlpp11/select_column_list.h +++ b/include/sqlpp11/select_column_list.h @@ -409,7 +409,7 @@ namespace sqlpp private: template - auto _columns_impl(Check, std::tuple args) const -> Check; + auto _columns_impl(Check, std::tuple args) const -> inconsistent; template auto _columns_impl(consistent_t, std::tuple args) const diff --git a/include/sqlpp11/select_flag_list.h b/include/sqlpp11/select_flag_list.h index 7f593055..a1caa8df 100644 --- a/include/sqlpp11/select_flag_list.h +++ b/include/sqlpp11/select_flag_list.h @@ -223,7 +223,7 @@ namespace sqlpp private: template - auto _flags_impl(inconsistent, Flags... flgs) const -> Check; + auto _flags_impl(Check, Flags... flgs) const -> inconsistent; template auto _flags_impl(consistent_t, Flags... flgs) const diff --git a/include/sqlpp11/single_table.h b/include/sqlpp11/single_table.h index ee16289e..93881f88 100644 --- a/include/sqlpp11/single_table.h +++ b/include/sqlpp11/single_table.h @@ -176,7 +176,7 @@ namespace sqlpp private: template - auto _single_table_impl(Check, Table table) const -> Check; + auto _single_table_impl(Check, Table table) const -> inconsistent; template auto _single_table_impl(consistent_t, Table table) const diff --git a/include/sqlpp11/union.h b/include/sqlpp11/union.h index 2bac56c7..e113ea16 100644 --- a/include/sqlpp11/union.h +++ b/include/sqlpp11/union.h @@ -241,7 +241,7 @@ namespace sqlpp private: template - auto _union_impl(Check, Rhs rhs) const -> Check; + auto _union_impl(Check, Rhs rhs) const -> inconsistent; template auto _union_impl(consistent_t, Rhs rhs) const diff --git a/include/sqlpp11/update_list.h b/include/sqlpp11/update_list.h index c79c17d0..a95f434c 100644 --- a/include/sqlpp11/update_list.h +++ b/include/sqlpp11/update_list.h @@ -273,7 +273,7 @@ namespace sqlpp private: template - auto _set_impl(inconsistent, Assignments... assignments) const -> Check; + auto _set_impl(Check, Assignments... assignments) const -> inconsistent; template auto _set_impl(consistent_t, Assignments... assignments) const diff --git a/include/sqlpp11/using.h b/include/sqlpp11/using.h index 84fede64..6586f011 100644 --- a/include/sqlpp11/using.h +++ b/include/sqlpp11/using.h @@ -224,7 +224,7 @@ namespace sqlpp private: template - auto _using_impl(inconsistent, Tables... tables) const -> Check; + auto _using_impl(Check, Tables... tables) const -> inconsistent; template auto _using_impl(consistent_t, Tables... tables) const diff --git a/include/sqlpp11/where.h b/include/sqlpp11/where.h index 93b7e45a..c77af5d3 100644 --- a/include/sqlpp11/where.h +++ b/include/sqlpp11/where.h @@ -343,7 +343,7 @@ namespace sqlpp private: template - auto _where_impl(Check, Expression expression) const -> Check; + auto _where_impl(Check, Expression expression) const -> inconsistent; template auto _where_impl(consistent_t, Expression expression) const diff --git a/test_serializer/CustomQuery.cpp b/test_serializer/CustomQuery.cpp index 4f3f106a..67294930 100644 --- a/test_serializer/CustomQuery.cpp +++ b/test_serializer/CustomQuery.cpp @@ -29,7 +29,7 @@ #include -SQLPP_ALIAS_PROVIDER(pragma); +SQLPP_ALIAS_PROVIDER(pragma) int CustomQuery(int, char* []) { From 83d5147cd1191ef27859f90500e05361ded4ed29 Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 3 Sep 2016 12:35:40 +0200 Subject: [PATCH 10/11] Add begin/end to portable static assert to make error messages a bit shorter --- include/sqlpp11/portable_static_assert.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/sqlpp11/portable_static_assert.h b/include/sqlpp11/portable_static_assert.h index b0a8036c..c7cbdcfb 100644 --- a/include/sqlpp11/portable_static_assert.h +++ b/include/sqlpp11/portable_static_assert.h @@ -40,6 +40,8 @@ namespace sqlpp { \ static_assert(wrong_t::value, message); \ } \ + auto begin() const -> void; \ + auto end() const -> void; \ } namespace detail From b688f47d4236223ec72bdfc080a6acc79141b957 Mon Sep 17 00:00:00 2001 From: Roland Bock Date: Sat, 3 Sep 2016 13:12:44 +0200 Subject: [PATCH 11/11] Aded gitter link --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4d1c69c8..2abd4307 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,12 @@ A type safe embedded domain specific language for SQL queries and results in C++ Documentation is found in the [wiki](https://github.com/rbock/sqlpp11/wiki) +Contact: +-------- + * Meet me at [CppCon 2016](https://cppcon2016.sched.org/event/7nKk) + * Issues at https://github.com/rbock/sqlpp11/issues + * email at rbock at eudoxos dot de + * [![Join the chat at https://gitter.im/sqlpp11/Lobby](https://badges.gitter.im/sqlpp11/Lobby.svg)](https://gitter.im/sqlpp11/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) Breaking changes in 0.36: ------------------------- @@ -109,9 +115,7 @@ Past talks about sqlpp11 and some coding concepts used within the library: * [MUC++:](http://www.meetup.com/MUCplusplus/) * 2014-02-27: [Selected C++11 Template Toffees From sqlpp11, Part1](https://www.youtube.com/watch?v=hXnGFYNbmXg), [Part2](https://www.youtube.com/watch?v=WPCV6dvxZ_U), [Part 3](https://www.youtube.com/watch?v=eB7hd_KjTig), [Part 4](https://www.youtube.com/watch?v=NBfqzcN0_EQ) -You can contact me - * by posting issues at https://github.com/rbock/sqlpp11/issues - * or via email at rbock at eudoxos dot de + Requirements: