Added portable static asserts for joins and first static tests

This commit is contained in:
rbock
2016-03-04 21:07:42 +01:00
parent ab875fc79b
commit cf5ddfde00
7 changed files with 269 additions and 32 deletions

View File

@@ -33,6 +33,26 @@
namespace sqlpp
{
SQLPP_PORTABLE_STATIC_ASSERT(assert_cross_join_lhs_table_t, "lhs argument of join() has to be a table or a join");
SQLPP_PORTABLE_STATIC_ASSERT(assert_cross_join_rhs_table_t, "rhs argument of join() has to be a table");
SQLPP_PORTABLE_STATIC_ASSERT(assert_cross_join_rhs_no_join_t, "rhs argument of join() must not be a table");
SQLPP_PORTABLE_STATIC_ASSERT(assert_cross_join_unique_names_t, "joined table names have to be unique");
template <typename Lhs, typename Rhs>
struct check_cross_join
{
using type = static_combined_check_t<
static_check_t<is_table_t<Lhs>::value, assert_cross_join_lhs_table_t>,
static_check_t<is_table_t<Rhs>::value, assert_cross_join_rhs_table_t>,
static_check_t<not is_join_t<Rhs>::value, assert_cross_join_rhs_no_join_t>,
static_check_t<detail::is_disjunct_from<detail::make_name_of_set_t<provided_tables_of<Lhs>>,
detail::make_name_of_set_t<provided_tables_of<Rhs>>>::value,
assert_cross_join_unique_names_t>>;
};
template <typename Lhs, typename Rhs>
using check_cross_join_t = typename check_cross_join<Lhs, Rhs>::type;
template <typename CrossJoin, typename On>
struct join_t;
@@ -86,6 +106,56 @@ namespace sqlpp
return context;
}
};
template <typename Lhs, typename Rhs>
auto join(Lhs lhs, Rhs rhs) -> typename std::conditional<check_cross_join_t<Lhs, Rhs>::value,
cross_join_t<inner_join_t, Lhs, Rhs>,
bad_statement>::type
{
check_cross_join_t<Lhs, Rhs>::_();
return {lhs, rhs};
}
template <typename Lhs, typename Rhs>
auto inner_join(Lhs lhs, Rhs rhs) -> typename std::conditional<check_cross_join_t<Lhs, Rhs>::value,
cross_join_t<inner_join_t, Lhs, Rhs>,
bad_statement>::type
{
check_cross_join_t<Lhs, Rhs>::_();
return {lhs, rhs};
}
template <typename Lhs, typename Rhs>
auto left_outer_join(Lhs lhs, Rhs rhs) -> typename std::conditional<check_cross_join_t<Lhs, Rhs>::value,
cross_join_t<left_outer_join_t, Lhs, Rhs>,
bad_statement>::type
{
check_cross_join_t<Lhs, Rhs>::_();
return {lhs, rhs};
}
template <typename Lhs, typename Rhs>
auto right_outer_join(Lhs lhs, Rhs rhs) -> typename std::conditional<check_cross_join_t<Lhs, Rhs>::value,
cross_join_t<right_outer_join_t, Lhs, Rhs>,
bad_statement>::type
{
check_cross_join_t<Lhs, Rhs>::_();
return {lhs, rhs};
}
template <typename Lhs, typename Rhs>
auto outer_join(Lhs lhs, Rhs rhs) -> typename std::conditional<check_cross_join_t<Lhs, Rhs>::value,
cross_join_t<right_outer_join_t, Lhs, Rhs>,
bad_statement>::type
{
check_cross_join_t<Lhs, Rhs>::_();
return {lhs, rhs};
}
}
#endif

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2015, Roland Bock
* Copyright (c) 2013-2016, Roland Bock
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@@ -50,33 +50,33 @@ namespace sqlpp
"on() condition must not depend on other tables");
template <typename T>
cross_join_t<inner_join_t, join_t, T> join(T t)
auto join(T t) const -> decltype(::sqlpp::join(*this, t))
{
return {*this, t};
return ::sqlpp::join(*this, t);
}
template <typename T>
cross_join_t<inner_join_t, join_t, T> inner_join(T t)
auto inner_join(T t) const -> decltype(::sqlpp::inner_join(*this, t))
{
return {*this, t};
return ::sqlpp::inner_join(*this, t);
}
template <typename T>
cross_join_t<outer_join_t, join_t, T> outer_join(T t)
auto left_outer_join(T t) const -> decltype(::sqlpp::left_outer_join(*this, t))
{
return {*this, t};
return ::sqlpp::left_outer_join(*this, t);
}
template <typename T>
cross_join_t<left_outer_join_t, join_t, T> left_outer_join(T t)
auto right_outer_join(T t) const -> decltype(::sqlpp::right_outer_join(*this, t))
{
return {*this, t};
return ::sqlpp::right_outer_join(*this, t);
}
template <typename T>
cross_join_t<right_outer_join_t, join_t, T> right_outer_join(T t)
auto outer_join(T t) const -> decltype(::sqlpp::outer_join(*this, t))
{
return {*this, t};
return ::sqlpp::outer_join(*this, t);
}
CrossJoin _cross_join;

