mirror of
https://github.com/rbock/sqlpp11.git
synced 2025-12-31 10:10:28 -06:00
Added a few compile-time checks for unions
This commit is contained in:
@@ -37,6 +37,43 @@
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template<typename Statement, typename Enable = void>
|
||||
struct has_result_row_impl
|
||||
{
|
||||
using type = std::false_type;
|
||||
};
|
||||
|
||||
template<typename Statement>
|
||||
struct has_result_row_impl<Statement,
|
||||
typename std::enable_if<
|
||||
not wrong_t<typename Statement::template _result_methods_t<Statement>::template _result_row_t<void>>::value,
|
||||
void>::type>
|
||||
{
|
||||
using type = std::true_type;
|
||||
};
|
||||
|
||||
template<typename Statement>
|
||||
using has_result_row_t = typename has_result_row_impl<Statement>::type;
|
||||
|
||||
template<typename Statement, typename Enable = void>
|
||||
struct get_result_row_impl
|
||||
{
|
||||
using type = void;
|
||||
};
|
||||
|
||||
template<typename Statement>
|
||||
struct get_result_row_impl<Statement,
|
||||
typename std::enable_if<
|
||||
not wrong_t<typename Statement::template _result_methods_t<Statement>::template _result_row_t<void>>::value,
|
||||
void>::type>
|
||||
{
|
||||
using type = typename Statement::template _result_methods_t<Statement>::template _result_row_t<void>;
|
||||
};
|
||||
|
||||
template<typename Statement>
|
||||
using get_result_row_t = typename get_result_row_impl<Statement>::type;
|
||||
|
||||
|
||||
struct no_union_t;
|
||||
|
||||
using blank_union_t = statement_t<void,
|
||||
@@ -172,11 +209,9 @@ namespace sqlpp
|
||||
-> _new_statement_t<_check<Rhs>, union_t<void, distinct_t, derived_statement_t<Policies>, Rhs>>
|
||||
{
|
||||
static_assert(is_statement_t<Rhs>::value, "argument of union call has to be a statement");
|
||||
// Being a select might be determined by the return type?
|
||||
//FIXME static_assert(is_select this and Rhs, "at least one argument is not an expression in union_()");
|
||||
//FIXME static_assert(same return type, "at least one argument is not an expression in union_()");
|
||||
//FIXME static_assert(consistent/runnable this and Rhs, "at least one expression argument required in union_()");
|
||||
//FIXME static_assert(no order_y in this and Rhs, "at least one expression argument required in union_()");
|
||||
static_assert(has_result_row_t<Rhs>::value, "argument of a union has to be a (complete) select statement");
|
||||
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");
|
||||
static_assert(std::is_same<get_result_row_t<derived_statement_t<Policies>>, get_result_row_t<Rhs>>::value, "both select statements in a union have to have the same result columns (type and name)");
|
||||
|
||||
return _union_impl<void, distinct_t>(_check<derived_statement_t<Policies>, Rhs>{}, rhs);
|
||||
}
|
||||
@@ -185,10 +220,11 @@ namespace sqlpp
|
||||
auto union_all(Rhs rhs) const
|
||||
-> _new_statement_t<_check<Rhs>, union_t<void, all_t, derived_statement_t<Policies>, Rhs>>
|
||||
{
|
||||
//FIXME static_assert(is_select this and Rhs, "at least one argument is not an expression in union_()");
|
||||
//FIXME static_assert(same return type, "at least one argument is not an expression in union_()");
|
||||
//FIXME static_assert(consistent/runnable this and Rhs, "at least one expression argument required in union_()");
|
||||
//FIXME static_assert(no order_y in this and Rhs, "at least one expression argument required in union_()");
|
||||
static_assert(is_statement_t<Rhs>::value, "argument of union call has to be a statement");
|
||||
static_assert(has_result_row_t<Rhs>::value, "argument of a union has to be a (complete) select statement");
|
||||
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");
|
||||
static_assert(std::is_same<get_result_row_t<derived_statement_t<Policies>>, get_result_row_t<Rhs>>::value, "both select statements in a union have to have the same result columns (type and name)");
|
||||
|
||||
|
||||
return _union_impl<void, all_t>(_check<derived_statement_t<Policies>, Rhs>{}, rhs);
|
||||
}
|
||||
|
||||
@@ -37,12 +37,12 @@ int main()
|
||||
test::TabBar t;
|
||||
test::TabFoo f;
|
||||
|
||||
db(select(t.alpha).from(t).union_distinct(select(f.epsilon).from(f)));
|
||||
db(select(t.alpha).from(t).union_all(select(f.epsilon).from(f)));
|
||||
db(select(t.alpha).from(t).union_distinct(select(f.epsilon.as(t.alpha)).from(f)));
|
||||
db(select(t.alpha).from(t).union_all(select(f.epsilon.as(t.alpha)).from(f)));
|
||||
|
||||
auto u = select(t.alpha).from(t).union_all(select(f.epsilon).from(f)).as(sqlpp::alias::u);
|
||||
auto u = select(t.alpha).from(t).union_all(select(f.epsilon.as(t.alpha)).from(f)).as(sqlpp::alias::u);
|
||||
|
||||
db(select(all_of(u)).from(u).union_all(select(t.delta).from(t)));
|
||||
db(select(all_of(u)).from(u).union_all(select(t.delta.as(t.alpha)).from(t)));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user