From c347b5d11c71f762c5bc32d844f482d0c2a50a10 Mon Sep 17 00:00:00 2001 From: Roland Bock Date: Sat, 8 Jun 2024 11:35:54 +0200 Subject: [PATCH] Remove dynamic query components --- include/sqlpp11/boolean_expression.h | 74 -------- include/sqlpp11/cte.h | 4 - include/sqlpp11/custom_query.h | 9 - include/sqlpp11/dynamic_join.h | 57 ------ include/sqlpp11/dynamic_pre_join.h | 163 ------------------ include/sqlpp11/dynamic_select_column_list.h | 102 ----------- include/sqlpp11/from.h | 82 --------- include/sqlpp11/group_by.h | 53 +----- include/sqlpp11/having.h | 59 ------- include/sqlpp11/insert.h | 14 -- include/sqlpp11/insert_value_list.h | 44 +---- include/sqlpp11/interpretable.h | 101 ----------- include/sqlpp11/interpretable_list.h | 93 ---------- include/sqlpp11/limit.h | 111 ------------ include/sqlpp11/named_interpretable.h | 112 ------------ include/sqlpp11/offset.h | 125 -------------- include/sqlpp11/on.h | 1 - include/sqlpp11/order_by.h | 51 ------ .../postgresql/on_conflict_do_update.h | 2 - .../postgresql/returning_column_list.h | 135 +-------------- include/sqlpp11/prepared_select.h | 4 +- include/sqlpp11/remove.h | 13 -- include/sqlpp11/result.h | 5 +- include/sqlpp11/result_row.h | 107 ------------ include/sqlpp11/select.h | 14 -- include/sqlpp11/select_column_list.h | 79 +-------- include/sqlpp11/select_flag_list.h | 46 ----- include/sqlpp11/sqlpp11.h | 1 - include/sqlpp11/union.h | 1 - include/sqlpp11/update.h | 7 - include/sqlpp11/update_list.h | 57 +----- include/sqlpp11/using.h | 43 ----- include/sqlpp11/where.h | 80 --------- include/sqlpp11/with.h | 3 - tests/core/serialize/CMakeLists.txt | 2 + tests/core/serialize/CustomQuery.cpp | 11 +- tests/core/serialize/DynamicWhere.cpp | 17 +- tests/core/serialize/From.cpp | 56 +----- tests/core/serialize/SelectColumns.cpp | 59 +++++++ .../SelectFlags.cpp} | 29 ++-- tests/core/static_asserts/from.cpp | 87 +--------- tests/core/static_asserts/having.cpp | 58 +------ tests/core/static_asserts/insert.cpp | 68 +------- tests/core/static_asserts/join.cpp | 99 +---------- tests/core/static_asserts/update_list.cpp | 50 +----- tests/core/static_asserts/where.cpp | 59 +------ tests/core/usage/CMakeLists.txt | 1 - tests/core/usage/Insert.cpp | 10 +- tests/core/usage/Interpret.cpp | 30 ---- tests/core/usage/Remove.cpp | 13 +- tests/core/usage/Select.cpp | 46 ++--- tests/core/usage/SelectType.cpp | 3 + tests/core/usage/Update.cpp | 15 +- 53 files changed, 137 insertions(+), 2428 deletions(-) delete mode 100644 include/sqlpp11/boolean_expression.h delete mode 100644 include/sqlpp11/dynamic_join.h delete mode 100644 include/sqlpp11/dynamic_pre_join.h delete mode 100644 include/sqlpp11/dynamic_select_column_list.h delete mode 100644 include/sqlpp11/interpretable.h delete mode 100644 include/sqlpp11/interpretable_list.h delete mode 100644 include/sqlpp11/named_interpretable.h create mode 100644 tests/core/serialize/SelectColumns.cpp rename tests/core/{usage/BooleanExpression.cpp => serialize/SelectFlags.cpp} (71%) diff --git a/include/sqlpp11/boolean_expression.h b/include/sqlpp11/boolean_expression.h deleted file mode 100644 index f8f4de99..00000000 --- a/include/sqlpp11/boolean_expression.h +++ /dev/null @@ -1,74 +0,0 @@ -#pragma once - -/* - * 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. - */ - -#include -#include - -namespace sqlpp -{ - template - struct boolean_expression_t : public expression_operators, boolean> - { - using _traits = make_traits; - using _nodes = detail::type_vector<>; - - template - boolean_expression_t(Expr expr) : _expr(expr) - { - static_assert(is_expression_t::value, "boolean_expression requires a boolean expression argument"); - static_assert(is_boolean_t::value, "boolean_expression requires a boolean expression argument"); - } - - boolean_expression_t(const boolean_expression_t&) = default; - boolean_expression_t(boolean_expression_t&&) = default; - boolean_expression_t& operator=(const boolean_expression_t&) = default; - boolean_expression_t& operator=(boolean_expression_t&&) = default; - ~boolean_expression_t() = default; - - interpretable_t _expr; - }; - - template - boolean_expression_t boolean_expression(T t) - { - using Expr = wrap_operand_t; - return {Expr{t}}; - } - - template - boolean_expression_t boolean_expression(const Database& /*unused*/, T t) - { - return boolean_expression(t); - } - - template - Context& serialize(const boolean_expression_t& t, Context& context) - { - return serialize(t._expr, context); - } -} // namespace sqlpp diff --git a/include/sqlpp11/cte.h b/include/sqlpp11/cte.h index e151e8ed..0af0f86a 100644 --- a/include/sqlpp11/cte.h +++ b/include/sqlpp11/cte.h @@ -28,7 +28,6 @@ #include #include -#include #include #include #include @@ -234,7 +233,6 @@ namespace sqlpp // The cte_t is displayed as AliasProviderName except within the with: // - the with needs the // AliasProviderName AS (ColumnNames) (select/union) - // The result row of the select should not have dynamic parts template struct cte_ref_t { @@ -253,8 +251,6 @@ namespace sqlpp static_assert(not required_ctes_of::template count(), "common table expression must not self-reference in the first part, use union_all/union_distinct " "for recursion"); - static_assert(is_static_result_row_t>::value, - "ctes must not have dynamically added columns"); return {statement}; } diff --git a/include/sqlpp11/custom_query.h b/include/sqlpp11/custom_query.h index 419c7e80..f935c461 100644 --- a/include/sqlpp11/custom_query.h +++ b/include/sqlpp11/custom_query.h @@ -135,13 +135,4 @@ namespace sqlpp return custom_query_t...>(parts...); } - template - auto dynamic_custom_query(const Database& /*unused*/, Parts... parts) - -> custom_query_t...> - { - static_assert(sizeof...(Parts) > 0, "custom query requires at least one query argument"); - static_assert(std::is_base_of::value, "Invalid database parameter"); - - return custom_query_t...>(parts...); - } } // namespace sqlpp diff --git a/include/sqlpp11/dynamic_join.h b/include/sqlpp11/dynamic_join.h deleted file mode 100644 index a868b5c1..00000000 --- a/include/sqlpp11/dynamic_join.h +++ /dev/null @@ -1,57 +0,0 @@ -#pragma once - -/* - * 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. - */ - -#include - -namespace sqlpp -{ - template - struct dynamic_join_t - { - using _traits = make_traits; - using _nodes = detail::type_vector; - using _can_be_null = std::false_type; - using _provided_tables = provided_tables_of; - using _required_tables = detail::make_difference_set_t, _provided_tables>; - - static_assert(is_dynamic_pre_join_t::value, "lhs argument for on() has to be a pre join"); - static_assert(required_tables_of::size::value == 0, "joined tables must not depend on other tables"); - static_assert(is_on_t::value, "invalid on expression in join().on()"); - - PreJoin _pre_join; - On _on; - }; - - template - Context& serialize(const dynamic_join_t& t, Context& context) - { - serialize(t._pre_join, context); - serialize(t._on, context); - return context; - } -} // namespace sqlpp diff --git a/include/sqlpp11/dynamic_pre_join.h b/include/sqlpp11/dynamic_pre_join.h deleted file mode 100644 index 50f61381..00000000 --- a/include/sqlpp11/dynamic_pre_join.h +++ /dev/null @@ -1,163 +0,0 @@ -#pragma once - -/* - * 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. - */ - -#include -#include - -namespace sqlpp -{ - SQLPP_PORTABLE_STATIC_ASSERT(assert_dynamic_pre_join_table_t, "argument of dynamic_join() has to be a table"); - SQLPP_PORTABLE_STATIC_ASSERT(assert_dynamic_pre_join_no_join_t, "argument of dynamic_join() must not be a table"); - - template - struct check_dynamic_pre_join - { - using type = - static_combined_check_t::value, assert_dynamic_pre_join_table_t>, - static_check_t::value, assert_dynamic_pre_join_no_join_t>>; - }; - - template - using check_dynamic_pre_join_t = typename check_dynamic_pre_join::type; - - SQLPP_PORTABLE_STATIC_ASSERT(assert_dynamic_join_consist_of_pre_join_and_on_t, - "dynamic join has to consist of a dynamic pre_join and a join condition"); - SQLPP_PORTABLE_STATIC_ASSERT(assert_dynamic_join_no_table_dependencies_t, - "dynamically joined tables must not depend on other tables"); - - template - struct check_dynamic_join - { - using type = static_combined_check_t< - static_check_t::value, assert_dynamic_join_consist_of_pre_join_and_on_t>, - static_check_t::value, assert_dynamic_join_consist_of_pre_join_and_on_t>, - static_check_t::size::value == 0, assert_dynamic_join_no_table_dependencies_t>>; - }; - - template - using check_dynamic_join_t = typename check_dynamic_join::type; - - template - struct check_dynamic_join_on - { - using type = static_combined_check_t, check_dynamic_join_t>>; - }; - - template - using check_dynamic_join_on_t = typename check_dynamic_join_on::type; - - template - struct dynamic_join_t; - - template - struct dynamic_pre_join_t - { - using _traits = make_traits; - using _nodes = detail::type_vector; - using _can_be_null = std::false_type; - - static_assert(is_table_t::value, "rhs argument for dynamic_join() has to be a table"); - static_assert(not is_join_t::value, "rhs argument for dynamic_join must not be a join"); - - static_assert(required_tables_of::size::value == 0, - "joined tables must not depend on other tables"); - - auto unconditionally() const -> dynamic_join_t> - { - return {*this, {}}; - } - - template - auto on(Expr expr) const -> typename std::conditional::value, - dynamic_join_t>, - check_dynamic_join_on_t>::type - { - return {*this, {expr}}; - } - - Rhs _rhs; - }; - - template - Context& serialize(const dynamic_pre_join_t& t, Context& context) - { - context << JoinType::_name; - context << " JOIN "; - serialize(t._rhs, context); - return context; - } - - template - using make_dynamic_pre_join_t = typename std::conditional::value, - dynamic_pre_join_t, - check_dynamic_pre_join_t
>::type; - - template - auto dynamic_join(Table table) -> make_dynamic_pre_join_t - { - check_dynamic_pre_join_t
::verify(); // FIXME: Failure return type? - return {table}; - } - - template - auto dynamic_inner_join(Table table) -> make_dynamic_pre_join_t - { - check_dynamic_pre_join_t
::verify(); - return {table}; - } - - template - auto dynamic_left_outer_join(Table table) -> make_dynamic_pre_join_t - { - check_dynamic_pre_join_t
::verify(); - return {table}; - } - - template - auto dynamic_right_outer_join(Table table) -> make_dynamic_pre_join_t - { - check_dynamic_pre_join_t
::verify(); - return {table}; - } - - template - auto dynamic_outer_join(Table table) -> make_dynamic_pre_join_t - { - check_dynamic_pre_join_t
::verify(); - return {table}; - } - - template - auto dynamic_cross_join(Table table) -> - typename std::conditional::value, - dynamic_join_t, on_t>, - check_dynamic_pre_join_t
>::type - { - return {dynamic_pre_join_t{table}, {}}; - } -} // namespace sqlpp diff --git a/include/sqlpp11/dynamic_select_column_list.h b/include/sqlpp11/dynamic_select_column_list.h deleted file mode 100644 index 2ec44d06..00000000 --- a/include/sqlpp11/dynamic_select_column_list.h +++ /dev/null @@ -1,102 +0,0 @@ -#pragma once - -/* - * Copyright (c) 2013-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. - */ - -#include -#include -#include -#include - -namespace sqlpp -{ - template - struct dynamic_select_column_list - { - using _names_t = std::vector; - std::vector> _dynamic_columns; - _names_t _dynamic_expression_names; - - template - void emplace_back(Expr expr) - { - _dynamic_expression_names.push_back(name_of::template char_ptr()); - _dynamic_columns.emplace_back(expr); - } - - bool empty() const - { - return _dynamic_columns.empty(); - } - - auto size() -> size_t - { - return _dynamic_columns.size(); - } - }; - - template <> - struct dynamic_select_column_list - { - using _names_t = no_name_t; - _names_t _dynamic_expression_names; - - static constexpr bool empty() - { - return true; - } - - static constexpr auto size() -> size_t - { - return {}; - } - }; - - template - Context& serialize(const dynamic_select_column_list& t, Context& context) - { - bool first = true; - for (const auto& column : t._dynamic_columns) - { - if (first) - { - first = false; - } - else - { - context << ','; - } - serialize(column, context); - } - return context; - } - - template - Context& serialize(const dynamic_select_column_list&, Context& context) - { - return context; - } -} // namespace sqlpp diff --git a/include/sqlpp11/from.h b/include/sqlpp11/from.h index 374f3bc8..ccef5d95 100644 --- a/include/sqlpp11/from.h +++ b/include/sqlpp11/from.h @@ -26,9 +26,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include -#include #include #include #include @@ -52,43 +50,8 @@ namespace sqlpp ~from_data_t() = default; Table _table; - interpretable_list_t _dynamic_tables; }; - SQLPP_PORTABLE_STATIC_ASSERT(assert_from_add_dynamic, "from::add() requires a dynamic_from"); - SQLPP_PORTABLE_STATIC_ASSERT(assert_from_add_not_dynamic_pre_join, "join condition missing"); - SQLPP_PORTABLE_STATIC_ASSERT(assert_from_add_dynamic_join, "from::add(X) requires X to be a dynamic join"); - SQLPP_PORTABLE_STATIC_ASSERT(assert_from_add_unique_names, - "from::add() must not add table names already used in from"); - SQLPP_PORTABLE_STATIC_ASSERT(assert_from_add_no_required_tables, - "from::add():dynamic join condition depends on " - "tables not statically known, use " - "without_table_check() to express the intent"); - - template - struct check_from_add - { - 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>; - using _joined_tables = provided_tables_of; - using _joined_table_names = detail::make_name_of_set_t<_joined_tables>; - using _required_tables = required_tables_of; - using type = static_combined_check_t< - static_check_t, - static_check_t::value, assert_from_add_not_dynamic_pre_join>, - static_check_t::value, assert_from_add_dynamic_join>, - static_check_t::value, - assert_from_add_unique_names>, - static_check_t::value, - assert_from_add_no_required_tables> - >; - }; - - template - using check_from_add_t = typename check_from_add::type; - // FROM template struct from_t @@ -104,7 +67,6 @@ namespace sqlpp struct _impl_t { using _database_t = Database; - using _is_dynamic = is_database<_database_t>; using _table_t = Table; // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 @@ -113,24 +75,6 @@ namespace sqlpp { } - template - 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>; - return _add_impl(dynamicJoin, Check{}); - } - - private: - template - auto _add_impl(DynamicJoin dynamicJoin, consistent_t /*unused*/) -> void - { - _data._dynamic_tables.emplace_back(from_table(dynamicJoin)); - } - - template - auto _add_impl(DynamicJoin dynamicJoin, Check) -> inconsistent; - public: _data_t _data; }; @@ -175,9 +119,6 @@ namespace sqlpp SQLPP_PORTABLE_STATIC_ASSERT(assert_from_dependency_free_t, "at least one table depends on another table in from()"); SQLPP_PORTABLE_STATIC_ASSERT(assert_from_no_duplicates_t, "at least one duplicate table name detected in from()"); - SQLPP_PORTABLE_STATIC_ASSERT(assert_from_dynamic_statement_dynamic_t, - "dynamic_from must not be called in a static statement"); - template struct check_from { @@ -196,11 +137,6 @@ namespace sqlpp template using check_from_static_t = check_from_t
; - template - using check_from_dynamic_t = static_combined_check_t< - static_check_t::value, assert_from_dynamic_statement_dynamic_t>, - check_from_t
>; - struct no_from_t { using _traits = make_traits; @@ -264,14 +200,6 @@ namespace sqlpp return _from_impl(Check{}, table); } - template - auto dynamic_from(Table table) const - -> _new_statement_t, from_t<_database_t, from_table_t
>> - { - using Check = check_from_dynamic_t<_database_t, Table>; - return _from_impl<_database_t>(Check{}, table); - } - private: template auto _from_impl(Check, Table table) const -> inconsistent; @@ -292,10 +220,6 @@ namespace sqlpp { context << " FROM "; serialize(t._table, context); - if (not t._dynamic_tables.empty()) - { - interpret_list(t._dynamic_tables, "", context); - } return context; } @@ -305,10 +229,4 @@ namespace sqlpp return statement_t().from(std::forward(t)); } - template - auto dynamic_from(const Database& /*unused*/, T&& t) - -> decltype(statement_t().dynamic_from(std::forward(t))) - { - return statement_t().dynamic_from(std::forward(t)); - } } // namespace sqlpp diff --git a/include/sqlpp11/group_by.h b/include/sqlpp11/group_by.h index 7f434183..b4f60625 100644 --- a/include/sqlpp11/group_by.h +++ b/include/sqlpp11/group_by.h @@ -28,7 +28,6 @@ #include #include -#include #include #include #include @@ -51,7 +50,6 @@ namespace sqlpp ~group_by_data_t() = default; std::tuple _expressions; - interpretable_list_t _dynamic_expressions; }; SQLPP_PORTABLE_STATIC_ASSERT( @@ -65,9 +63,7 @@ namespace sqlpp using _traits = make_traits; 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 = detail::make_type_set_t; // Data using _data_t = group_by_data_t; @@ -82,28 +78,6 @@ namespace sqlpp { } - template - void add(Expression expression) - { - static_assert(_is_dynamic::value, "add() must not be called for static group_by"); - static_assert(is_expression_t::value, "invalid expression argument in group_by::add()"); - static_assert(Policies::template _no_unknown_tables::value, - "expression uses tables unknown to this statement in group_by::add()"); - using ok = logic::all_t<_is_dynamic::value, is_expression_t::value>; - - _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert - } - - private: - template - void _add_impl(Expression expression, const std::true_type& /*unused*/) - { - _data._dynamic_expressions.emplace_back(expression); - } - - template - void _add_impl(Expression expression, const std::false_type&); - public: _data_t _data; }; @@ -219,16 +193,6 @@ namespace sqlpp return _group_by_impl(check_group_by_t{}, expressions...); } - template - auto dynamic_group_by(Expressions... expressions) const - -> _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"); - - return _group_by_impl<_database_t>(check_group_by_t{}, expressions...); - } - private: template auto _group_by_impl(Check, Expressions... expressions) const -> inconsistent; @@ -250,17 +214,8 @@ namespace sqlpp template Context& serialize(const group_by_data_t& t, Context& context) { - if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty()) - { - return context; - } context << " GROUP BY "; interpret_tuple(t._expressions, ',', context); - if (sizeof...(Expressions) and not t._dynamic_expressions.empty()) - { - context << ','; - } - interpret_list(t._dynamic_expressions, ',', context); return context; } @@ -270,10 +225,4 @@ namespace sqlpp return statement_t().group_by(std::forward(t)...); } - template - auto dynamic_group_by(const Database& /*unused*/, T&&... t) - -> decltype(statement_t().dynamic_group_by(std::forward(t)...)) - { - return statement_t().dynamic_group_by(std::forward(t)...); - } } // namespace sqlpp diff --git a/include/sqlpp11/having.h b/include/sqlpp11/having.h index bb9aea6f..dc17e5ea 100644 --- a/include/sqlpp11/having.h +++ b/include/sqlpp11/having.h @@ -28,7 +28,6 @@ #include #include -#include #include #include #include @@ -51,7 +50,6 @@ namespace sqlpp ~having_data_t() = default; Expression _expression; - interpretable_list_t _dynamic_expressions; }; SQLPP_PORTABLE_STATIC_ASSERT( @@ -68,8 +66,6 @@ namespace sqlpp using _traits = make_traits; using _nodes = detail::type_vector; - using _is_dynamic = is_database; - // Data using _data_t = having_data_t; @@ -83,28 +79,6 @@ namespace sqlpp { } - template - void add(Expr expression) - { - static_assert(_is_dynamic::value, "having::add() can only be called for dynamic_having"); - static_assert(is_expression_t::value, "invalid expression argument in having::add()"); - static_assert(Policies::template _no_unknown_tables::value, - "expression uses tables unknown to this statement in having::add()"); - using ok = logic::all_t<_is_dynamic::value, is_expression_t::value>; - - _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert - } - - private: - template - void _add_impl(Expr expression, const std::true_type& /*unused*/) - { - _data._dynamic_expressions.emplace_back(expression); - } - - template - void _add_impl(Expr expression, const std::false_type&); - public: _data_t _data; }; @@ -154,8 +128,6 @@ namespace sqlpp "sqlpp::value(bool_expresson) if you really want to use a bool value here"); SQLPP_PORTABLE_STATIC_ASSERT(assert_having_boolean_expression_t, "having() argument has to be an sqlpp boolean expression."); - SQLPP_PORTABLE_STATIC_ASSERT(assert_having_dynamic_statement_dynamic_t, - "dynamic_having() must not be called in a static statement"); template struct check_having @@ -172,11 +144,6 @@ namespace sqlpp template using check_having_static_t = check_having_t; - template - using check_having_dynamic_t = static_combined_check_t< - static_check_t::value, assert_having_dynamic_statement_dynamic_t>, - check_having_t>; - template constexpr auto are_all_parameters_expressions() -> bool { @@ -257,21 +224,6 @@ namespace sqlpp return _having_impl(Check{}, expression); } - template - auto dynamic_having(Expression expression) const - -> _new_statement_t, having_t<_database_t, Expression>> - { - using Check = check_having_dynamic_t<_database_t, Expression>; - - return _having_impl<_database_t>(Check{}, expression); - } - - auto dynamic_having() const -> _new_statement_t, - having_t<_database_t, boolean_operand>> - { - return dynamic_having(::sqlpp::value(true)); - } - private: template auto _having_impl(Check, Expression expression) const -> inconsistent; @@ -292,11 +244,6 @@ namespace sqlpp { context << " HAVING "; serialize(t._expression, context); - if (not t._dynamic_expressions.empty()) - { - context << " AND "; - } - interpret_list(t._dynamic_expressions, " AND ", context); return context; } @@ -306,10 +253,4 @@ namespace sqlpp return statement_t().having(std::forward(t)); } - template - auto dynamic_having(const Database& /*unused*/, T&& t) - -> decltype(statement_t().dynamic_having(std::forward(t))) - { - return statement_t().dynamic_having(std::forward(t)); - } } // namespace sqlpp diff --git a/include/sqlpp11/insert.h b/include/sqlpp11/insert.h index 39e2b1d8..a9066c70 100644 --- a/include/sqlpp11/insert.h +++ b/include/sqlpp11/insert.h @@ -109,18 +109,4 @@ namespace sqlpp return {blank_insert_t().into(table)}; } - template - constexpr auto dynamic_insert(const Database & /*unused*/) -> decltype(blank_insert_t()) - { - static_assert(std::is_base_of::value, "Invalid database parameter"); - return {blank_insert_t()}; - } - - template - constexpr auto dynamic_insert_into(const Database& /*unused*/, Table table) - -> decltype(blank_insert_t().into(table)) - { - static_assert(std::is_base_of::value, "Invalid database parameter"); - return {blank_insert_t().into(table)}; - } } // namespace sqlpp diff --git a/include/sqlpp11/insert_value_list.h b/include/sqlpp11/insert_value_list.h index d6361c07..4c1a62a5 100644 --- a/include/sqlpp11/insert_value_list.h +++ b/include/sqlpp11/insert_value_list.h @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -137,8 +136,6 @@ namespace sqlpp // (connector-container requires assignments) std::tuple>...> _columns; std::tuple...> _values; - interpretable_list_t _dynamic_columns; - interpretable_list_t _dynamic_values; private: template @@ -636,34 +633,14 @@ namespace sqlpp template Context& serialize(const insert_list_data_t& t, Context& context) { - if (sizeof...(Assignments) + t._dynamic_columns.size() == 0) - { - serialize(insert_default_values_data_t(), context); - } - else - { - context << " ("; - interpret_tuple(t._columns, ",", context); - if (sizeof...(Assignments) and not t._dynamic_columns.empty()) - { - context << ','; - } - interpret_list(t._dynamic_columns, ',', context); - context << ")"; - if (sizeof...(Assignments) or not t._dynamic_values.empty()) - { - context << " VALUES("; - interpret_tuple(t._values, ",", context); - if (sizeof...(Assignments) and not t._dynamic_values.empty()) - { - context << ','; - } - interpret_list(t._dynamic_values, ',', context); - context << ")"; - } - } + context << " ("; + interpret_tuple(t._columns, ",", context); + context << ")"; + context << " VALUES("; + interpret_tuple(t._values, ",", context); + context << ")"; return context; - } + } template auto insert_set(Assignments... assignments) @@ -672,13 +649,6 @@ namespace sqlpp return statement_t().set(assignments...); } - template - auto dynamic_insert_set(Assignments... assignments) - -> decltype(statement_t().dynamic_set(assignments...)) - { - return statement_t().dynamic_set(assignments...); - } - template auto insert_columns(Columns... cols) -> decltype(statement_t().columns(cols...)) diff --git a/include/sqlpp11/interpretable.h b/include/sqlpp11/interpretable.h deleted file mode 100644 index 030fb964..00000000 --- a/include/sqlpp11/interpretable.h +++ /dev/null @@ -1,101 +0,0 @@ -#pragma once - -/* - * 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. - */ - -#include -#include -#include - -namespace sqlpp -{ - template - struct interpretable_t - { - using _serializer_context_t = typename Db::_serializer_context_t; - - template - interpretable_t(T t) : _requires_parens(requires_parens_t::value), _impl(std::make_shared<_impl_t>(t)) - { - } - - interpretable_t(const interpretable_t&) = default; - interpretable_t(interpretable_t&&) = default; - interpretable_t& operator=(const interpretable_t&) = default; - interpretable_t& operator=(interpretable_t&&) = default; - ~interpretable_t() = default; - - _serializer_context_t& interpret(_serializer_context_t& context) const - { - return _impl->interpret(context); - } - - bool _requires_parens; - - private: - struct _impl_base - { - virtual ~_impl_base() = default; - virtual _serializer_context_t& interpret(_serializer_context_t& context) const = 0; - }; - - template - struct _impl_t : public _impl_base - { - static_assert(not make_parameter_list_t::size::value, "parameters not supported in dynamic statement parts"); - _impl_t(T t) : _t(t) - { - } - - _serializer_context_t& interpret(_serializer_context_t& context) const - { - serialize(_t, context); - return context; - } - - T _t; - }; - - std::shared_ptr _impl; - }; - - template - Context& serialize(const interpretable_t& t, Context& context) - { - if (t._requires_parens) - { - context << '('; - t.interpret(context); - context << ')'; - } - else - { - t.interpret(context); - } - - return context; - } -} // namespace sqlpp diff --git a/include/sqlpp11/interpretable_list.h b/include/sqlpp11/interpretable_list.h deleted file mode 100644 index 4db0534d..00000000 --- a/include/sqlpp11/interpretable_list.h +++ /dev/null @@ -1,93 +0,0 @@ -#pragma once - -/* - * 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. - */ - -#include -#include - -namespace sqlpp -{ - template - struct interpretable_list_t - { - std::vector> _serializables; - - std::size_t size() const - { - return _serializables.size(); - } - - bool empty() const - { - return _serializables.empty(); - } - - template - void emplace_back(Expr expr) - { - _serializables.emplace_back(expr); - } - }; - - template <> - struct interpretable_list_t - { - static constexpr std::size_t size() - { - return 0; - } - - static constexpr bool empty() - { - return true; - } - }; - - template - auto interpret_list(const interpretable_list_t& t, const Separator& separator, Context& context) - -> Context& - { - bool first = true; - for (const auto& entry : t._serializables) - { - if (not first) - { - context << separator; - } - first = false; - serialize(entry, context); - } - return context; - } - - template - auto interpret_list(const interpretable_list_t&, const Separator&, Context& context) - -> Context& - { - return context; - } -} // namespace sqlpp diff --git a/include/sqlpp11/limit.h b/include/sqlpp11/limit.h index 8173a5cb..4e3585af 100644 --- a/include/sqlpp11/limit.h +++ b/include/sqlpp11/limit.h @@ -104,96 +104,6 @@ namespace sqlpp }; }; - // DYNAMIC LIMIT DATA - template - struct dynamic_limit_data_t - { - dynamic_limit_data_t() : _value(noop()) - { - } - - template - dynamic_limit_data_t(Limit value) : _initialized(true), _value(wrap_operand_t(value)) - { - } - - dynamic_limit_data_t(const dynamic_limit_data_t&) = default; - dynamic_limit_data_t(dynamic_limit_data_t&&) = default; - dynamic_limit_data_t& operator=(const dynamic_limit_data_t&) = default; - dynamic_limit_data_t& operator=(dynamic_limit_data_t&&) = default; - ~dynamic_limit_data_t() = default; - - bool _initialized = false; - interpretable_t _value; - }; - - // DYNAMIC LIMIT - template - struct dynamic_limit_t - { - using _traits = make_traits; - using _nodes = detail::type_vector<>; - - // Data - using _data_t = dynamic_limit_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) - { - } - - template - void set(Limit value) - { - // FIXME: Make sure that Limit does not require external tables? Need to read up on SQL - using arg_t = wrap_operand_t; - static_assert(is_unsigned_integral_t::value, - "limit requires an unsigned integral value or unsigned integral parameter"); - _data._value = arg_t{value}; - _data._initialized = true; - } - - public: - _data_t _data; - }; - - // Base template to be inherited by the statement - template - struct _base_t - { - using _data_t = dynamic_limit_data_t; - - // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 - template - _base_t(Args&&... args) : limit{std::forward(args)...} - { - } - - _impl_t limit; - _impl_t& operator()() - { - return limit; - } - const _impl_t& operator()() const - { - return limit; - } - - template - static auto _get_member(T t) -> decltype(t.limit) - { - return t.limit; - } - - using _consistency_check = consistent_t; - }; - }; - SQLPP_PORTABLE_STATIC_ASSERT(assert_limit_is_unsigned_integral, "argument for limit() must be an unsigned integral expressions"); template @@ -267,11 +177,6 @@ namespace sqlpp return _limit_impl(check_limit_t{}, wrap_operand_t{arg}); } - auto dynamic_limit() const -> _new_statement_t> - { - return {static_cast&>(*this), dynamic_limit_data_t<_database_t>{}}; - } - private: template auto _limit_impl(Check, Arg arg) const -> inconsistent; @@ -285,17 +190,6 @@ namespace sqlpp }; // Interpreters - template - Context& serialize(const dynamic_limit_data_t& t, Context& context) - { - if (t._initialized) - { - context << " LIMIT "; - serialize(t._value, context); - } - return context; - } - template Context& serialize(const limit_data_t& t, Context& context) { @@ -310,9 +204,4 @@ namespace sqlpp return statement_t().limit(std::forward(t)); } - template - auto dynamic_limit(const Database & /*unused*/) -> decltype(statement_t().dynamic_limit()) - { - return statement_t().dynamic_limit(); - } } // namespace sqlpp diff --git a/include/sqlpp11/named_interpretable.h b/include/sqlpp11/named_interpretable.h deleted file mode 100644 index 7923caa7..00000000 --- a/include/sqlpp11/named_interpretable.h +++ /dev/null @@ -1,112 +0,0 @@ -#pragma once - -/* - * 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. - */ - -#include -#include -#include - -namespace sqlpp -{ - template - struct named_interpretable_t - { - using _serializer_context_t = typename Db::_serializer_context_t; - - template - named_interpretable_t(T t) : _requires_parens(requires_parens_t::value), _impl(std::make_shared<_impl_t>(t)) - { - } - - named_interpretable_t(const named_interpretable_t&) = default; - named_interpretable_t(named_interpretable_t&&) = default; - named_interpretable_t& operator=(const named_interpretable_t&) = default; - named_interpretable_t& operator=(named_interpretable_t&&) = default; - ~named_interpretable_t() = default; - - _serializer_context_t& interpret(_serializer_context_t& context) const - { - return _impl->interpret(context); - } - - std::string _get_name() const - { - return _impl->_get_name(); - } - - bool _requires_parens; - - private: - struct _impl_base - { - virtual ~_impl_base() = default; - virtual _serializer_context_t& interpret(_serializer_context_t& context) const = 0; - virtual std::string _get_name() const = 0; - }; - - template - struct _impl_t : public _impl_base - { - static_assert(not make_parameter_list_t::size::value, "parameters not supported in dynamic statement parts"); - _impl_t(T t) : _t(t) - { - } - - _serializer_context_t& interpret(_serializer_context_t& context) const - { - serialize(_t, context); - return context; - } - - std::string _get_name() const - { - return name_of::template char_ptr<_serializer_context_t>(); - } - - T _t; - }; - - std::shared_ptr _impl; - }; - - template - Context& serialize(const named_interpretable_t& t, Context& context) - { - if (t._requires_parens) - { - context << '('; - t.interpret(context); - context << ')'; - } - else - { - t.interpret(context); - } - - return context; - } -} // namespace sqlpp diff --git a/include/sqlpp11/offset.h b/include/sqlpp11/offset.h index e22148a1..5a0d5101 100644 --- a/include/sqlpp11/offset.h +++ b/include/sqlpp11/offset.h @@ -104,108 +104,6 @@ namespace sqlpp }; }; - // DYNAMIC OFFSET DATA - template - struct dynamic_offset_data_t - { - dynamic_offset_data_t() : _value(noop()) - { - } - - template - dynamic_offset_data_t(Offset value) : _initialized(true), _value(wrap_operand_t(value)) - { - } - - dynamic_offset_data_t(const dynamic_offset_data_t&) = default; - dynamic_offset_data_t(dynamic_offset_data_t&&) = default; - dynamic_offset_data_t& operator=(const dynamic_offset_data_t&) = default; - dynamic_offset_data_t& operator=(dynamic_offset_data_t&&) = default; - ~dynamic_offset_data_t() = default; - - bool _initialized = false; - interpretable_t _value; - }; - - // DYNAMIC OFFSET - template - struct dynamic_offset_t - { - using _traits = make_traits; - using _nodes = detail::type_vector<>; - - // Data - using _data_t = dynamic_offset_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) - { - } - - template - void set(Offset value) - { - // FIXME: Make sure that Offset does not require external tables? Need to read up on SQL - using arg_t = wrap_operand_t; - static_assert(is_unsigned_integral_t::value, - "offset requires an unsigned integral value or unsigned integral parameter"); - _data._value = arg_t{value}; - _data._initialized = true; - } - - public: - _data_t _data; - }; - - // Base template to be inherited by the statement - template - struct _base_t - { - using _data_t = dynamic_offset_data_t; - - // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069 - template - _base_t(Args&&... args) : offset{std::forward(args)...} - { - } - - _impl_t offset; - _impl_t& operator()() - { - return offset; - } - const _impl_t& operator()() const - { - return offset; - } - - template - static auto _get_member(T t) -> decltype(t.offset) - { - return t.offset; - } - - using _consistency_check = consistent_t; - - template - void set_offset(Offset value) - { - // FIXME: Make sure that Offset does not require external tables? Need to read up on SQL - using arg_t = wrap_operand_t; - static_cast*>(this)->_offset()._value = arg_t{value}; - static_cast*>(this)->_offset()._initialized = true; - } - }; - - bool _initialized = false; - interpretable_t _value; - }; - SQLPP_PORTABLE_STATIC_ASSERT(assert_offset_is_unsigned_integral, "argument for offset() must be an integral expressions"); template @@ -279,13 +177,6 @@ namespace sqlpp return _offset_impl(check_offset_t{}, wrap_operand_t{arg}); } - 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"); - return {static_cast&>(*this), dynamic_offset_data_t<_database_t>{}}; - } - private: template auto _offset_impl(Check, Arg arg) const -> inconsistent; @@ -307,26 +198,10 @@ namespace sqlpp return context; } - template - Context& serialize(const dynamic_offset_data_t& t, Context& context) - { - if (t._initialized) - { - context << " OFFSET "; - serialize(t._value, context); - } - return context; - } - template auto offset(T&& t) -> decltype(statement_t().offset(std::forward(t))) { return statement_t().offset(std::forward(t)); } - template - auto dynamic_offset(const Database & /*unused*/) -> decltype(statement_t().dynamic_offset()) - { - return statement_t().dynamic_offset(); - } } // namespace sqlpp diff --git a/include/sqlpp11/on.h b/include/sqlpp11/on.h index ee9be580..4e4dd58d 100644 --- a/include/sqlpp11/on.h +++ b/include/sqlpp11/on.h @@ -27,7 +27,6 @@ */ #include -#include #include #include diff --git a/include/sqlpp11/order_by.h b/include/sqlpp11/order_by.h index bf288677..42b33f3b 100644 --- a/include/sqlpp11/order_by.h +++ b/include/sqlpp11/order_by.h @@ -28,7 +28,6 @@ #include #include -#include #include #include #include @@ -51,7 +50,6 @@ namespace sqlpp ~order_by_data_t() = default; std::tuple _expressions; - interpretable_list_t _dynamic_expressions; }; SQLPP_PORTABLE_STATIC_ASSERT( @@ -65,8 +63,6 @@ namespace sqlpp using _traits = make_traits; using _nodes = detail::type_vector; - using _is_dynamic = is_database; - // Data using _data_t = order_by_data_t; @@ -80,28 +76,6 @@ namespace sqlpp { } - template - void add(Expression expression) - { - static_assert(_is_dynamic::value, "add() must not be called for static order_by"); - static_assert(is_sort_order_t::value, "invalid expression argument in order_by::add()"); - static_assert(Policies::template _no_unknown_tables::value, - "expression uses tables unknown to this statement in order_by::add()"); - using ok = logic::all_t<_is_dynamic::value, is_sort_order_t::value>; - - _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert - } - - private: - template - void _add_impl(Expression expression, const std::true_type& /*unused*/) - { - _data._dynamic_expressions.emplace_back(expression); - } - - template - void _add_impl(Expression expression, const std::false_type&); - public: _data_t _data; }; @@ -217,16 +191,6 @@ namespace sqlpp return _order_by_impl(check_order_by_t{}, expressions...); } - template - auto dynamic_order_by(Expressions... expressions) const - -> _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"); - - return _order_by_impl<_database_t>(check_order_by_t{}, expressions...); - } - private: template auto _order_by_impl(Check, Expressions... expressions) const -> inconsistent; @@ -248,17 +212,8 @@ namespace sqlpp template Context& serialize(const order_by_data_t& t, Context& context) { - if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty()) - { - return context; - } context << " ORDER BY "; interpret_tuple(t._expressions, ',', context); - if (sizeof...(Expressions) and not t._dynamic_expressions.empty()) - { - context << ','; - } - interpret_list(t._dynamic_expressions, ',', context); return context; } @@ -268,10 +223,4 @@ namespace sqlpp return statement_t().order_by(std::forward(t)...); } - template - auto dynamic_order_by(const Database& /*unused*/, T&&... t) - -> decltype(statement_t().dynamic_order_by(std::forward(t)...)) - { - return statement_t().dynamic_order_by(std::forward(t)...); - } } // namespace sqlpp diff --git a/include/sqlpp11/postgresql/on_conflict_do_update.h b/include/sqlpp11/postgresql/on_conflict_do_update.h index f85f1f93..66f70b6e 100644 --- a/include/sqlpp11/postgresql/on_conflict_do_update.h +++ b/include/sqlpp11/postgresql/on_conflict_do_update.h @@ -29,7 +29,6 @@ #include #include -#include #include #include @@ -57,7 +56,6 @@ namespace sqlpp on_conflict_data_t _conflict_target; std::tuple _assignments; - // interpretable_list_t _dynamic_assignments; }; // Where data diff --git a/include/sqlpp11/postgresql/returning_column_list.h b/include/sqlpp11/postgresql/returning_column_list.h index 2542a22b..d52e9e04 100644 --- a/include/sqlpp11/postgresql/returning_column_list.h +++ b/include/sqlpp11/postgresql/returning_column_list.h @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -70,66 +69,6 @@ namespace sqlpp }; } // namespace detail - template - struct dynamic_returning_column_list - { - using _names_t = std::vector; - std::vector> _dynamic_columns; - _names_t _dynamic_expression_names; - - template - void emplace_back(Expr expr) - { - _dynamic_expression_names.push_back(name_of::char_ptr()); - _dynamic_columns.emplace_back(expr); - } - - bool empty() const - { - return _dynamic_columns.empty(); - } - }; - - template <> - struct dynamic_returning_column_list - { - using _names_t = no_name_t; - _names_t _dynamic_expression_names; - - static constexpr bool empty() - { - return true; - } - }; - - template - postgresql::context_t& serialize(const postgresql::dynamic_returning_column_list& t, - postgresql::context_t& context) - { - bool first{true}; - for (const auto& column : t._dynamic_columns) - { - if (first) - { - first = false; - } - else - { - context << ','; - } - - serialize(column, context); - } - - return context; - } - - inline postgresql::context_t& serialize(const postgresql::dynamic_returning_column_list&, - postgresql::context_t& context) - { - return context; - } - template struct returning_column_list_data_t { @@ -145,7 +84,6 @@ namespace sqlpp returning_column_list_data_t& operator=(returning_column_list_data_t&&) = default; std::tuple _columns; - dynamic_returning_column_list _dynamic_columns; }; // static asserts... @@ -160,7 +98,6 @@ namespace sqlpp using _traits = typename detail::returning_traits::_traits; using _nodes = ::sqlpp::detail::type_vector; using _alias_t = typename detail::returning_traits::_alias_t; - using _is_dynamic = is_database; struct _column_type { @@ -179,39 +116,6 @@ namespace sqlpp { } - template - void add_ntc(NamedExpression namedExpression) - { - add(namedExpression); - } - - template - void add(NamedExpression namedExpression) - { - using named_expression = auto_alias_t; - static_assert(_is_dynamic::value, "selected_columns::add() can only be called for dynamic_column"); - static_assert(is_selectable_t::value, - "invalid named expression argument in selected_columns::add()"); - static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, - "named expression uses tables unknown to this statement in selected_columns::add()"); - using column_names = ::sqlpp::detail::make_type_set_t; - static_assert(not::sqlpp::detail::is_element_of::value, - "a column of this name is present in the select already"); - - using ok = logic::all_t<_is_dynamic::value, is_selectable_t::value>; - - _add_impl(namedExpression, ok()); - } - - template - void _add_impl(NamedExpression namedExpression, const std::true_type&) - { - return _data._dynamic_columns.emplace_back(auto_alias_t{namedExpression}); - } - - template - void _add_impl(NamedExpression namedExpression, const std::false_type&); - _data_t _data; }; @@ -281,12 +185,7 @@ namespace sqlpp template using _field_t = typename _deferred_field_t::type; - template - using _result_row_t = typename std::conditional<_is_dynamic::value, - dynamic_result_row_t...>, - result_row_t...>>::type; - - using _dynamic_names_t = typename dynamic_returning_column_list::_names_t; + using _result_row_t = result_row_t < Db, _field_t... >; template struct _deferred_table_t @@ -310,14 +209,9 @@ namespace sqlpp return _table_t(_get_statement()).as(aliasProvider); } - const _dynamic_names_t& get_dynamic_names() const - { - return _get_statement().get_selected_columns()._data._dynamic_columns._dynamic_expression_names; - } - size_t get_no_of_result_columns() const { - return sizeof...(Columns) + get_dynamic_names().size(); + return sizeof...(Columns); } // auto .. @@ -325,26 +219,26 @@ namespace sqlpp auto _run(Db& db, const Composite& composite) const -> result_t> { - return {db.select(composite), get_dynamic_names()}; + return {db.select(composite)}; } template auto _run(Db& db) const -> result_t())), _result_row_t> { - return {db.select(_get_statement()), get_dynamic_names()}; + return {db.select(_get_statement())}; } // Prepare template auto _prepare(Db& db, const Composite& composite) const -> prepared_select_t { - return {make_parameter_list_t{}, get_dynamic_names(), db.prepare_select(composite)}; + return {make_parameter_list_t{}, db.prepare_select(composite)}; } template auto _prepare(Db& db) const -> prepared_select_t { - return {make_parameter_list_t<_statement_t>{}, get_dynamic_names(), db.prepare_select(_get_statement())}; + return {make_parameter_list_t<_statement_t>{}, db.prepare_select(_get_statement())}; } }; }; @@ -445,20 +339,6 @@ namespace sqlpp return _returning_impl(decltype(_check_args(args...)){}, ::sqlpp::detail::column_tuple_merge(args...)); } - template - auto dynamic_returning(Args... args) const - -> _new_statement_t(::sqlpp::detail::column_tuple_merge(args...)))> - { - static_assert(not std::is_same<_database_t, void>::value, - "dynamic_columns must not be called in a static statement"); - static_assert(decltype(_check_args(args...))::value, - "at least one argument is not a selectable expression in returning()"); - - return _returning_impl<_database_t>(decltype(_check_args(args...)){}, - ::sqlpp::detail::column_tuple_merge(args...)); - } - private: template auto _returning_impl(const std::false_type&, std::tuple args) const -> inconsistent; @@ -484,9 +364,6 @@ namespace sqlpp { context << " RETURNING "; interpret_tuple(t._columns, ',', context); - if (sizeof...(Columns) and not t._dynamic_columns.empty()) - context << ','; - serialize(t._dynamic_columns, context); return context; } } diff --git a/include/sqlpp11/prepared_select.h b/include/sqlpp11/prepared_select.h index 3d4ed444..d5586bfe 100644 --- a/include/sqlpp11/prepared_select.h +++ b/include/sqlpp11/prepared_select.h @@ -40,14 +40,13 @@ namespace sqlpp using _result_row_t = typename Statement::template _result_row_t; using _parameter_list_t = make_parameter_list_t; - using _dynamic_names_t = typename Statement::_dynamic_names_t; using _prepared_statement_t = typename Database::_prepared_statement_t; using _run_check = consistent_t; auto _run(Database& db) const -> result_t { - return {db.run_prepared_select(*this), _dynamic_names}; + return {db.run_prepared_select(*this)}; } void _bind_params() const @@ -56,7 +55,6 @@ namespace sqlpp } _parameter_list_t params; - _dynamic_names_t _dynamic_names; mutable _prepared_statement_t _prepared_statement; }; } // namespace sqlpp diff --git a/include/sqlpp11/remove.h b/include/sqlpp11/remove.h index 99a44080..45d33280 100644 --- a/include/sqlpp11/remove.h +++ b/include/sqlpp11/remove.h @@ -108,17 +108,4 @@ namespace sqlpp return {blank_remove_t().from(table)}; } - template - auto dynamic_remove(const Database & /*unused*/) -> decltype(blank_remove_t()) - { - static_assert(std::is_base_of::value, "Invalid database parameter"); - return {blank_remove_t()}; - } - - template - auto dynamic_remove_from(const Database& /*unused*/, Table table) -> decltype(blank_remove_t().from(table)) - { - static_assert(std::is_base_of::value, "Invalid database parameter"); - return {blank_remove_t().from(table)}; - } } // namespace sqlpp diff --git a/include/sqlpp11/result.h b/include/sqlpp11/result.h index 58b0bd10..45cd33b5 100644 --- a/include/sqlpp11/result.h +++ b/include/sqlpp11/result.h @@ -71,9 +71,8 @@ namespace sqlpp public: result_t() = default; - template - result_t(db_result_t&& result, const DynamicNames& dynamic_names) - : _result(std::move(result)), _result_row(dynamic_names) + result_t(db_result_t&& result) + : _result(std::move(result)), _result_row() { _result.next(_result_row); } diff --git a/include/sqlpp11/result_row.h b/include/sqlpp11/result_row.h index b4129a2a..f02e043f 100644 --- a/include/sqlpp11/result_row.h +++ b/include/sqlpp11/result_row.h @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -122,10 +121,6 @@ namespace sqlpp { } - result_row_t(const typename dynamic_select_column_list::_names_t& /*unused*/) : _impl() - { - } - result_row_t(const result_row_t&) = delete; result_row_t(result_row_t&&) = default; result_row_t& operator=(const result_row_t&) = delete; @@ -195,108 +190,6 @@ namespace sqlpp static constexpr auto value = logic::all_t::value...>::value; }; - template - struct dynamic_result_row_t - : public detail::result_row_impl, FieldSpecs...> - { - using _impl = detail::result_row_impl, FieldSpecs...>; - using _field_type = sqlpp::string_view; - - bool _is_valid{false}; - std::vector _dynamic_field_names; - std::map _dynamic_fields; - - dynamic_result_row_t() : _impl() - { - } - - dynamic_result_row_t(std::vector dynamic_field_names) - : _impl(), _dynamic_field_names(std::move(dynamic_field_names)) - { - for (auto field_name : _dynamic_field_names) - { - _dynamic_fields.insert({field_name, _field_type{}}); - } - } - - dynamic_result_row_t(const dynamic_result_row_t&) = delete; - dynamic_result_row_t(dynamic_result_row_t&&) = default; - dynamic_result_row_t& operator=(const dynamic_result_row_t&) = delete; - dynamic_result_row_t& operator=(dynamic_result_row_t&&) = default; - - void _validate() - { - _is_valid = true; - } - - void _invalidate() - { - _is_valid = false; - } - - bool operator==(const dynamic_result_row_t& rhs) const - { - return _is_valid == rhs._is_valid; - } - - const _field_type& at(const std::string& field_name) const - { - return _dynamic_fields.at(field_name); - } - - explicit operator bool() const - { - return _is_valid; - } - - template - void _bind(Target& target) - { - _impl::_bind(target); - - std::size_t index = sizeof...(FieldSpecs); - for (const auto& field_name : _dynamic_field_names) - { - target.read_field(index, _dynamic_fields.at(field_name)); - ++index; - } - } - - template - void _post_bind(Target& target) - { - _impl::_post_bind(target); - - std::size_t index = sizeof...(FieldSpecs); - for (const auto& field_name : _dynamic_field_names) - { - target.post_read(index, _dynamic_fields.at(field_name)); - ++index; - } - } - - template - void _apply(Callable& callable) const - { - _impl::_apply(callable); - - for (const auto& field_name : _dynamic_field_names) - { - callable(_dynamic_fields.at(field_name)); - } - } - - template - void _apply(const Callable& callable) const - { - _impl::_apply(callable); - - for (const auto& field_name : _dynamic_field_names) - { - callable(_dynamic_fields.at(field_name)); - } - } - }; template struct is_static_result_row_impl diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index d15ed5c5..5f669d02 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -90,18 +90,4 @@ namespace sqlpp return blank_select_t().columns(columns...); } - template - blank_select_t dynamic_select(const Database& /*unused*/) - { - static_assert(std::is_base_of::value, "Invalid database parameter"); - return {}; - } - - template - auto dynamic_select(const Database& /*unused*/, Columns... columns) - -> decltype(blank_select_t().columns(columns...)) - { - static_assert(std::is_base_of::value, "Invalid database parameter"); - return blank_select_t().columns(columns...); - } } // namespace sqlpp diff --git a/include/sqlpp11/select_column_list.h b/include/sqlpp11/select_column_list.h index edfa2fc0..b05b38b2 100644 --- a/include/sqlpp11/select_column_list.h +++ b/include/sqlpp11/select_column_list.h @@ -30,11 +30,9 @@ #include #include #include -#include #include #include #include -#include #include #include #include @@ -85,7 +83,6 @@ namespace sqlpp ~select_column_list_data_t() = default; std::tuple _columns; - dynamic_select_column_list _dynamic_columns; }; SQLPP_PORTABLE_STATIC_ASSERT( @@ -106,8 +103,6 @@ namespace sqlpp using _alias_t = typename detail::select_traits::_alias_t; - using _is_dynamic = is_database; - struct _column_type { }; @@ -125,34 +120,6 @@ namespace sqlpp { } - template - void add(NamedExpression namedExpression) - { - using named_expression = auto_alias_t; - static_assert(_is_dynamic::value, "selected_columns::add() can only be called for dynamic_column"); - static_assert(is_selectable_t::value, - "invalid named expression argument in selected_columns::add()"); - static_assert(Policies::template _no_unknown_tables::value, - "named expression uses tables unknown to this statement in selected_columns::add()"); - using column_names = detail::make_type_set_t; - static_assert(not column_names::template count(), - "a column of this name is present in the select already"); - using ok = - logic::all_t<_is_dynamic::value, is_selectable_t::value>; - - _add_impl(namedExpression, ok()); // dispatch to prevent compile messages after the static_assert - } - - // private: - template - void _add_impl(NamedExpression namedExpression, const std::true_type& /*unused*/) - { - _data._dynamic_columns.emplace_back(auto_alias_t{namedExpression}); - } - - template - void _add_column_impl(NamedExpression namedExpression, const std::false_type&); - public: _data_t _data; }; @@ -234,11 +201,7 @@ namespace sqlpp using _field_t = typename _deferred_field_t::type; template - using _result_row_t = typename std::conditional<_is_dynamic::value, - dynamic_result_row_t...>, - result_row_t...>>::type; - - using _dynamic_names_t = typename dynamic_select_column_list::_names_t; + using _result_row_t = result_row_t...>; template struct _deferred_table_t @@ -262,40 +225,35 @@ namespace sqlpp return _table_t(_get_statement()).as(aliasProvider); } - const _dynamic_names_t& get_dynamic_names() const - { - return _get_statement().get_selected_columns()._data._dynamic_columns._dynamic_expression_names; - } - size_t get_no_of_result_columns() const { - return sizeof...(Columns) + _get_statement().get_selected_columns()._data._dynamic_columns.size(); + return sizeof...(Columns); } // Execute template auto _run(Db& db, const Composite& composite) const -> result_t> { - return {db.select(composite), get_dynamic_names()}; + return {db.select(composite)}; } template auto _run(Db& db) const -> result_t())), _result_row_t> { - return {db.select(_get_statement()), get_dynamic_names()}; + return {db.select(_get_statement())}; } // Prepare template auto _prepare(Db& db, const Composite& composite) const -> prepared_select_t { - return {make_parameter_list_t{}, get_dynamic_names(), db.prepare_select(composite)}; + return {make_parameter_list_t{}, db.prepare_select(composite)}; } template auto _prepare(Db& db) const -> prepared_select_t { - return {make_parameter_list_t<_statement_t>{}, get_dynamic_names(), db.prepare_select(_get_statement())}; + return {make_parameter_list_t<_statement_t>{}, db.prepare_select(_get_statement())}; } }; }; @@ -395,20 +353,6 @@ namespace sqlpp return _columns_impl(check{}, detail::column_tuple_merge(args...)); } - template - auto dynamic_columns(Args... args) const - -> _new_statement_t(detail::column_tuple_merge(args...)))> - { - static_assert(not std::is_same<_database_t, void>::value, - "dynamic_columns must not be called in a static statement"); - using check = decltype(_check_args(detail::column_tuple_merge(args...))); - static_assert(check::value, - "at least one argument is not a selectable expression in columns()"); - - return _columns_impl<_database_t>(check{}, detail::column_tuple_merge(args...)); - } - private: template auto _columns_impl(Check, std::tuple args) const -> inconsistent; @@ -428,11 +372,6 @@ namespace sqlpp Context& serialize(const select_column_list_data_t& t, Context& context) { interpret_tuple(t._columns, ',', context); - if (sizeof...(Columns) and not t._dynamic_columns.empty()) - { - context << ','; - } - serialize(t._dynamic_columns, context); return context; } @@ -442,10 +381,4 @@ namespace sqlpp return statement_t().columns(std::forward(t)...); } - template - auto dynamic_select_columns(const Database& /*unused*/, T&&... t) - -> decltype(statement_t().dynamic_columns(std::forward(t)...)) - { - return statement_t().dynamic_columns(std::forward(t)...); - } } // namespace sqlpp diff --git a/include/sqlpp11/select_flag_list.h b/include/sqlpp11/select_flag_list.h index 8a2cfd2e..3ecebee6 100644 --- a/include/sqlpp11/select_flag_list.h +++ b/include/sqlpp11/select_flag_list.h @@ -51,7 +51,6 @@ namespace sqlpp ~select_flag_list_data_t() = default; std::tuple _flags; - interpretable_list_t _dynamic_flags; }; // SELECT FLAGS @@ -61,8 +60,6 @@ namespace sqlpp using _traits = make_traits; using _nodes = detail::type_vector; - using _is_dynamic = is_database; - // Data using _data_t = select_flag_list_data_t; @@ -76,28 +73,6 @@ namespace sqlpp { } - template - void add(Flag flag) - { - static_assert(_is_dynamic::value, "select_flags::add() must not be called for static select flags"); - static_assert(is_select_flag_t::value, "invalid select flag argument in select_flags::add()"); - static_assert(Policies::template _no_unknown_tables::value, - "flag uses tables unknown to this statement in select_flags::add()"); - using ok = logic::all_t<_is_dynamic::value, is_select_flag_t::value>; - - _add_impl(flag, ok()); // dispatch to prevent compile messages after the static_assert - } - - private: - template - void _add_impl(Flag flag, const std::true_type& /*unused*/) - { - _data._dynamic_flags.emplace_back(flag); - } - - template - void _add_impl(Flag flag, const std::false_type&); - public: _data_t _data; }; @@ -207,16 +182,6 @@ namespace sqlpp return _flags_impl(check_select_flags_t{}, flgs...); } - template - auto dynamic_flags(Flags... flgs) const - -> _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"); - - return _flags_impl<_database_t>(check_select_flags_t{}, flgs...); - } - private: template auto _flags_impl(Check, Flags... flgs) const -> inconsistent; @@ -243,11 +208,6 @@ namespace sqlpp { context << ' '; } - interpret_list(t._dynamic_flags, ',', context); - if (not t._dynamic_flags.empty()) - { - context << ' '; - } return context; } @@ -257,10 +217,4 @@ namespace sqlpp return statement_t().flags(std::forward(t)); } - template - auto dynamic_select_flags(const Database& /*unused*/, T&& t) - -> decltype(statement_t().dynamic_flags(std::forward(t))) - { - return statement_t().dynamic_flags(std::forward(t)); - } } // namespace sqlpp diff --git a/include/sqlpp11/sqlpp11.h b/include/sqlpp11/sqlpp11.h index cf0f845b..274aebb0 100644 --- a/include/sqlpp11/sqlpp11.h +++ b/include/sqlpp11/sqlpp11.h @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include diff --git a/include/sqlpp11/union.h b/include/sqlpp11/union.h index 5fa19141..b87cc7cc 100644 --- a/include/sqlpp11/union.h +++ b/include/sqlpp11/union.h @@ -28,7 +28,6 @@ #include #include -#include #include #include #include diff --git a/include/sqlpp11/update.h b/include/sqlpp11/update.h index d7dff83c..9b8554c3 100644 --- a/include/sqlpp11/update.h +++ b/include/sqlpp11/update.h @@ -103,11 +103,4 @@ namespace sqlpp return {blank_update_t().single_table(table)}; } - template - constexpr auto dynamic_update(const Database& /*unused*/, Table table) - -> decltype(blank_update_t().single_table(table)) - { - static_assert(std::is_base_of::value, "Invalid database parameter"); - return {blank_update_t().single_table(table)}; - } } // namespace sqlpp diff --git a/include/sqlpp11/update_list.h b/include/sqlpp11/update_list.h index 3e06c108..198b2e96 100644 --- a/include/sqlpp11/update_list.h +++ b/include/sqlpp11/update_list.h @@ -28,7 +28,6 @@ #include #include -#include #include namespace sqlpp @@ -48,7 +47,6 @@ namespace sqlpp ~update_list_data_t() = default; std::tuple _assignments; - interpretable_list_t _dynamic_assignments; }; SQLPP_PORTABLE_STATIC_ASSERT( @@ -61,7 +59,6 @@ namespace sqlpp { using _traits = make_traits; using _nodes = detail::type_vector; - using _is_dynamic = is_database; // Data using _data_t = update_list_data_t; @@ -76,32 +73,6 @@ namespace sqlpp { } - template - void add(Assignment assignment) - { - static_assert(_is_dynamic::value, "add must not be called for static from()"); - static_assert(is_assignment_t::value, "invalid assignment argument in add()"); - using _assigned_columns = detail::make_type_set_t...>; - static_assert(not _assigned_columns::template count>(), - "Must not assign value to column twice"); - static_assert(logic::not_t>::value, "add() argument must not be updated"); - static_assert(Policies::template _no_unknown_tables::value, - "assignment uses tables unknown to this statement in add()"); - using ok = logic::all_t<_is_dynamic::value, is_assignment_t::value>; - - _add_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert - } - - private: - template - void _add_impl(Assignment assignment, const std::true_type& /*unused*/) - { - _data._dynamic_assignments.emplace_back(assignment); - } - - template - void _add_impl(Assignment assignment, const std::false_type&); - public: _data_t _data; }; @@ -149,8 +120,7 @@ namespace sqlpp SQLPP_PORTABLE_STATIC_ASSERT(assert_update_set_single_table_t, "set() contains assignments for columns from more than one table"); SQLPP_PORTABLE_STATIC_ASSERT(assert_update_set_count_args_t, "at least one assignment expression required in set()"); - SQLPP_PORTABLE_STATIC_ASSERT(assert_update_dynamic_set_statement_dynamic_t, - "dynamic_set() must not be called in a static statement"); + namespace detail { template @@ -182,17 +152,6 @@ namespace sqlpp template using check_update_static_set_t = typename check_update_static_set::type; - template - struct check_update_dynamic_set - { - using type = static_combined_check_t< - static_check_t::value, assert_update_dynamic_set_statement_dynamic_t>, - check_update_set_t>; - }; - - template - using check_update_dynamic_set_t = typename check_update_dynamic_set::type; - struct no_update_list_t { using _traits = make_traits; @@ -265,15 +224,6 @@ namespace sqlpp return _set_impl(Check{}, assignments); } - template - auto dynamic_set(Assignments... assignments) const - -> _new_statement_t, - update_list_t<_database_t, Assignments...>> - { - using Check = check_update_dynamic_set_t<_database_t, Assignments...>; - return _set_impl<_database_t>(Check{}, std::make_tuple(assignments...)); - } - private: template auto _set_impl(Check, Assignments... assignments) const -> inconsistent; @@ -294,11 +244,6 @@ namespace sqlpp { context << " SET "; interpret_tuple(t._assignments, ",", context); - if (sizeof...(Assignments) and not t._dynamic_assignments.empty()) - { - context << ','; - } - interpret_list(t._dynamic_assignments, ',', context); return context; } } // namespace sqlpp diff --git a/include/sqlpp11/using.h b/include/sqlpp11/using.h index 1518a324..708cc6e1 100644 --- a/include/sqlpp11/using.h +++ b/include/sqlpp11/using.h @@ -28,7 +28,6 @@ #include #include -#include #include #include @@ -49,7 +48,6 @@ namespace sqlpp ~using_data_t() = default; std::tuple _tables; - interpretable_list_t _dynamic_tables; }; // USING @@ -59,8 +57,6 @@ namespace sqlpp using _traits = make_traits; using _nodes = detail::type_vector; - using _is_dynamic = is_database; - // Data using _data_t = using_data_t; @@ -74,26 +70,6 @@ namespace sqlpp { } - template - void add(Table table) - { - 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 ok = logic::all_t<_is_dynamic::value, is_table_t
::value>; - - _add_impl(table, ok()); // dispatch to prevent compile messages after the static_assert - } - - private: - template - void _add_impl(Table table, const std::true_type& /*unused*/) - { - _data._dynamic_tables.emplace_back(table); - } - - template - void _add_impl(Table table, const std::false_type&); - public: _data_t _data; }; @@ -208,16 +184,6 @@ namespace sqlpp return {_using_impl(check_using_t{}, tables...)}; } - 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"); - - return {_using_impl<_database_t>(check_using_t{}, tables...)}; - } - private: template auto _using_impl(Check, Tables... tables) const -> inconsistent; @@ -238,17 +204,8 @@ namespace sqlpp template Context& serialize(const using_data_t& t, Context& context) { - if (sizeof...(Tables) == 0 and t._dynamic_tables.empty()) - { - return context; - } context << " USING "; interpret_tuple(t._tables, ',', context); - if (sizeof...(Tables) and not t._dynamic_tables.empty()) - { - context << ','; - } - interpret_list(t._dynamic_tables, ',', context); return context; } } // namespace sqlpp diff --git a/include/sqlpp11/where.h b/include/sqlpp11/where.h index 9d3d854a..c9759a5e 100644 --- a/include/sqlpp11/where.h +++ b/include/sqlpp11/where.h @@ -28,7 +28,6 @@ #include #include -#include #include #include #include @@ -53,7 +52,6 @@ namespace sqlpp ~where_data_t() = default; Expression _expression; - interpretable_list_t _dynamic_expressions; }; SQLPP_PORTABLE_STATIC_ASSERT( @@ -67,8 +65,6 @@ namespace sqlpp using _traits = make_traits; using _nodes = detail::type_vector; - using _is_dynamic = is_database; - // Data using _data_t = where_data_t; @@ -82,31 +78,6 @@ namespace sqlpp { } - template - void add(Expr expression) - { - static_assert(_is_dynamic::value, "where::add() can only be called for dynamic_where"); - static_assert(is_expression_t::value, "invalid expression argument in where::add()"); - static_assert(is_boolean_t::value, "invalid expression argument in where::add()"); - static_assert(Policies::template _no_unknown_tables::value, - "expression uses tables unknown to this statement in where::add()"); - static_assert(not contains_aggregate_function_t::value, - "where expression must not contain aggregate functions"); - using ok = logic::all_t<_is_dynamic::value, is_expression_t::value>; - - _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert - } - - private: - template - void _add_impl(Expr expression, const std::true_type& /*unused*/) - { - _data._dynamic_expressions.emplace_back(expression); - } - - template - void _add_impl(Expr expression, const std::false_type&); - public: _data_t _data; }; @@ -215,8 +186,6 @@ namespace sqlpp "where() argument has to be an sqlpp boolean expression."); SQLPP_PORTABLE_STATIC_ASSERT(assert_where_arg_contains_no_aggregate_functions_t, "at least one aggregate function used in where()"); - SQLPP_PORTABLE_STATIC_ASSERT(assert_where_dynamic_used_with_dynamic_statement_t, - "dynamic_where() must not be called in a static statement"); // workaround for msvc bugs https://connect.microsoft.com/VisualStudio/Feedback/Details/2086629 & // https://connect.microsoft.com/VisualStudio/feedback/details/2173198 @@ -247,15 +216,6 @@ namespace sqlpp template using check_where_static_t = check_where_t; - template - using check_where_dynamic_t = static_combined_check_t< - static_check_t::value, assert_where_dynamic_used_with_dynamic_statement_t>, - check_where_t>; - - template - using check_where_empty_dynamic_t = static_combined_check_t< - static_check_t::value, assert_where_dynamic_used_with_dynamic_statement_t>>; - // NO WHERE YET template struct no_where_t @@ -330,21 +290,6 @@ namespace sqlpp return _where_impl(Check{}, expression); } - template - auto dynamic_where(Expression expression) const - -> _new_statement_t, where_t<_database_t, Expression>> - { - using Check = check_where_dynamic_t<_database_t, Expression>; - return _where_impl<_database_t>(Check{}, expression); - } - - auto dynamic_where() const - -> _new_statement_t, where_t<_database_t, unconditional_t>> - { - return {static_cast&>(*this), - where_data_t<_database_t, unconditional_t>{unconditional_t{}}}; - } - private: template auto _where_impl(Check, Expression expression) const -> inconsistent; @@ -365,23 +310,12 @@ namespace sqlpp { context << " WHERE "; serialize(t._expression, context); - if (not t._dynamic_expressions.empty()) - { - context << " AND "; - } - interpret_list(t._dynamic_expressions, " AND ", context); return context; } template Context& serialize(const where_data_t& t, Context& context) { - if (t._dynamic_expressions.empty()) - { - return context; - } - context << " WHERE "; - interpret_list(t._dynamic_expressions, " AND ", context); return context; } @@ -397,20 +331,6 @@ namespace sqlpp return statement_t>().where(std::forward(t)); } - template - auto dynamic_where(const Database& /*unused*/, T&& t) - -> decltype(statement_t>().dynamic_where(std::forward(t))) - { - return statement_t>().dynamic_where(std::forward(t)); - } - - template - auto dynamic_where(const Database & /*unused*/) - -> decltype(statement_t>().dynamic_where()) - { - return statement_t>().dynamic_where(); - } - inline auto unconditionally() -> decltype(statement_t>().unconditionally()) { return statement_t>().unconditionally(); diff --git a/include/sqlpp11/with.h b/include/sqlpp11/with.h index a6405e8c..6356c67f 100644 --- a/include/sqlpp11/with.h +++ b/include/sqlpp11/with.h @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -69,8 +68,6 @@ namespace sqlpp detail::make_joined_set_t...>; // WITH provides common table expressions using _parameters = detail::type_vector_cat_t...>; - using _is_dynamic = is_database; - // Data using _data_t = with_data_t; diff --git a/tests/core/serialize/CMakeLists.txt b/tests/core/serialize/CMakeLists.txt index 51ed9757..5b15e1b7 100644 --- a/tests/core/serialize/CMakeLists.txt +++ b/tests/core/serialize/CMakeLists.txt @@ -44,6 +44,8 @@ set(test_files Operator.cpp Over.cpp SelectAs.cpp + SelectColumns.cpp + SelectFlags.cpp Some.cpp Sum.cpp TableAlias.cpp diff --git a/tests/core/serialize/CustomQuery.cpp b/tests/core/serialize/CustomQuery.cpp index 5b2c5819..f6241c75 100644 --- a/tests/core/serialize/CustomQuery.cpp +++ b/tests/core/serialize/CustomQuery.cpp @@ -35,7 +35,6 @@ int CustomQuery(int, char*[]) { const auto foo = test::TabFoo{}; const auto bar = test::TabBar{}; - auto db = MockDb{}; // Unconditionally compare(__LINE__, @@ -55,11 +54,11 @@ int CustomQuery(int, char*[]) // A full select statement made individual clauses compare( __LINE__, - custom_query(sqlpp::select(), dynamic_select_flags(db, sqlpp::distinct), dynamic_select_columns(db, foo.omega), - dynamic_from(db, foo.join(bar).on(foo.omega == bar.alpha)), dynamic_where(db, bar.alpha > 17), - dynamic_group_by(db, foo.omega), dynamic_having(db, avg(bar.alpha) > 19), - dynamic_order_by(db, foo.omega.asc(), foo.psi.order(sqlpp::sort_type::desc)), - sqlpp::dynamic_limit(db), sqlpp::dynamic_offset(db)), + custom_query(sqlpp::select(), select_flags(sqlpp::distinct), select_columns(foo.omega), + from(foo.join(bar).on(foo.omega == bar.alpha)), where(bar.alpha > 17), + group_by(foo.omega), having(avg(bar.alpha) > 19), + order_by(foo.omega.asc(), foo.psi.order(sqlpp::sort_type::desc)), + sqlpp::limit(7u), sqlpp::offset(3u)), "SELECT DISTINCT tab_foo.omega FROM tab_foo INNER JOIN tab_bar ON (tab_foo.omega=tab_bar.alpha) WHERE " "(tab_bar.alpha>17) GROUP BY tab_foo.omega HAVING (AVG(tab_bar.alpha)>19) ORDER BY tab_foo.omega " "ASC,tab_foo.psi DESC "); diff --git a/tests/core/serialize/DynamicWhere.cpp b/tests/core/serialize/DynamicWhere.cpp index 3fa9b0dc..02e59f94 100644 --- a/tests/core/serialize/DynamicWhere.cpp +++ b/tests/core/serialize/DynamicWhere.cpp @@ -34,20 +34,9 @@ int DynamicWhere(int, char*[]) const auto bar = test::TabBar{}; auto db = MockDb{}; - compare(__LINE__, dynamic_where(db), ""); - compare(__LINE__, dynamic_where(db, bar.gamma), " WHERE tab_bar.gamma"); - - { - auto statement = sqlpp::dynamic_where(db); - statement.where.add(without_table_check(bar.gamma)); - compare(__LINE__, statement, " WHERE tab_bar.gamma"); - } - - { - auto statement = dynamic_where(db, bar.gamma); - statement.where.add(without_table_check(bar.gamma)); - compare(__LINE__, statement, " WHERE tab_bar.gamma AND tab_bar.gamma"); - } + compare(__LINE__, sqlpp::unconditionally(), ""); + compare(__LINE__, where(bar.gamma), " WHERE tab_bar.gamma"); +#warning add tests with optional expressions return 0; } diff --git a/tests/core/serialize/From.cpp b/tests/core/serialize/From.cpp index 7ea8126f..7f05badb 100644 --- a/tests/core/serialize/From.cpp +++ b/tests/core/serialize/From.cpp @@ -77,60 +77,6 @@ int From(int, char* []) .on(sqlpp::verbatim("a.column_x>another_table.x"))), " FROM unknown_table AS a INNER JOIN another_table ON a.column_x>another_table.x"); - // Dynamic joins - const auto df = dynamic_from(db, foo); - compare(__LINE__, df, " FROM tab_foo"); - { - auto dfa = df; - dfa.from.add(dynamic_cross_join(bar)); - compare(__LINE__, dfa, " FROM tab_foo CROSS JOIN tab_bar"); - } - { - auto dfa = df; - dfa.from.add(dynamic_join(bar).on(bar.alpha > foo.omega)); - compare(__LINE__, dfa, " FROM tab_foo INNER JOIN tab_bar ON (tab_bar.alpha>tab_foo.omega)"); - } - { - auto dfa = df; - dfa.from.add(dynamic_inner_join(bar).on(bar.alpha > foo.omega)); - compare(__LINE__, dfa, " FROM tab_foo INNER JOIN tab_bar ON (tab_bar.alpha>tab_foo.omega)"); - } - { - auto dfa = df; - dfa.from.add(dynamic_outer_join(bar).on(bar.alpha > foo.omega)); - compare(__LINE__, dfa, " FROM tab_foo OUTER JOIN tab_bar ON (tab_bar.alpha>tab_foo.omega)"); - } - { - auto dfa = df; - dfa.from.add(dynamic_left_outer_join(bar).on(bar.alpha > foo.omega)); - compare(__LINE__, dfa, " FROM tab_foo LEFT OUTER JOIN tab_bar ON (tab_bar.alpha>tab_foo.omega)"); - } - { - auto dfa = df; - dfa.from.add(dynamic_right_outer_join(bar).on(bar.alpha > foo.omega)); - compare(__LINE__, dfa, " FROM tab_foo RIGHT OUTER JOIN tab_bar ON (tab_bar.alpha>tab_foo.omega)"); - } - { - auto dfa = df; - dfa.from.add(dynamic_join(bar).unconditionally()); - compare(__LINE__, dfa, " FROM tab_foo INNER JOIN tab_bar"); - } - { - auto dfa = df; - dfa.from.add(dynamic_inner_join(bar).on(bar.alpha > foo.omega)); - dfa.from.add(dynamic_outer_join(aFoo).on(without_table_check(bar.alpha > aFoo.omega))); - compare(__LINE__, dfa, " FROM tab_foo INNER JOIN tab_bar ON (tab_bar.alpha>tab_foo.omega) OUTER JOIN tab_foo AS a " - "ON (tab_bar.alpha>a.omega)"); - } - - // Dynamic joins involving verbatim table - { - auto dfa = df; - dfa.from.add( - dynamic_inner_join(sqlpp::verbatim_table("unknown_table")) - .on(without_table_check(bar.alpha > sqlpp::verbatim("unknown_table.column_x")))); - compare(__LINE__, dfa, " FROM tab_foo INNER JOIN unknown_table ON (tab_bar.alpha>unknown_table.column_x)"); - } - +#warning add tests for optional joins return 0; } diff --git a/tests/core/serialize/SelectColumns.cpp b/tests/core/serialize/SelectColumns.cpp new file mode 100644 index 00000000..8cb4618d --- /dev/null +++ b/tests/core/serialize/SelectColumns.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2024, 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. + */ + +#include "compare.h" +#include "Sample.h" +#include + +int SelectColumns(int, char*[]) +{ + const auto foo = test::TabFoo{}; + const auto bar = test::TabBar{}; + + // Single column + compare(__LINE__, select(foo.omega), "SELECT tab_foo.omega"); + + // Two columns + compare(__LINE__, select(foo.omega, bar.alpha), "SELECT tab_foo.omega,tab_bar.alpha"); + + // All columns of a table + compare(__LINE__, select(all_of(foo)), "SELECT tab_foo.delta,tab_foo.epsilon,tab_foo.omega,tab_foo.psi,tab_foo.book"); + + // All columns of a table plus one more + compare(__LINE__, select(all_of(foo), bar.alpha), "SELECT tab_foo.delta,tab_foo.epsilon,tab_foo.omega,tab_foo.psi,tab_foo.book,tab_bar.alpha"); + + // One more, plus all columns of a table + compare(__LINE__, select(bar.alpha, all_of(foo)), "SELECT tab_bar.alpha,tab_foo.delta,tab_foo.epsilon,tab_foo.omega,tab_foo.psi,tab_foo.book"); + + // Column and aggregate function + compare(__LINE__, select(foo.omega, count(bar.alpha)), "SELECT tab_foo.omega,COUNT(tab_bar.alpha) AS count_"); + + // Column aliases + compare(__LINE__, select(foo.omega.as(sqlpp::alias::o), count(bar.alpha).as(sqlpp::alias::a)), "SELECT tab_foo.omega AS o,COUNT(tab_bar.alpha) AS a"); + +#warning: add optional column tests + + return 0; +} diff --git a/tests/core/usage/BooleanExpression.cpp b/tests/core/serialize/SelectFlags.cpp similarity index 71% rename from tests/core/usage/BooleanExpression.cpp rename to tests/core/serialize/SelectFlags.cpp index 2e84c5d8..be8d6996 100644 --- a/tests/core/usage/BooleanExpression.cpp +++ b/tests/core/serialize/SelectFlags.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2024, Roland Bock * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -23,22 +23,29 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include "compare.h" #include "Sample.h" -#include "MockDb.h" #include -int BooleanExpression(int, char*[]) +int SelectFlags(int, char*[]) { - MockDb db = {}; - const auto t = test::TabBar{}; + const auto foo = test::TabFoo{}; + const auto bar = test::TabBar{}; - auto x = boolean_expression(db, not(t.alpha == 7)); - x = sqlpp::boolean_expression(db, true); - x = sqlpp::boolean_expression(t.beta.like("%cheesecake")); - x = x and boolean_expression(db, t.gamma); + // No flags + compare(__LINE__, select(foo.omega), "SELECT tab_foo.omega"); - db(select(t.alpha).from(t).where(x)); + // No flags +#warning: This should work + //compare(__LINE__, sqlpp::select_flags(), ""); + + // No flags + compare(__LINE__, select(foo.omega).flags(sqlpp::distinct), "SELECT DISTINCT tab_foo.omega"); + + // One flag + compare(__LINE__, select_flags(sqlpp::distinct), "DISTINCT "); + +#warning: Add tests for dynamic select flags return 0; } diff --git a/tests/core/static_asserts/from.cpp b/tests/core/static_asserts/from.cpp index c4acab06..4bd3885d 100644 --- a/tests/core/static_asserts/from.cpp +++ b/tests/core/static_asserts/from.cpp @@ -58,21 +58,6 @@ namespace static_assert(ExpectedReturnType::value, "Unexpected return type"); } - template - void from_dynamic_check(const Expression& expression) - { - static auto db = MockDb{}; - using CheckResult = sqlpp::check_from_dynamic_t; - using ExpectedCheckResult = std::is_same; - print_type_on_error(ExpectedCheckResult{}); - 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>; - print_type_on_error(ExpectedReturnType{}); - static_assert(ExpectedReturnType::value, "Unexpected return type"); - } - void static_from() { // OK @@ -90,80 +75,10 @@ namespace // Try cross joins (missing condition) from_static_check(t.join(f)); } - - void dynamic_from() - { - // OK - from_dynamic_check(t); - from_dynamic_check(t.cross_join(f)); - from_dynamic_check(t.join(f).on(t.alpha > f.omega)); - - // Try a bunch of non-tables - from_dynamic_check(7); - from_dynamic_check(t.alpha); - from_dynamic_check(t.beta); - from_dynamic_check(t.gamma); - from_dynamic_check(t.delta); - - // Try cross joins (missing condition) - from_dynamic_check(t.join(f)); - } - - template - void dynamic_from_add_check(FromImpl from, const Expression& expression) - { - using CheckResult = sqlpp::check_from_add_t; - using ExpectedCheckResult = std::is_same; - print_type_on_error(ExpectedCheckResult{}); - static_assert(ExpectedCheckResult::value, "Unexpected check result"); - - using ReturnType = decltype(from.add(expression)); - using ExpectedReturnType = sqlpp::logic::all_t::value>; - print_type_on_error(ExpectedReturnType{}); - static_assert(ExpectedReturnType::value, "Unexpected return type"); - } - - void dynamic_from_add() - { - static auto db = MockDb{}; - auto fromT = dynamic_select(db, t.alpha).dynamic_from(t).from; - auto staticFrom = dynamic_select(db, t.alpha).from(t).from; - const auto fa = f.as(sqlpp::alias::a); - - // OK - dynamic_from_add_check(fromT, dynamic_join(f).on(t.alpha > f.omega)); - dynamic_from_add_check(fromT, dynamic_inner_join(f).on(t.alpha > f.omega)); - dynamic_from_add_check(fromT, dynamic_left_outer_join(f).on(t.alpha > f.omega)); - dynamic_from_add_check(fromT, dynamic_right_outer_join(f).on(t.alpha > f.omega)); - dynamic_from_add_check(fromT, dynamic_outer_join(f).on(t.alpha > f.omega)); - dynamic_from_add_check(fromT, dynamic_cross_join(f)); - - // Try a bunch of non dynamic joins - dynamic_from_add_check(staticFrom, 7); - - // Try a bunch of non dynamic joins - dynamic_from_add_check(fromT, 7); - dynamic_from_add_check(fromT, t.gamma); - dynamic_from_add_check(fromT, join(f, f.as(sqlpp::alias::a))); - - // Try incomplete dynamic join - dynamic_from_add_check(fromT, dynamic_join(f)); - - // Try joining the same table name - dynamic_from_add_check(fromT, dynamic_cross_join(t)); - dynamic_from_add_check(fromT, dynamic_cross_join(f.as(t))); - - // Try joining with a condition that requires other tables - dynamic_from_add_check(fromT, dynamic_join(f).on(t.alpha > fa.omega)); - - // If you really think you know what you are doing, use without_table_check - dynamic_from_add_check(fromT, dynamic_join(f).on(t.alpha > without_table_check(fa.omega))); - } } int main(int, char* []) { static_from(); - dynamic_from(); - dynamic_from_add(); +#warning add tests for optional joins } diff --git a/tests/core/static_asserts/having.cpp b/tests/core/static_asserts/having.cpp index 514892b6..7c139b14 100644 --- a/tests/core/static_asserts/having.cpp +++ b/tests/core/static_asserts/having.cpp @@ -58,22 +58,6 @@ namespace static_assert(ExpectedReturnType::value, "Unexpected return type"); } - template - auto having_dynamic_check(const Expression& expression) -> void - { - static auto db = MockDb{}; - using CheckResult = sqlpp::check_having_dynamic_t; - using ExpectedCheckResult = std::is_same; - print_type_on_error(ExpectedCheckResult{}); - static_assert(ExpectedCheckResult::value, "Unexpected check result"); - - 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>; - print_type_on_error(ExpectedReturnType{}); - static_assert(ExpectedReturnType::value, "Unexpected return type"); - } - auto static_having() -> void { // OK @@ -103,46 +87,6 @@ namespace having_static_check(t.alpha.as(t.beta)); } - auto dynamic_having() -> void - { - // OK - having_dynamic_check(t.gamma); - having_dynamic_check(t.gamma == true); - - // OK using aggregate functions in having - having_dynamic_check(count(t.alpha) > 0); - having_dynamic_check(t.gamma and count(t.alpha) > 0); - having_dynamic_check(case_when(count(t.alpha) > 0).then(t.gamma).else_(not t.gamma)); - - // Try assignment as condition - having_dynamic_check(t.gamma = true); - - // Try non-boolean expression - having_dynamic_check(t.alpha); - - // Try builtin bool - having_dynamic_check(true); - having_dynamic_check(17 > 3); - - // Try some other types as expressions - having_dynamic_check("true"); - having_dynamic_check(17); - having_dynamic_check('c'); - having_dynamic_check(nullptr); - having_dynamic_check(t.alpha.as(t.beta)); - - // Try dynamic_having on a non-dynamic select - using CheckResult = sqlpp::check_having_dynamic_t; - using ExpectedCheckResult = std::is_same; - print_type_on_error(ExpectedCheckResult{}); - static_assert(ExpectedCheckResult::value, "Unexpected check result"); - - using ReturnType = decltype(select(all_of(t)).from(t).dynamic_having()); - using ExpectedReturnType = std::is_same; - print_type_on_error(ExpectedReturnType{}); - static_assert(ExpectedReturnType::value, "Unexpected return type"); - } - template auto static_consistency_check(const Statement statement, const HavingCondition condtion) -> void { @@ -188,6 +132,6 @@ namespace int main(int, char* []) { static_having(); - dynamic_having(); +#warning: Add tests with optional expressions? consistency_check(); } diff --git a/tests/core/static_asserts/insert.cpp b/tests/core/static_asserts/insert.cpp index 6df6d5c8..e573c43c 100644 --- a/tests/core/static_asserts/insert.cpp +++ b/tests/core/static_asserts/insert.cpp @@ -58,21 +58,6 @@ namespace static_assert(ExpectedReturnType::value, "Unexpected return type"); } - template - void set_dynamic_check(const Assignments&... assignments) - { - static auto db = MockDb{}; - using CheckResult = sqlpp::check_insert_dynamic_set_t; - using ExpectedCheckResult = std::is_same; - static_assert(ExpectedCheckResult::value, "Unexpected check result"); - print_type_on_error(ExpectedCheckResult{}); - - using ReturnType = decltype(dynamic_insert_into(db, t).dynamic_set(assignments...)); - using ExpectedReturnType = sqlpp::logic::all_t::value>; - static_assert(ExpectedReturnType::value, "Unexpected return type"); - print_type_on_error(ExpectedReturnType{}); - } - // column alpha is not allowed, column gamma is required void static_set() { @@ -113,61 +98,10 @@ namespace set_static_check(f.omega = 41, t.gamma = true); } - // column alpha is not allowed, column gamma is required - void dynamic_set() - { - // OK - set_dynamic_check(t.gamma = true); - set_dynamic_check(t.beta = "fortytwo", t.gamma = true); - set_dynamic_check(t.beta = "fortytwo", t.gamma = true, t.delta = 42); - set_dynamic_check(t.delta = 42, t.beta = "fortytwo", t.gamma = true); - set_dynamic_check(t.delta = 42, t.gamma = true, t.beta = "fortytwo"); - set_dynamic_check(t.gamma = true, t.delta = 42, t.beta = "fortytwo"); - - // Try setting alpha - set_dynamic_check(t.alpha = 17, t.beta = "whatever"); - set_dynamic_check(t.beta = "whatever", t.alpha = 17); - - // Omitting gamma is OK in the dynamic case, since we have to assume that it gets added later - set_dynamic_check(t.delta = 42); - set_dynamic_check(t.beta = "whatever"); - - // Same with no arguments - set_dynamic_check(); - - // Try none-assignment arguments - set_dynamic_check(t.delta == 42, t.delta = 42, t.beta = "fortytwo", - t.gamma = true); - set_dynamic_check(17, t.delta = 42, t.beta = "fortytwo", t.gamma = true); - set_dynamic_check(t.delta = 42, t.beta = "fortytwo", t.gamma = true, - "EEEK"); - - // Try duplicates - set_dynamic_check(t.delta = 41, t.delta = 42, t.beta = "fortytwo", - t.gamma = true); - set_dynamic_check(t.beta = "fortyone", t.delta = 41, t.beta = "fortytwo", - t.gamma = true); - set_dynamic_check(t.gamma = false, t.delta = 41, t.beta = "fortytwo", - t.gamma = true); - - // Try multiple tables - set_dynamic_check(f.omega = 41, t.gamma = true); - - // Try dynamic_set on a non-dynamic insert - using CheckResult = sqlpp::check_insert_dynamic_set_t; - using ExpectedCheckResult = std::is_same; - static_assert(ExpectedCheckResult::value, "Unexpected check result"); - print_type_on_error(ExpectedCheckResult{}); - - using ReturnType = decltype(insert_into(t).dynamic_set()); - using ExpectedReturnType = std::is_same; - static_assert(ExpectedReturnType::value, "Unexpected return type"); - print_type_on_error(ExpectedReturnType{}); - } } int main(int, char* []) { static_set(); - dynamic_set(); +#warning add tests with optional expressions } diff --git a/tests/core/static_asserts/join.cpp b/tests/core/static_asserts/join.cpp index 2c4117ea..b857114a 100644 --- a/tests/core/static_asserts/join.cpp +++ b/tests/core/static_asserts/join.cpp @@ -173,107 +173,10 @@ namespace on_static_check(f_f, f.omega > fa.omega); } - template - void join_dynamic_check(const Table& table) - { - using CheckResult = sqlpp::check_dynamic_pre_join_t
; - using ExpectedCheckResult = std::is_same; - print_type_on_error(ExpectedCheckResult{}); - static_assert(ExpectedCheckResult::value, "Unexpected check result"); - - using JoinType = decltype(sqlpp::dynamic_join(table)); - using InnerJoinType = decltype(sqlpp::dynamic_inner_join(table)); - using LeftOuterJoinType = decltype(sqlpp::dynamic_left_outer_join(table)); - 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)>; - print_type_on_error(ExpectedReturnType{}); - print_type_on_error(ExpectedReturnType{}); - print_type_on_error(ExpectedReturnType{}); - print_type_on_error(ExpectedReturnType{}); - print_type_on_error(ExpectedReturnType{}); - print_type_on_error(ExpectedReturnType{}); - static_assert(ExpectedReturnType::value, "Unexpected return type"); - } - - template - void on_dynamic_check(const Lhs& lhs, const Rhs& rhs) - { - using CheckResult = sqlpp::check_dynamic_join_on_t; - using ExpectedCheckResult = std::is_same; - print_type_on_error(ExpectedCheckResult{}); - static_assert(ExpectedCheckResult::value, "Unexpected check result"); - - 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>; - print_type_on_error(ExpectedReturnType{}); - static_assert(ExpectedReturnType::value, "Unexpected return type"); - } - - void dynamic_join() - { - // Prepare a few table aliases for tests - const auto ta = t.as(sqlpp::alias::a); - const auto fa = f.as(sqlpp::alias::a); - - // OK - join_dynamic_check(t); - join_dynamic_check(f); - join_dynamic_check(ta); - join_dynamic_check(fa); - join_dynamic_check(sqlpp::verbatim_table("tab_sample")); - join_dynamic_check(sqlpp::verbatim_table("tab_sample").as(sqlpp::alias::a)); - - // Try a bunch of non-tables - join_dynamic_check(7); - join_dynamic_check(t.alpha); - join_dynamic_check(t.beta); - join_dynamic_check(t.gamma); - join_dynamic_check(t.delta); - - // Try (pre) joins - join_dynamic_check(t.join(f)); - join_dynamic_check(t.cross_join(f)); - - // Prepare a dynamic_pre_joins for tests: - const auto tj = dynamic_join(t); - const auto fj = dynamic_join(f); - const auto vj = dynamic_join(sqlpp::verbatim_table("tab_sample")); - - // OK dynamic_join.on() - on_dynamic_check(tj, t.alpha > f.omega); - on_dynamic_check(fj, t.alpha < f.omega); - - // Try dynamic_join.on(non-expression) - on_dynamic_check(tj, true); - on_dynamic_check(tj, 7); - on_dynamic_check(tj, t); - - // Try dynamic_join.on(non-boolean) - on_dynamic_check(tj, t.alpha); - on_dynamic_check(tj, t.beta); - on_dynamic_check(tj, f.omega); - - // OK dynamic_join.on(foreign-table) - on_dynamic_check(tj, ta.alpha != 0); - on_dynamic_check(tj, t.gamma); - on_dynamic_check(tj, f.omega > fa.omega); - on_dynamic_check(vj, t.alpha < f.omega); - } } int main(int, char* []) { static_join(); - dynamic_join(); +#warning add tests for optional from } diff --git a/tests/core/static_asserts/update_list.cpp b/tests/core/static_asserts/update_list.cpp index 56cb666f..d8e7d88c 100644 --- a/tests/core/static_asserts/update_list.cpp +++ b/tests/core/static_asserts/update_list.cpp @@ -58,21 +58,6 @@ namespace static_assert(ExpectedReturnType::value, "Unexpected return type"); } - template - void update_set_dynamic_check(const Expressions&... expressions) - { - static auto db = MockDb{}; - using CheckResult = sqlpp::check_update_dynamic_set_t; - using ExpectedCheckResult = std::is_same; - print_type_on_error(ExpectedCheckResult{}); - static_assert(ExpectedCheckResult::value, "Unexpected check result"); - - using ReturnType = decltype(dynamic_update(db, t).dynamic_set(expressions...)); - using ExpectedReturnType = sqlpp::logic::all_t::value>; - print_type_on_error(ExpectedReturnType{}); - static_assert(ExpectedReturnType::value, "Unexpected return type"); - } - void static_update_set() { // OK @@ -96,43 +81,10 @@ namespace update_set_static_check(t.gamma = true, f.omega = 7); } - void dynamic_update_set() - { - // OK - update_set_dynamic_check(t.gamma = true); - update_set_dynamic_check(t.gamma = true, t.beta = ""); - - // Try to update nothing - update_set_dynamic_check(); - - // Try condition as assignment - update_set_dynamic_check(t.gamma == true); - - // Try duplicate columns - update_set_dynamic_check(t.gamma = true, t.gamma = false); - update_set_dynamic_check(t.gamma = true, t.beta = "", t.gamma = false); - - // Try to update prohibited columns - update_set_dynamic_check(t.alpha = 42); - - // Try to update multiple tables at once - update_set_dynamic_check(t.gamma = true, f.omega = 7); - - // Try dynamic_set on a non-dynamic update - using CheckResult = sqlpp::check_update_dynamic_set_t; - using ExpectedCheckResult = std::is_same; - print_type_on_error(ExpectedCheckResult{}); - static_assert(ExpectedCheckResult::value, "Unexpected check result"); - - using ReturnType = decltype(update(t).dynamic_set()); - using ExpectedReturnType = std::is_same; - print_type_on_error(ExpectedReturnType{}); - static_assert(ExpectedReturnType::value, "Unexpected return type"); - } } int main(int, char* []) { static_update_set(); - dynamic_update_set(); +#warning: add tests with optional } diff --git a/tests/core/static_asserts/where.cpp b/tests/core/static_asserts/where.cpp index e437d2f8..3a0728ac 100644 --- a/tests/core/static_asserts/where.cpp +++ b/tests/core/static_asserts/where.cpp @@ -57,22 +57,7 @@ namespace static_assert(ExpectedReturnType::value, "Unexpected return type"); } - template - void where_dynamic_check(const Expression& expression) - { - static auto db = MockDb{}; - using CheckResult = sqlpp::check_where_dynamic_t; - using ExpectedCheckResult = std::is_same; - print_type_on_error(ExpectedCheckResult{}); - 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>; - print_type_on_error(ExpectedReturnType{}); - static_assert(ExpectedReturnType::value, "Unexpected return type"); - } - - void static_where() + void static_where() { // OK where_static_check(t.gamma); @@ -102,50 +87,10 @@ namespace case_when(count(t.alpha) > 0).then(t.gamma).else_(not t.gamma)); } - void dynamic_where() - { - // OK - where_dynamic_check(t.gamma); - where_dynamic_check(t.gamma == true); - - // Try assignment as condition - where_dynamic_check(t.gamma = true); - - // Try non-boolean expression - where_dynamic_check(t.alpha); - - // Try builtin bool - where_dynamic_check(true); - where_dynamic_check(17 > 3); - - // Try some other types as expressions - where_dynamic_check("true"); - where_dynamic_check(17); - where_dynamic_check('c'); - where_dynamic_check(nullptr); - where_dynamic_check(t.alpha.as(t.beta)); - - // Try using aggregate functions in where - where_dynamic_check(count(t.alpha) > 0); - where_dynamic_check(t.gamma and count(t.alpha) > 0); - where_dynamic_check( - case_when(count(t.alpha) > 0).then(t.gamma).else_(not t.gamma)); - - // Try dynamic_where on a non-dynamic remove - using CheckResult = sqlpp::check_where_dynamic_t; - using ExpectedCheckResult = std::is_same; - print_type_on_error(ExpectedCheckResult{}); - static_assert(ExpectedCheckResult::value, "Unexpected check result"); - - using ReturnType = decltype(remove_from(t).dynamic_where()); - using ExpectedReturnType = std::is_same; - print_type_on_error(ExpectedReturnType{}); - static_assert(ExpectedReturnType::value, "Unexpected return type"); - } } int main(int, char* []) { static_where(); - dynamic_where(); +#warning: Add test with optional expressions? } diff --git a/tests/core/usage/CMakeLists.txt b/tests/core/usage/CMakeLists.txt index cd0c3fac..93770454 100644 --- a/tests/core/usage/CMakeLists.txt +++ b/tests/core/usage/CMakeLists.txt @@ -30,7 +30,6 @@ if (NOT MSVC) endif () set(test_files - BooleanExpression.cpp CustomQuery.cpp DateTime.cpp DateTimeParser.cpp diff --git a/tests/core/usage/Insert.cpp b/tests/core/usage/Insert.cpp index 91f7c8bf..65d84bba 100644 --- a/tests/core/usage/Insert.cpp +++ b/tests/core/usage/Insert.cpp @@ -50,11 +50,6 @@ int Insert(int, char*[]) static_assert(sqlpp::is_regular::value, "type requirement"); } - { - using T = decltype(dynamic_insert_into(db, t).dynamic_set()); - static_assert(sqlpp::is_regular::value, "type requirement"); - } - db(insert_into(t).default_values()); db(insert_into(t).set(t.gamma = true, t.beta = "kirschauflauf")); db(insert_into(t).set(t.gamma = sqlpp::default_value, t.beta = sqlpp::value_or_null("pie"), @@ -82,10 +77,7 @@ int Insert(int, char*[]) multi_time_insert.values.add(tabDateTime.colTimePoint = std::chrono::time_point_cast( std::chrono::system_clock::now())); - auto i = dynamic_insert_into(db, t).dynamic_set(); - i.insert_list.add(t.beta = "kirschauflauf"); - printer.reset(); - std::cerr << serialize(i, printer).str() << std::endl; +#warning add tests with optional db(multi_insert); diff --git a/tests/core/usage/Interpret.cpp b/tests/core/usage/Interpret.cpp index a0cbbb30..8f20d31f 100644 --- a/tests/core/usage/Interpret.cpp +++ b/tests/core/usage/Interpret.cpp @@ -139,29 +139,6 @@ int Interpret(int, char* []) serialize(select(t.alpha).from(inner), printer).str(); } - // dynamic select - { - auto s = dynamic_select(db).dynamic_flags().dynamic_columns().from(t); - s.selected_columns.add(t.beta); - s.selected_columns.add(t.gamma); - serialize(s, printer).str(); - } - { - auto s = dynamic_select(db).dynamic_flags().dynamic_columns().from(t); - s.select_flags.add(sqlpp::distinct); - s.selected_columns.add(t.beta); - s.selected_columns.add(t.gamma); - serialize(s, printer).str(); - } - { - // 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(without_table_check(t.beta)); - s.selected_columns.add(without_table_check(t.gamma)); - serialize(s, printer).str(); - } - // distinct aggregate serialize(count(sqlpp::distinct, t.alpha % 7), printer).str(); serialize(avg(sqlpp::distinct, t.alpha - 7), printer).str(); @@ -181,13 +158,6 @@ int Interpret(int, char* []) flatten(t.alpha == 7, db); - auto x = boolean_expression(db, t.alpha == 7); - x = sqlpp::boolean_expression(t.beta.like("%cheesecake")); - x = x and boolean_expression(db, t.gamma); - std::cerr << "----------------------------" << std::endl; - printer.reset(); - std::cerr << serialize(x, printer).str() << std::endl; - printer.reset(); std::cerr << serialize(select(all_of(t)).from(t).where(t.alpha.in(select(f.epsilon).from(f).unconditionally())), printer) diff --git a/tests/core/usage/Remove.cpp b/tests/core/usage/Remove.cpp index c3fd6bbc..e4ab8193 100644 --- a/tests/core/usage/Remove.cpp +++ b/tests/core/usage/Remove.cpp @@ -47,25 +47,14 @@ int Remove(int, char* []) static_assert(sqlpp::is_regular::value, "type requirement"); } - { - using T = decltype(dynamic_remove_from(db, t).dynamic_using().dynamic_where()); - static_assert(sqlpp::is_regular::value, "type requirement"); - } - serialize(remove_from(t), printer).str(); serialize(remove_from(t).where(t.beta != "transparent"), printer).str(); serialize(remove_from(t).using_(t), printer).str(); serialize(remove_from(t).using_(f), printer).str(); - auto r = dynamic_remove_from(db, t).dynamic_using().dynamic_where(); - r.using_.add(t); - r.where.add(t.beta != "transparent"); - printer.reset(); - std::cerr << serialize(r, printer).str() << std::endl; +#warning: add tests with optional using and optional where printer.reset(); std::cerr << serialize(remove_from(t).unconditionally(), printer).str() << std::endl; - db(r); - remove_from(t).where(t.beta.in(select(f.delta).from(f).unconditionally())); return 0; diff --git a/tests/core/usage/Select.cpp b/tests/core/usage/Select.cpp index 176ea1ba..bfedf4d0 100644 --- a/tests/core/usage/Select.cpp +++ b/tests/core/usage/Select.cpp @@ -141,41 +141,17 @@ int Select(int, char*[]) printer.reset(); std::cerr << serialize(stat, printer).str() << std::endl; - auto s0 = dynamic_select(db) - .columns(all_of(t)) - .flags(sqlpp::all) - .from(t) - .where(t.alpha > 0) - .group_by(t.alpha) - .order_by(t.gamma.asc()) - .having(t.gamma) - .limit(7u) - .offset(19u); - - printer.reset(); - std::cerr << serialize(s0, printer).str() << std::endl; - - auto s = dynamic_select(db) - .dynamic_columns(all_of(t)) - .dynamic_flags() - .dynamic_from(t) - .dynamic_where() - .dynamic_group_by(t.alpha) - .dynamic_order_by() - .dynamic_having(sum(t.alpha) > parameter(t.delta)) - .dynamic_limit() - .dynamic_offset(); - s.select_flags.add(sqlpp::distinct); - s.selected_columns.add(without_table_check(f.omega)); - s.selected_columns.add(select(f.omega).from(f).unconditionally().as(f.delta)); - s.from.add(dynamic_cross_join(f)); - s.where.add(t.alpha > 7); - s.having.add(t.alpha > 7); - s.limit.set(3u); - s.offset.set(3u); - s.group_by.add(t.beta); - s.order_by.add(t.beta.asc()); - s.order_by.add(t.delta.order(sqlpp::sort_type::desc)); + auto s = sqlpp::select() + .columns(t.alpha) + .flags(sqlpp::distinct) + .from(t) + .where(t.alpha > 3) + .group_by(t.alpha) + .order_by(t.beta.asc()) + .having(sum(t.alpha) > parameter(t.delta)) + .limit(32u) + .offset(7u); +#warning add tests for optional everything for (const auto& row : db(db.prepare(s))) { const sqlpp::optional a = row.alpha; diff --git a/tests/core/usage/SelectType.cpp b/tests/core/usage/SelectType.cpp index e61c8259..2754346e 100644 --- a/tests/core/usage/SelectType.cpp +++ b/tests/core/usage/SelectType.cpp @@ -350,6 +350,8 @@ int SelectType(int, char*[]) std::cout << a << std::endl; } +#warning add tests for dynamic everything. + /* { auto s = dynamic_select(db, all_of(t)).dynamic_from(t).dynamic_where().dynamic_limit().dynamic_offset(); s.from.add(dynamic_join(f).on(f.omega > t.alpha)); @@ -375,6 +377,7 @@ int SelectType(int, char*[]) find_query.from.add(sqlpp::dynamic_join(f).on(t.alpha == f.omega)); find_query.selected_columns.add(sqlpp::without_table_check(f.omega.as(alias::b))); } + */ // Test that verbatim_table compiles { diff --git a/tests/core/usage/Update.cpp b/tests/core/usage/Update.cpp index fb4c522e..39e5b036 100644 --- a/tests/core/usage/Update.cpp +++ b/tests/core/usage/Update.cpp @@ -46,25 +46,14 @@ int Update(int, char*[]) static_assert(sqlpp::is_regular::value, "type requirement"); } - { - using T = decltype(dynamic_update(db, t).dynamic_set(t.gamma = false).dynamic_where()); - static_assert(sqlpp::is_regular::value, "type requirement"); - } - serialize(update(t), printer).str(); serialize(update(t).set(t.gamma = false), printer).str(); serialize(update(t).set(t.gamma = false).where(t.beta != "transparent"), printer).str(); serialize(update(t).set(t.beta = "opaque").where(t.beta != t.beta + "this is nonsense"), printer).str(); - auto u = dynamic_update(db, t).dynamic_set(t.gamma = false).dynamic_where(); - u.assignments.add(t.beta = "cannot update gamma a second time"); - u.where.add(t.gamma != false); - printer.reset(); - std::cerr << serialize(u, printer).str() << std::endl; - - db(u); - auto values = [&t]() { return std::make_tuple(t.delta += t.alpha, t.beta = "no cake this time"); }; +#warning add tests with dynamic set and dynamic where + db(update(t).set(t.delta = sqlpp::verbatim("17+4")).unconditionally()); db(update(t) .set(t.delta = sqlpp::verbatim("17+4"))