View File

@@ -62,33 +62,33 @@ namespace sqlpp
using _alias_t = table_alias_t<AliasProvider, Table, ColumnSpec...>;
template <typename T>
cross_join_t<inner_join_t, Table, T> join(T t) const
auto join(T t) const -> decltype(::sqlpp::join(std::declval<Table>(), t))
{
return {*static_cast<const Table*>(this), t};
return ::sqlpp::join(*static_cast<const Table*>(this), t);
}
template <typename T>
cross_join_t<inner_join_t, Table, T> inner_join(T t) const
auto inner_join(T t) const -> decltype(::sqlpp::inner_join(std::declval<Table>(), t))
{
return {*static_cast<const Table*>(this), t};
return ::sqlpp::inner_join(*static_cast<const Table*>(this), t);
}
template <typename T>
cross_join_t<outer_join_t, Table, T> outer_join(T t) const
auto left_outer_join(T t) const -> decltype(::sqlpp::left_outer_join(std::declval<Table>(), t))
{
return {*static_cast<const Table*>(this), t};
return ::sqlpp::left_outer_join(*static_cast<const Table*>(this), t);
}
template <typename T>
cross_join_t<left_outer_join_t, Table, T> left_outer_join(T t) const
auto right_outer_join(T t) const -> decltype(::sqlpp::right_outer_join(std::declval<Table>(), t))
{
return {*static_cast<const Table*>(this), t};
return ::sqlpp::right_outer_join(*static_cast<const Table*>(this), t);
}
template <typename T>
cross_join_t<right_outer_join_t, Table, T> right_outer_join(T t) const
auto outer_join(T t) const -> decltype(::sqlpp::outer_join(std::declval<Table>(), t))
{
return {*static_cast<const Table*>(this), t};
return ::sqlpp::outer_join(*static_cast<const Table*>(this), t);
}
template <typename AliasProvider>

View File

@@ -61,33 +61,33 @@ namespace sqlpp
}
template <typename T>
cross_join_t<inner_join_t, table_alias_t, T> join(T t) const
auto join(T t) const -> decltype(::sqlpp::join(*this, t))
{
return {*this, t};
return ::sqlpp::join(*this, t);
}
template <typename T>
cross_join_t<inner_join_t, table_alias_t, T> inner_join(T t) const
auto inner_join(T t) const -> decltype(::sqlpp::inner_join(*this, t))
{
return {*this, t};
return ::sqlpp::inner_join(*this, t);
}
template <typename T>
cross_join_t<outer_join_t, table_alias_t, T> outer_join(T t) const
auto left_outer_join(T t) const -> decltype(::sqlpp::left_outer_join(*this, t))
{
return {*this, t};
return ::sqlpp::left_outer_join(*this, t);
}
template <typename T>
cross_join_t<left_outer_join_t, table_alias_t, T> left_outer_join(T t) const
auto right_outer_join(T t) const -> decltype(::sqlpp::right_outer_join(*this, t))
{
return {*this, t};
return ::sqlpp::right_outer_join(*this, t);
}
template <typename T>
cross_join_t<right_outer_join_t, table_alias_t, T> right_outer_join(T t) const
auto outer_join(T t) const -> decltype(::sqlpp::outer_join(*this, t))
{
return {*this, t};
return ::sqlpp::outer_join(*this, t);
}
Table _table;