mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
Slightly better comparison of row types for unions.
Needs some work for non-static versions
This commit is contained in:
parent
b0aa23ee87
commit
fa0fe887b5
@ -41,11 +41,39 @@ namespace sqlpp
|
|||||||
using _nodes = detail::type_vector<>;
|
using _nodes = detail::type_vector<>;
|
||||||
|
|
||||||
using _alias_t = NameType;
|
using _alias_t = NameType;
|
||||||
|
|
||||||
|
template <typename N, typename V, bool C, bool T>
|
||||||
|
static constexpr auto is_compatible(field_spec_t<N, V, C, T>) -> bool
|
||||||
|
{
|
||||||
|
using rhs = field_spec_t<N, V, C, T>;
|
||||||
|
return std::is_same<_traits, typename rhs::_traits>::value and
|
||||||
|
std::is_same<typename _alias_t::_name_t, typename rhs::_alias_t::_name_t>::value;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename AliasProvider, typename FieldSpecTuple>
|
template <typename AliasProvider, typename FieldSpecTuple>
|
||||||
struct multi_field_spec_t
|
struct multi_field_spec_t
|
||||||
{
|
{
|
||||||
|
static_assert(wrong_t<AliasProvider, FieldSpecTuple>::value,
|
||||||
|
"multi_field_spec_t needs to be specialized with a tuple");
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename AliasProvider, typename... FieldSpecs>
|
||||||
|
struct multi_field_spec_t<AliasProvider, std::tuple<FieldSpecs...>>
|
||||||
|
{
|
||||||
|
template <typename A, typename... Fs>
|
||||||
|
static constexpr auto is_compatible(multi_field_spec_t<A, Fs...>) ->
|
||||||
|
typename std::enable_if<sizeof...(Fs) == sizeof...(FieldSpecs), bool>::type
|
||||||
|
{
|
||||||
|
return logic::all_t<FieldSpecs::is_compatible(Fs{})...>::value;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename A, typename... Fs>
|
||||||
|
static constexpr auto is_compatible(multi_field_spec_t<A, Fs...>) ->
|
||||||
|
typename std::enable_if<sizeof...(Fs) != sizeof...(FieldSpecs), bool>::type
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
|
@ -186,6 +186,19 @@ namespace sqlpp
|
|||||||
using _impl = detail::result_row_impl<Db, _field_index_sequence, FieldSpecs...>;
|
using _impl = detail::result_row_impl<Db, _field_index_sequence, FieldSpecs...>;
|
||||||
bool _is_valid;
|
bool _is_valid;
|
||||||
|
|
||||||
|
template <typename D, typename... Fs>
|
||||||
|
static constexpr auto is_compatible(detail::type_vector<result_row_t<D, Fs...>>) ->
|
||||||
|
typename std::enable_if<sizeof...(Fs) == sizeof...(FieldSpecs), bool>::type
|
||||||
|
{
|
||||||
|
return logic::all_t<FieldSpecs::is_compatible(Fs{})...>::value;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename D, typename... Fs>
|
||||||
|
static constexpr auto is_compatible(detail::type_vector<result_row_t<D, Fs...>>) ->
|
||||||
|
typename std::enable_if<sizeof...(Fs) != sizeof...(FieldSpecs), bool>::type
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
result_row_t() : _impl(), _is_valid(false)
|
result_row_t() : _impl(), _is_valid(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -213,10 +213,13 @@ namespace sqlpp
|
|||||||
static_assert(has_result_row_t<derived_statement_t<Policies>>::value,
|
static_assert(has_result_row_t<derived_statement_t<Policies>>::value,
|
||||||
"left hand side argument of a union has to be a complete select statement or union");
|
"left hand side argument of a union has to be a complete select statement or union");
|
||||||
|
|
||||||
using _result_row_t = get_result_row_t<Rhs>;
|
using lhs_result_row_t = get_result_row_t<derived_statement_t<Policies>>;
|
||||||
static_assert(std::is_same<get_result_row_t<derived_statement_t<Policies>>, _result_row_t>::value,
|
using rhs_result_row_t = get_result_row_t<Rhs>;
|
||||||
|
static_assert(lhs_result_row_t::is_compatible(detail::type_vector<rhs_result_row_t>{}),
|
||||||
"both arguments in a union have to have the same result columns (type and name)");
|
"both arguments in a union have to have the same result columns (type and name)");
|
||||||
static_assert(is_static_result_row_t<_result_row_t>::value, "unions must not have dynamically added columns");
|
static_assert(
|
||||||
|
is_static_result_row_t<lhs_result_row_t>::value && is_static_result_row_t<rhs_result_row_t>::value,
|
||||||
|
"unions must not have dynamically added columns");
|
||||||
|
|
||||||
return _union_impl<void, union_distinct_t>(check_union_t<derived_statement_t<Policies>, Rhs>{}, rhs);
|
return _union_impl<void, union_distinct_t>(check_union_t<derived_statement_t<Policies>, Rhs>{}, rhs);
|
||||||
}
|
}
|
||||||
@ -231,10 +234,13 @@ namespace sqlpp
|
|||||||
static_assert(has_result_row_t<derived_statement_t<Policies>>::value,
|
static_assert(has_result_row_t<derived_statement_t<Policies>>::value,
|
||||||
"left hand side argument of a union has to be a (complete) select statement");
|
"left hand side argument of a union has to be a (complete) select statement");
|
||||||
|
|
||||||
using _result_row_t = get_result_row_t<Rhs>;
|
using lhs_result_row_t = get_result_row_t<derived_statement_t<Policies>>;
|
||||||
static_assert(std::is_same<get_result_row_t<derived_statement_t<Policies>>, _result_row_t>::value,
|
using rhs_result_row_t = get_result_row_t<Rhs>;
|
||||||
|
static_assert(lhs_result_row_t::is_compatible(detail::type_vector<rhs_result_row_t>{}),
|
||||||
"both arguments in a union have to have the same result columns (type and name)");
|
"both arguments in a union have to have the same result columns (type and name)");
|
||||||
static_assert(is_static_result_row_t<_result_row_t>::value, "unions must not have dynamically added columns");
|
static_assert(
|
||||||
|
is_static_result_row_t<lhs_result_row_t>::value && is_static_result_row_t<rhs_result_row_t>::value,
|
||||||
|
"unions must not have dynamically added columns");
|
||||||
|
|
||||||
return _union_impl<void, union_all_t>(check_union_t<derived_statement_t<Policies>, Rhs>{}, rhs);
|
return _union_impl<void, union_all_t>(check_union_t<derived_statement_t<Policies>, Rhs>{}, rhs);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user