diff --git a/include/sqlpp11/extra_tables.h b/include/sqlpp11/extra_tables.h deleted file mode 100644 index 90332156..00000000 --- a/include/sqlpp11/extra_tables.h +++ /dev/null @@ -1,220 +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_EXTRA_TABLES_H -#define SQLPP_EXTRA_TABLES_H - -#include -#include -#include - -namespace sqlpp -{ - template - struct extra_tables_data_t - { - extra_tables_data_t() - { - } - - extra_tables_data_t(const extra_tables_data_t&) = default; - extra_tables_data_t(extra_tables_data_t&&) = default; - extra_tables_data_t& operator=(const extra_tables_data_t&) = default; - extra_tables_data_t& operator=(extra_tables_data_t&&) = default; - ~extra_tables_data_t() = default; - }; - - // EXTRA_TABLES - template - struct extra_tables_t - { - using _traits = make_traits; - using _nodes = detail::type_vector<>; - using _required_ctes = detail::make_joined_set_t...>; - using _extra_tables = detail::type_set; - - // Data - using _data_t = extra_tables_data_t; - - // Member implementation with data and methods - template - struct _impl_t - { - // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 - _impl_t() = default; - _impl_t(const _data_t& data) : _data(data) - { - } - - _data_t _data; - }; - - // Base template to be inherited by the statement - template - struct _base_t - { - using _data_t = extra_tables_data_t; - - // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 - template - _base_t(Args&&... args) - : extra_tables{std::forward(args)...} - { - } - - _impl_t extra_tables; - _impl_t& operator()() - { - return extra_tables; - } - const _impl_t& operator()() const - { - return extra_tables; - } - - template - static auto _get_member(T t) -> decltype(t.extra_tables) - { - return t.extra_tables; - } - - using _consistency_check = consistent_t; - }; - }; - - // NO EXTRA TABLES YET - struct no_extra_tables_t - { - using _traits = make_traits; - using _nodes = detail::type_vector<>; - - // Data - using _data_t = no_data_t; - - // Member implementation with data and methods - template - struct _impl_t - { - // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 - _impl_t() = default; - _impl_t(const _data_t& data) : _data(data) - { - } - - _data_t _data; - }; - - // Base template to be inherited by the statement - template - struct _base_t - { - using _data_t = no_data_t; - - // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 - template - _base_t(Args&&... args) - : no_extra_tables{std::forward(args)...} - { - } - - _impl_t no_extra_tables; - _impl_t& operator()() - { - return no_extra_tables; - } - const _impl_t& operator()() const - { - return no_extra_tables; - } - - template - static auto _get_member(T t) -> decltype(t.no_extra_tables) - { - return t.no_extra_tables; - } - - template - using _new_statement_t = new_statement_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...> - { - }; - - using _consistency_check = consistent_t; - - template - auto extra_tables(Tables... tables) const -> _new_statement_t<_check, extra_tables_t> - { - static_assert(_check::value, "at least one argument is not a table or join in extra_tables()"); - - return _extra_tables_impl(_check{}, tables...); - } - - private: - template - auto _extra_tables_impl(const std::false_type&, Tables... tables) const -> bad_statement; - - template - auto _extra_tables_impl(const std::true_type&, Tables...) const - -> _new_statement_t> - { - static_assert(required_tables_of>::size::value == 0, - "at least one table depends on another table in extra_tables()"); - - static constexpr std::size_t _number_of_tables = detail::sum(provided_tables_of::size::value...); - using _unique_tables = detail::make_joined_set_t...>; - // workaround for msvc bug https://connect.microsoft.com/VisualStudio/feedback/details/2173198 - // using _unique_table_names = detail::transform_set_t; - 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 extra_tables()"); - static_assert(_number_of_tables == _unique_table_names::size::value, - "at least one duplicate table name detected in extra_tables()"); - - return {static_cast&>(*this), extra_tables_data_t{}}; - } - }; - }; - - // Interpreters - template - struct serializer_t> - { - using _serialize_check = serialize_check_of; - using T = extra_tables_data_t; - - static Context& _(const T&, Context& context) - { - return context; - } - }; -} - -#endif diff --git a/include/sqlpp11/remove.h b/include/sqlpp11/remove.h index e53faeba..fe63205e 100644 --- a/include/sqlpp11/remove.h +++ b/include/sqlpp11/remove.h @@ -34,7 +34,6 @@ #include #include #include -#include #include #include @@ -103,7 +102,7 @@ namespace sqlpp }; template - using blank_remove_t = statement_t>; + using blank_remove_t = statement_t>; inline auto remove() -> blank_remove_t { diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 16be853e..824645c4 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -77,7 +76,6 @@ namespace sqlpp no_select_flag_list_t, no_select_column_list_t, no_from_t, - no_extra_tables_t, no_where_t, no_group_by_t, no_having_t, diff --git a/include/sqlpp11/statement.h b/include/sqlpp11/statement.h index 846aefde..f338222b 100644 --- a/include/sqlpp11/statement.h +++ b/include/sqlpp11/statement.h @@ -76,13 +76,10 @@ namespace sqlpp using _all_required_tables = detail::make_joined_set_t...>; using _all_provided_tables = detail::make_joined_set_t...>; using _all_provided_outer_tables = detail::make_joined_set_t...>; - using _all_extra_tables = detail::make_joined_set_t...>; using _all_provided_aggregates = detail::make_joined_set_t...>; - using _known_tables = detail::make_joined_set_t<_all_provided_tables, _all_extra_tables>; - template - using _no_unknown_tables = detail::is_subset_of, _known_tables>; + using _no_unknown_tables = detail::is_subset_of, _all_provided_tables>; // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2086629 // template @@ -100,11 +97,7 @@ namespace sqlpp using any_t = logic::any_t::value...>; // The tables not covered by the from. - using _required_tables = - detail::make_difference_set_t<_all_required_tables, - _all_provided_tables // Hint: extra_tables are not used here because they are - // just a helper for dynamic .add_*() - >; + using _required_tables = detail::make_difference_set_t<_all_required_tables, _all_provided_tables>; // The common table expressions not covered by the with. using _required_ctes = detail::make_difference_set_t<_all_required_ctes, _all_provided_ctes>; diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index f97a05d2..d8f3fd9e 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -181,7 +181,6 @@ namespace sqlpp SQLPP_VALUE_TRAIT_GENERATOR(is_from) SQLPP_VALUE_TRAIT_GENERATOR(is_single_table) SQLPP_VALUE_TRAIT_GENERATOR(is_into) - SQLPP_VALUE_TRAIT_GENERATOR(is_extra_tables) SQLPP_VALUE_TRAIT_GENERATOR(is_on) SQLPP_VALUE_TRAIT_GENERATOR(is_where) SQLPP_VALUE_TRAIT_GENERATOR(is_group_by) @@ -259,7 +258,6 @@ namespace sqlpp SQLPP_RECURSIVE_TRAIT_SET_GENERATOR(required_tables) SQLPP_RECURSIVE_TRAIT_SET_GENERATOR(provided_tables) SQLPP_RECURSIVE_TRAIT_SET_GENERATOR(provided_outer_tables) - SQLPP_RECURSIVE_TRAIT_SET_GENERATOR(extra_tables) SQLPP_RECURSIVE_TRAIT_SET_GENERATOR(provided_aggregates) #define SQLPP_RECURSIVE_TRAIT_GENERATOR(trait) \ diff --git a/include/sqlpp11/without_table_check.h b/include/sqlpp11/without_table_check.h index 37bc26c9..82051860 100644 --- a/include/sqlpp11/without_table_check.h +++ b/include/sqlpp11/without_table_check.h @@ -33,23 +33,13 @@ namespace sqlpp { template - struct without_table_check_t + struct without_table_check_t : Expression { - using _traits = typename Expression::_traits; - using _nodes = detail::type_vector; using _required_tables = detail::type_set<>; - without_table_check_t(Expression expression) : _expression(expression) + without_table_check_t(Expression expression) : Expression(expression) { } - - without_table_check_t(const without_table_check_t&) = default; - without_table_check_t(without_table_check_t&&) = default; - without_table_check_t& operator=(const without_table_check_t&) = default; - without_table_check_t& operator=(without_table_check_t&&) = default; - ~without_table_check_t() = default; - - Expression _expression; }; template @@ -60,7 +50,7 @@ namespace sqlpp static Context& _(const T& t, Context& context) { - serialize(t._expression, context); + serialize(t, context); return context; } }; diff --git a/tests/Interpret.cpp b/tests/Interpret.cpp index 24841870..8e671948 100644 --- a/tests/Interpret.cpp +++ b/tests/Interpret.cpp @@ -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, @@ -163,13 +163,11 @@ int Interpret(int, char* []) serialize(s, printer).str(); } { - auto s = dynamic_select(db) - .dynamic_flags(sqlpp::distinct) - .dynamic_columns(t.alpha) - .extra_tables(t); // Would fail to run() + // Behold, dynamically constructed queries might compile but be illegal SQL + auto s = dynamic_select(db).dynamic_flags(sqlpp::distinct).dynamic_columns(t.alpha); s.select_flags.add(sqlpp::all); - s.selected_columns.add(t.beta); - s.selected_columns.add(t.gamma); + s.selected_columns.add(without_table_check(t.beta)); + s.selected_columns.add(without_table_check(t.gamma)); serialize(s, printer).str(); } diff --git a/tests/Select.cpp b/tests/Select.cpp index 43be425c..1b4a8b58 100644 --- a/tests/Select.cpp +++ b/tests/Select.cpp @@ -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, @@ -31,6 +31,7 @@ #include #include #include +#include template int64_t getColumn(Db&& db, const Column& column) @@ -108,7 +109,6 @@ int Select(int, char* []) .columns(all_of(t)) .flags(sqlpp::all) .from(t) - .extra_tables(f, t) .where(t.alpha > 0) .group_by(t.alpha) .order_by(t.gamma.asc()) @@ -122,7 +122,6 @@ int Select(int, char* []) .columns(all_of(t)) .flags(sqlpp::all) .from(t) - .extra_tables(f, t) .where(t.alpha > 0) .group_by(t.alpha) .order_by(t.gamma.asc()) @@ -137,7 +136,6 @@ int Select(int, char* []) .dynamic_columns(all_of(t)) .dynamic_flags() .dynamic_from(t) - .extra_tables(f, t) .dynamic_where() .dynamic_group_by(t.alpha) .dynamic_order_by() @@ -145,7 +143,7 @@ int Select(int, char* []) .dynamic_limit() .dynamic_offset(); s.select_flags.add(sqlpp::distinct); - s.selected_columns.add(f.omega); + s.selected_columns.add(without_table_check(f.omega)); s.from.add(dynamic_cross_join(f)); s.where.add(t.alpha > 7); s.having.add(t.alpha > 7); diff --git a/tests/SelectType.cpp b/tests/SelectType.cpp index cb710b89..c1ecb262 100644 --- a/tests/SelectType.cpp +++ b/tests/SelectType.cpp @@ -340,8 +340,8 @@ int SelectType(int, char* []) // Test that select can be called with zero columns if it is used with dynamic columns. { - auto s = dynamic_select(db).dynamic_columns().extra_tables(t); - s.selected_columns.add(t.alpha); + auto s = dynamic_select(db).dynamic_columns(); + s.selected_columns.add(without_table_check(t.alpha)); serialize(s, printer).str(); }