mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 04:47:18 +08:00
Added table checks for dynamic_join(x).add(y)
This commit is contained in:
parent
ec81299259
commit
cf9ec10ae4
@ -38,7 +38,7 @@ namespace sqlpp
|
|||||||
using _nodes = detail::type_vector<PreJoin, On>;
|
using _nodes = detail::type_vector<PreJoin, On>;
|
||||||
using _can_be_null = std::false_type;
|
using _can_be_null = std::false_type;
|
||||||
using _provided_tables = provided_tables_of<PreJoin>;
|
using _provided_tables = provided_tables_of<PreJoin>;
|
||||||
using _required_tables = detail::type_set<>;
|
using _required_tables = detail::make_difference_set_t<required_tables_of<On>, _provided_tables>;
|
||||||
|
|
||||||
static_assert(is_dynamic_pre_join_t<PreJoin>::value, "lhs argument for on() has to be a pre join");
|
static_assert(is_dynamic_pre_join_t<PreJoin>::value, "lhs argument for on() has to be a pre join");
|
||||||
static_assert(required_tables_of<PreJoin>::size::value == 0, "joined tables must not depend on other tables");
|
static_assert(required_tables_of<PreJoin>::size::value == 0, "joined tables must not depend on other tables");
|
||||||
|
@ -91,6 +91,10 @@ namespace sqlpp
|
|||||||
using _joined_table_names = detail::make_name_of_set_t<_joined_tables>;
|
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,
|
static_assert(detail::is_disjunct_from<_joined_table_names, _known_table_names>::value,
|
||||||
"Must not use the same table name twice in from()");
|
"Must not use the same table name twice in from()");
|
||||||
|
using _required_tables = required_tables_of<DynamicJoin>;
|
||||||
|
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<typename Database::_serializer_context_t, DynamicJoin>;
|
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, DynamicJoin>;
|
||||||
_serialize_check::_();
|
_serialize_check::_();
|
||||||
|
|
||||||
|
@ -110,6 +110,11 @@ namespace
|
|||||||
// Try cross joins (missing condition)
|
// Try cross joins (missing condition)
|
||||||
from_dynamic_check<sqlpp::assert_from_not_pre_join_t>(t.join(f));
|
from_dynamic_check<sqlpp::assert_from_not_pre_join_t>(t.join(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dynamic_from()
|
||||||
|
{
|
||||||
|
#warning : need to add tests for dynamic_from(xxx).add(yyy)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int, char* [])
|
int main(int, char* [])
|
||||||
|
@ -237,6 +237,8 @@ namespace
|
|||||||
join_dynamic_check<sqlpp::consistent_t>(f);
|
join_dynamic_check<sqlpp::consistent_t>(f);
|
||||||
join_dynamic_check<sqlpp::consistent_t>(ta);
|
join_dynamic_check<sqlpp::consistent_t>(ta);
|
||||||
join_dynamic_check<sqlpp::consistent_t>(fa);
|
join_dynamic_check<sqlpp::consistent_t>(fa);
|
||||||
|
join_dynamic_check<sqlpp::consistent_t>(sqlpp::verbatim_table("tab_sample"));
|
||||||
|
join_dynamic_check<sqlpp::consistent_t>(sqlpp::verbatim_table("tab_sample").as(sqlpp::alias::a));
|
||||||
|
|
||||||
// Try a bunch of non-tables
|
// Try a bunch of non-tables
|
||||||
join_dynamic_check<sqlpp::assert_dynamic_pre_join_table_t>(7);
|
join_dynamic_check<sqlpp::assert_dynamic_pre_join_table_t>(7);
|
||||||
@ -252,6 +254,7 @@ namespace
|
|||||||
// Prepare a dynamic_pre_joins for tests:
|
// Prepare a dynamic_pre_joins for tests:
|
||||||
const auto tj = dynamic_join(t);
|
const auto tj = dynamic_join(t);
|
||||||
const auto fj = dynamic_join(f);
|
const auto fj = dynamic_join(f);
|
||||||
|
const auto vj = dynamic_join(sqlpp::verbatim_table("tab_sample"));
|
||||||
|
|
||||||
// OK dynamic_join.on()
|
// OK dynamic_join.on()
|
||||||
on_dynamic_check<sqlpp::consistent_t>(tj, t.alpha > f.omega);
|
on_dynamic_check<sqlpp::consistent_t>(tj, t.alpha > f.omega);
|
||||||
@ -271,6 +274,7 @@ namespace
|
|||||||
on_dynamic_check<sqlpp::consistent_t>(tj, ta.alpha != 0);
|
on_dynamic_check<sqlpp::consistent_t>(tj, ta.alpha != 0);
|
||||||
on_dynamic_check<sqlpp::consistent_t>(tj, t.gamma);
|
on_dynamic_check<sqlpp::consistent_t>(tj, t.gamma);
|
||||||
on_dynamic_check<sqlpp::consistent_t>(tj, f.omega > fa.omega);
|
on_dynamic_check<sqlpp::consistent_t>(tj, f.omega > fa.omega);
|
||||||
|
on_dynamic_check<sqlpp::consistent_t>(vj, t.alpha < f.omega);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user