From 15247504f27530b0cef5e465aafcbe5059b8cf51 Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 26 Feb 2016 20:00:34 +0100 Subject: [PATCH] Disallow unconditional join (ifdef to get it back) One day, users of the library have to make the switch anyway, why not today? --- include/sqlpp11/from.h | 97 +++++++++++++++--------------------- test_static_asserts/case.cpp | 1 - 2 files changed, 39 insertions(+), 59 deletions(-) diff --git a/include/sqlpp11/from.h b/include/sqlpp11/from.h index 35c77eaa..8604e955 100644 --- a/include/sqlpp11/from.h +++ b/include/sqlpp11/from.h @@ -39,17 +39,11 @@ namespace sqlpp { -#ifdef SQLPP_ALLOW_UNCONDITIONAL_JOIN - constexpr bool allow_unconditional_from = 1; -#else - constexpr bool allow_unconditional_from = 0; -#endif - // FROM DATA - template + template struct from_data_t { - from_data_t(Tables... tables) : _tables(tables...) + from_data_t(Table table) : _table(table) { } @@ -59,20 +53,20 @@ namespace sqlpp from_data_t& operator=(from_data_t&&) = default; ~from_data_t() = default; - std::tuple _tables; + Table _table; interpretable_list_t _dynamic_tables; }; // FROM - template + template struct from_t { using _traits = make_traits; - using _nodes = detail::type_vector; + using _nodes = detail::type_vector; using _is_dynamic = is_database; // Data - using _data_t = from_data_t; + using _data_t = from_data_t; // Member implementation with data and methods template @@ -88,12 +82,8 @@ namespace sqlpp void add(DynamicJoin dynamicJoin) { static_assert(_is_dynamic::value, "from::add() must not be called for static from()"); - static_assert( - is_dynamic_join_t::value or (allow_unconditional_from and is_table_t::value), - "invalid argument in from::add(), or #define ALLOW_UNCONDITIONAL_JOIN " - "for a grace period of using tables here"); - using _known_tables = - detail::make_joined_set_t...>; // Hint: Joins contain more than one table + static_assert(is_dynamic_join_t::value, "invalid argument in from::add(), expected dynamic_join"); + using _known_tables = provided_tables_of
; // Hint: Joins contain more than one table // workaround for msvc bug https://connect.microsoft.com/VisualStudio/feedback/details/2173198 // using _known_table_names = detail::transform_set_t; using _known_table_names = detail::make_name_of_set_t<_known_tables>; @@ -127,7 +117,7 @@ namespace sqlpp template struct _base_t { - using _data_t = from_data_t; + using _data_t = from_data_t; // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 template @@ -222,44 +212,35 @@ namespace sqlpp using _consistency_check = consistent_t; - template - auto from(Table table, Tables... tables) const - -> _new_statement_t<_check, from_t, from_table_t...>> + template + auto from(Table table) const -> _new_statement_t<_check
, from_t>> { - static_assert(_check::value, "at least one argument is not a table or join in from()"); - static_assert(sizeof...(Tables) == 0 or ::sqlpp::allow_unconditional_from, - "unconditional join is deprecated, please use explicit joins or #define ALLOW_UNCONDITIONAL_JOIN " - "for a grace period"); - return _from_impl(_check{}, table, tables...); + static_assert(_check
::value, "argument is not a table or join in from()"); + return _from_impl(_check
{}, table); } - template - auto dynamic_from(Tables... tables) const - -> _new_statement_t<_check, from_t<_database_t, from_table_t...>> + template + auto dynamic_from(Table table) const -> _new_statement_t<_check
, from_t<_database_t, from_table_t
>> { static_assert(not std::is_same<_database_t, void>::value, "dynamic_from must not be called in a static statement"); - static_assert(_check::value, "at least one argument is not a table or join in from()"); - static_assert( - sizeof...(Tables) == 1 or ::sqlpp::allow_unconditional_from, - "unconditional join is deprecated, please use explicit joins or #define SQLPP_ALLOW_UNCONDITIONAL_JOIN " - "for a grace period"); - return _from_impl<_database_t>(_check{}, tables...); + static_assert(_check
::value, "argument is not a table or join in from()"); + return _from_impl<_database_t>(_check
{}, table); } private: - template - auto _from_impl(const std::false_type&, Tables... tables) const -> bad_statement; + template + auto _from_impl(const std::false_type&, Table table) const -> bad_statement; - template - auto _from_impl(const std::true_type&, Tables... tables) const - -> _new_statement_t...>> + template + auto _from_impl(const std::true_type&, Table table) const + -> _new_statement_t>> { - static_assert(required_tables_of>::size::value == 0, + static_assert(required_tables_of>::size::value == 0, "at least one table depends on another table in from()"); - static constexpr std::size_t _number_of_tables = detail::sum(provided_tables_of::size::value...); - using _unique_tables = detail::make_joined_set_t...>; + static constexpr std::size_t _number_of_tables = detail::sum(provided_tables_of
::size::value); + using _unique_tables = provided_tables_of
; using _unique_table_names = detail::make_name_of_set_t<_unique_tables>; static_assert(_number_of_tables == _unique_tables::size::value, "at least one duplicate table detected in from()"); @@ -267,35 +248,35 @@ namespace sqlpp "at least one duplicate table name detected in from()"); return {static_cast&>(*this), - from_data_t...>{from_table(tables)...}}; + from_data_t>{from_table(table)}}; } }; }; // Interpreters - template - struct serializer_t> + template + struct serializer_t> { - using _serialize_check = serialize_check_of; - using T = from_data_t; + using _serialize_check = serialize_check_of; + using T = from_data_t; static Context& _(const T& t, Context& context) { - if (sizeof...(Tables) == 0 and t._dynamic_tables.empty()) - return context; context << " FROM "; - interpret_tuple(t._tables, ',', context); - if (sizeof...(Tables) and not t._dynamic_tables.empty()) - context << ','; - interpret_list(t._dynamic_tables, ',', context); + serialize(t._table, context); + if (not t._dynamic_tables.empty()) + { + context << ' '; + interpret_list(t._dynamic_tables, ' ', context); + } return context; } }; - template - auto from(T&&... t) -> decltype(statement_t().from(std::forward(t)...)) + template + auto from(T&& t) -> decltype(statement_t().from(std::forward(t))) { - return statement_t().from(std::forward(t)...); + return statement_t().from(std::forward(t)); } } diff --git a/test_static_asserts/case.cpp b/test_static_asserts/case.cpp index 5b37e551..44506abb 100644 --- a/test_static_asserts/case.cpp +++ b/test_static_asserts/case.cpp @@ -31,7 +31,6 @@ namespace { constexpr auto t = test::TabBar{}; - constexpr auto f = test::TabFoo{}; template void print_type_on_error(std::true_type)