From cf9ec10ae4aabf2769c74ce1e3fa6e99f56c505e Mon Sep 17 00:00:00 2001 From: rbock Date: Tue, 22 Mar 2016 09:23:37 +0100 Subject: [PATCH] Added table checks for dynamic_join(x).add(y) --- include/sqlpp11/dynamic_join.h | 2 +- include/sqlpp11/from.h | 4 ++++ test_static_asserts/from.cpp | 5 +++++ test_static_asserts/join.cpp | 4 ++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/sqlpp11/dynamic_join.h b/include/sqlpp11/dynamic_join.h index 5aa9b7a1..fc7e742d 100644 --- a/include/sqlpp11/dynamic_join.h +++ b/include/sqlpp11/dynamic_join.h @@ -38,7 +38,7 @@ namespace sqlpp using _nodes = detail::type_vector; using _can_be_null = std::false_type; using _provided_tables = provided_tables_of; - using _required_tables = detail::type_set<>; + 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"); diff --git a/include/sqlpp11/from.h b/include/sqlpp11/from.h index 6a50bea8..e778e1fc 100644 --- a/include/sqlpp11/from.h +++ b/include/sqlpp11/from.h @@ -91,6 +91,10 @@ namespace sqlpp using _joined_table_names = detail::make_name_of_set_t<_joined_tables>; static_assert(detail::is_disjunct_from<_joined_table_names, _known_table_names>::value, "Must not use the same table name twice in from()"); + using _required_tables = required_tables_of; + static_assert(detail::is_subset_of<_required_tables, _known_tables>::value, + "dynamic join condition depends on tables not statically known, use without_table_check() to " + "express the intent"); using _serialize_check = sqlpp::serialize_check_t; _serialize_check::_(); diff --git a/test_static_asserts/from.cpp b/test_static_asserts/from.cpp index fff9d433..59453781 100644 --- a/test_static_asserts/from.cpp +++ b/test_static_asserts/from.cpp @@ -110,6 +110,11 @@ namespace // Try cross joins (missing condition) from_dynamic_check(t.join(f)); } + + void dynamic_from() + { +#warning : need to add tests for dynamic_from(xxx).add(yyy) + } } int main(int, char* []) diff --git a/test_static_asserts/join.cpp b/test_static_asserts/join.cpp index 29369ed3..e25fef2d 100644 --- a/test_static_asserts/join.cpp +++ b/test_static_asserts/join.cpp @@ -237,6 +237,8 @@ namespace 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); @@ -252,6 +254,7 @@ namespace // 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); @@ -271,6 +274,7 @@ namespace 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); } }