From c0ad5e06964ca124d1b72d213ee02442a1653949 Mon Sep 17 00:00:00 2001 From: Roland Bock Date: Sun, 25 Aug 2024 12:07:46 +0200 Subject: [PATCH] A bit of cleanup --- include/sqlpp11/core/basic/join.h | 8 +- include/sqlpp11/core/detail/type_set.h | 1 - include/sqlpp11/core/query/statement.h | 2 +- include/sqlpp11/core/type_traits.h | 62 +------------ include/sqlpp11/core/type_traits/tables_of.h | 95 ++++++++++++++++++++ include/sqlpp11/core/value_type_fwd.h | 53 ----------- tests/core/types/basic/join.cpp | 6 +- 7 files changed, 107 insertions(+), 120 deletions(-) create mode 100644 include/sqlpp11/core/type_traits/tables_of.h delete mode 100644 include/sqlpp11/core/value_type_fwd.h diff --git a/include/sqlpp11/core/basic/join.h b/include/sqlpp11/core/basic/join.h index e7e7b31b..a4ae1657 100644 --- a/include/sqlpp11/core/basic/join.h +++ b/include/sqlpp11/core/basic/join.h @@ -58,7 +58,13 @@ namespace sqlpp }; template - struct provided_outer_tables_of> + struct provided_tables_of, Condition>> + { + using type = detail::make_joined_set_t, detail::type_set>>; + }; + + template + struct provided_optional_tables_of> { using type = typename std::conditional< std::is_same::value, diff --git a/include/sqlpp11/core/detail/type_set.h b/include/sqlpp11/core/detail/type_set.h index f00ff4ec..27b7665b 100644 --- a/include/sqlpp11/core/detail/type_set.h +++ b/include/sqlpp11/core/detail/type_set.h @@ -63,7 +63,6 @@ namespace sqlpp public: using size = std::integral_constant; - using _is_type_set = std::true_type; template static constexpr bool count() diff --git a/include/sqlpp11/core/query/statement.h b/include/sqlpp11/core/query/statement.h index 64e4fecc..cb838878 100644 --- a/include/sqlpp11/core/query/statement.h +++ b/include/sqlpp11/core/query/statement.h @@ -79,7 +79,7 @@ namespace sqlpp using _all_provided_ctes = detail::make_joined_set_t...>; using _all_required_tables = detail::make_joined_set_t...>; using _all_provided_tables = detail::make_joined_set_t...>; - using _all_provided_outer_tables = detail::make_joined_set_t...>; + using _all_provided_outer_tables = detail::make_joined_set_t...>; using _all_provided_aggregates = detail::make_joined_set_t...>; template diff --git a/include/sqlpp11/core/type_traits.h b/include/sqlpp11/core/type_traits.h index 0dc4e062..624f0279 100644 --- a/include/sqlpp11/core/type_traits.h +++ b/include/sqlpp11/core/type_traits.h @@ -46,6 +46,7 @@ #include #include #include +#include namespace sqlpp { @@ -305,67 +306,6 @@ namespace sqlpp template using rhs_t = typename rhs::type; - // Anything that directly requires a table (e.g. a column) has to specialize required_tables_of. - template - struct required_tables_of - { - using type = typename required_tables_of>::type; - }; - - template - struct required_tables_of> - { - using type = detail::make_joined_set_t::type...>; - }; - - template - using required_tables_of_t = typename required_tables_of::type; - - static_assert(required_tables_of_t::size::value == 0, ""); - - template - struct provided_tables_of - { - using type = typename provided_tables_of>::type; - }; - - template - struct provided_tables_of> - { - using type = detail::make_joined_set_t::type...>; - }; - - template - using provided_tables_of_t = typename provided_tables_of::type; - - static_assert(provided_tables_of_t::size::value == 0, ""); - - template - struct provided_outer_tables_of - { - using type = typename provided_outer_tables_of>::type; - }; - - template - struct provided_outer_tables_of> - { - using type = detail::make_joined_set_t::type...>; - }; - - template - using provided_outer_tables_of_t = typename provided_outer_tables_of::type; - - static_assert(provided_outer_tables_of_t::size::value == 0, ""); - - template - struct is_valid_operand - { - static constexpr bool value = - is_expression_t::value // expressions are OK - and ValueType::template _is_valid_operand::value // the correct value type is required, of course - ; - }; - #warning: This should go away namespace detail { diff --git a/include/sqlpp11/core/type_traits/tables_of.h b/include/sqlpp11/core/type_traits/tables_of.h new file mode 100644 index 00000000..0ef8f40c --- /dev/null +++ b/include/sqlpp11/core/type_traits/tables_of.h @@ -0,0 +1,95 @@ +#pragma once + +/* + * 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 +#include +#include + +namespace sqlpp +{ + // required_tables_of determines the type_set of tables referenced by columns within within T. + // column_t or other structs that might reference a table shall specialize this template to indicate their table + // requirement. + // Dynamic parts of a query shall wrap their required tables in dynamic_t. + template + struct required_tables_of + { + using type = typename required_tables_of>::type; + }; + + template + struct required_tables_of> + { + using type = detail::make_joined_set_t::type...>; + }; + + template + using required_tables_of_t = typename required_tables_of::type; + +#warning: need type tests... + //static_assert(required_tables_of_t::size::value == 0, ""); + + // provided_tables_of determines the type_set of tables provided by the query clause, e.g. by FROM. + // Provided tables can be wrapped in dynamic_t if they are provided through a dynamic join. + // table_t, cte_ref_t, or other structs that might provide a table in a query need to specialize this template. + template + struct provided_tables_of + { + using type = typename provided_tables_of>::type; + }; + + template + struct provided_tables_of> + { + using type = detail::make_joined_set_t::type...>; + }; + + template + using provided_tables_of_t = typename provided_tables_of::type; + + static_assert(provided_tables_of_t::size::value == 0, ""); + + // provided_optional_tables_of is similar to provided_tables_of but only references the tables that have optional + // rows in outer joins (e.g. the right hand side table in a LEFT OUTER JOIN). + template + struct provided_optional_tables_of + { + using type = typename provided_optional_tables_of>::type; + }; + + template + struct provided_optional_tables_of> + { + using type = detail::make_joined_set_t::type...>; + }; + + template + using provided_optional_tables_of_t = typename provided_optional_tables_of::type; + +} // namespace sqlpp + diff --git a/include/sqlpp11/core/value_type_fwd.h b/include/sqlpp11/core/value_type_fwd.h deleted file mode 100644 index c9457024..00000000 --- a/include/sqlpp11/core/value_type_fwd.h +++ /dev/null @@ -1,53 +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 - -namespace sqlpp -{ - template - struct is_valid_assignment_operand - { - static constexpr bool value = - is_expression_t::value // expressions are OK - and ValueType::template _is_valid_operand::value // the correct value type is required, of course - ; - }; - - template - struct is_valid_assignment_operand< - ValueType, - T, - typename std::enable_if>::value>::type> - { - static constexpr bool value = - is_expression_t::value // expressions are OK - and ValueType::template _is_valid_assignment_operand::value // the correct value type is required, of course - ; - }; -} // namespace sqlpp diff --git a/tests/core/types/basic/join.cpp b/tests/core/types/basic/join.cpp index 970fb306..1f7b1906 100644 --- a/tests/core/types/basic/join.cpp +++ b/tests/core/types/basic/join.cpp @@ -42,7 +42,7 @@ void test_group_by() static_assert( std::is_same, sqlpp::detail::type_set>::value, ""); static_assert( - std::is_same, sqlpp::detail::type_set<>>::value, ""); + std::is_same, sqlpp::detail::type_set<>>::value, ""); #warning: test the provided dynamic tables of? } @@ -52,7 +52,7 @@ void test_group_by() static_assert( std::is_same, sqlpp::detail::type_set>::value, ""); static_assert( - std::is_same, sqlpp::detail::type_set>::value, ""); + std::is_same, sqlpp::detail::type_set>::value, ""); #warning: test the provided dynamic tables of? } @@ -64,7 +64,7 @@ void test_group_by() std::is_same, sqlpp::detail::type_set>::value, ""); #warning: OUTER is the wrong term. In a left-outer join, the *right* table is the one with optional rows. static_assert( - std::is_same, sqlpp::detail::type_set<>>::value, ""); + std::is_same, sqlpp::detail::type_set<>>::value, ""); #warning: test the provided dynamic tables of? }