diff --git a/include/sqlpp11/core/basic/table.h b/include/sqlpp11/core/basic/table.h index f81b58d0..51397441 100644 --- a/include/sqlpp11/core/basic/table.h +++ b/include/sqlpp11/core/basic/table.h @@ -75,11 +75,6 @@ namespace sqlpp { }; - template - struct provided_optional_tables_of> : public provided_tables_of> - { - }; - template auto to_sql_string(Context& context, const table_t& /*unused*/) -> std::string { diff --git a/include/sqlpp11/core/clause/single_table.h b/include/sqlpp11/core/clause/single_table.h index 675da1b6..f795f2cd 100644 --- a/include/sqlpp11/core/clause/single_table.h +++ b/include/sqlpp11/core/clause/single_table.h @@ -90,7 +90,7 @@ namespace sqlpp template struct check_update_table { - using type = static_combined_check_t::value, assert_update_table_arg_is_table_t>>; + using type = static_combined_check_t::value, assert_update_table_arg_is_table_t>>; }; template using check_update_table_t = typename check_update_table::type; @@ -147,4 +147,10 @@ namespace sqlpp { return to_sql_string(context, t._table); } + + template + auto single_table(T&& t) -> decltype(statement_t().single_table(std::forward(t))) + { + return statement_t().single_table(std::forward(t)); + } } // namespace sqlpp diff --git a/include/sqlpp11/core/type_traits/aggregates.h b/include/sqlpp11/core/type_traits/aggregates.h index fa84a1ce..f8238310 100644 --- a/include/sqlpp11/core/type_traits/aggregates.h +++ b/include/sqlpp11/core/type_traits/aggregates.h @@ -76,7 +76,7 @@ namespace sqlpp struct is_aggregate_expression : public std::integral_constant::value or - KnownAggregateColumns::template contains::value> + KnownAggregateColumns::template contains()> { }; diff --git a/tests/core/types/CMakeLists.txt b/tests/core/types/CMakeLists.txt index 1e8392f5..9f737c4c 100644 --- a/tests/core/types/CMakeLists.txt +++ b/tests/core/types/CMakeLists.txt @@ -33,4 +33,10 @@ test_compile(result_row) test_compile(select_as) test_compile(value) +add_subdirectory(aggregate_function) add_subdirectory(basic) +add_subdirectory(clause) +add_subdirectory(detail) +add_subdirectory(operator) +add_subdirectory(type_traits) + diff --git a/tests/core/types/basic/join.cpp b/tests/core/types/basic/join.cpp index c74b745e..98fd219f 100644 --- a/tests/core/types/basic/join.cpp +++ b/tests/core/types/basic/join.cpp @@ -152,6 +152,7 @@ void test_group_by() #warning: Need to add tests with verbatim tables +#warning: Need to add tests with schema qualified tables #warning: Need to add tests with 3 tables #warning: Need to add tests with CTEs diff --git a/tests/core/types/basic/table.cpp b/tests/core/types/basic/table.cpp index d448ae96..5d5d35f6 100644 --- a/tests/core/types/basic/table.cpp +++ b/tests/core/types/basic/table.cpp @@ -37,7 +37,8 @@ void test_table() static_assert(std::is_same, test::TabFoo_::_sqlpp_name_tag>::value, ""); static_assert(std::is_same, sqlpp::detail::type_vector>::value, ""); static_assert(std::is_same, sqlpp::provided_tables_of_t>::value, ""); - static_assert(std::is_same, sqlpp::provided_tables_of_t>::value, ""); + // Only joins can provide optional tables. + static_assert(std::is_same, sqlpp::detail::type_vector<>>::value, ""); } int main() diff --git a/tests/core/types/clause/CMakeLists.txt b/tests/core/types/clause/CMakeLists.txt index a895c99c..1bd41fe8 100644 --- a/tests/core/types/clause/CMakeLists.txt +++ b/tests/core/types/clause/CMakeLists.txt @@ -29,5 +29,7 @@ function(test_compile name) endfunction() test_compile(group_by) +test_compile(into) test_compile(select_columns) +test_compile(single_table) diff --git a/tests/core/types/clause/into.cpp b/tests/core/types/clause/into.cpp new file mode 100644 index 00000000..1181f1dd --- /dev/null +++ b/tests/core/types/clause/into.cpp @@ -0,0 +1,63 @@ +/* + * 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 "Sample.h" +#include + +SQLPP_CREATE_NAME_TAG(cheese); + +template +void assert_invalid_argument(T t) +{ + using I = decltype(sqlpp::into(t)); + static_assert(std::is_same::value, ""); +} + +void test_into() +{ + auto v = sqlpp::value(17); + auto foo = test::TabFoo{}; + auto bar = test::TabBar{}; + using Foo = decltype(foo); + auto id = foo.id; + + // Valid into clause + { + using I = decltype(sqlpp::into(foo)); + static_assert(std::is_same, sqlpp::detail::type_vector>::value, ""); + static_assert(std::is_same, sqlpp::provided_tables_of_t>::value, ""); + static_assert(std::is_same, sqlpp::detail::type_vector<>>::value, ""); + } + + assert_invalid_argument(foo.join(bar)); + assert_invalid_argument(foo.as(cheese)); + assert_invalid_argument(id); +} + +int main() +{ + void test_into(); +} + diff --git a/tests/core/types/clause/single_table.cpp b/tests/core/types/clause/single_table.cpp new file mode 100644 index 00000000..882c8d84 --- /dev/null +++ b/tests/core/types/clause/single_table.cpp @@ -0,0 +1,63 @@ +/* + * 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 "Sample.h" +#include + +SQLPP_CREATE_NAME_TAG(cheese); + +template +void assert_invalid_argument(T t) +{ + using S = decltype(sqlpp::single_table(t)); + static_assert(std::is_same::value, ""); +} + +void test_single_table() +{ + auto v = sqlpp::value(17); + auto foo = test::TabFoo{}; + auto bar = test::TabBar{}; + using Foo = decltype(foo); + auto id = foo.id; + + // Valid single table clause + { + using S = decltype(sqlpp::single_table(foo)); + static_assert(std::is_same, sqlpp::detail::type_vector>::value, ""); + static_assert(std::is_same, sqlpp::provided_tables_of_t>::value, ""); + static_assert(std::is_same, sqlpp::detail::type_vector<>>::value, ""); + } + + assert_invalid_argument(foo.join(bar)); + assert_invalid_argument(foo.as(cheese)); + assert_invalid_argument(id); +} + +int main() +{ + void test_single_table(); +} +