0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-15 20:31:16 +08:00

Better failure return values for union

There are still a lot of untestable static_assert, but one thing at a
time...
This commit is contained in:
rbock 2016-09-01 21:57:15 +02:00
parent 1a0f0ea0ab
commit 5d09b736b6
2 changed files with 32 additions and 27 deletions

View File

@ -135,6 +135,16 @@ namespace sqlpp
using _result_methods_t = typename Lhs::template _result_methods_t<Statement>;
};
SQLPP_PORTABLE_STATIC_ASSERT(assert_union_args_are_statements_t, "arguments for union() must be statements");
template <typename... T>
struct check_union
{
using type = static_combined_check_t<
static_check_t<logic::all_t<is_statement_t<T>::value...>::value, assert_union_args_are_statements_t>>;
};
template <typename... T>
using check_union_t = typename check_union<T...>::type;
// NO UNION YET
struct no_union_t
{
@ -187,12 +197,6 @@ namespace sqlpp
using _database_t = typename Policies::_database_t;
// workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269
// template <typename... T>
// using _check = logic::all_t<is_statement_t<T>::value...>;
template <typename... T>
using _check = typename logic::all<is_statement_t<T>::value...>::type;
template <typename Check, typename T>
using _new_statement_t = union_statement_t<Check, T>;
@ -200,7 +204,8 @@ namespace sqlpp
template <typename Rhs>
auto union_distinct(Rhs rhs) const
-> _new_statement_t<_check<Rhs>, union_t<void, union_distinct_t, derived_statement_t<Policies>, Rhs>>
-> _new_statement_t<check_union_t<derived_statement_t<Policies>, Rhs>,
union_t<void, union_distinct_t, derived_statement_t<Policies>, Rhs>>
{
static_assert(is_statement_t<Rhs>::value, "argument of union call has to be a statement");
static_assert(has_policy_t<Rhs, is_select_t>::value, "argument of union call has to be a select");
@ -213,12 +218,12 @@ namespace sqlpp
"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");
return _union_impl<void, union_distinct_t>(_check<derived_statement_t<Policies>, Rhs>{}, rhs);
return _union_impl<void, union_distinct_t>(check_union_t<derived_statement_t<Policies>, Rhs>{}, rhs);
}
template <typename Rhs>
auto union_all(Rhs rhs) const
-> _new_statement_t<_check<Rhs>, union_t<void, union_all_t, derived_statement_t<Policies>, Rhs>>
auto union_all(Rhs rhs) const -> _new_statement_t<check_union_t<derived_statement_t<Policies>, Rhs>,
union_t<void, union_all_t, derived_statement_t<Policies>, Rhs>>
{
static_assert(is_statement_t<Rhs>::value, "argument of union call has to be a statement");
static_assert(has_policy_t<Rhs, is_select_t>::value, "argument of union call has to be a select");
@ -231,11 +236,11 @@ namespace sqlpp
"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");
return _union_impl<void, union_all_t>(_check<derived_statement_t<Policies>, Rhs>{}, rhs);
return _union_impl<void, union_all_t>(check_union_t<derived_statement_t<Policies>, Rhs>{}, rhs);
}
private:
template <typename Database, typename Check, typename Flag, typename Rhs>
template <typename Database, typename Flag, typename Check, typename Rhs>
auto _union_impl(Check, Rhs rhs) const -> Check;
template <typename Database, typename Flag, typename Rhs>

View File

@ -1,4 +1,4 @@
# 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,
@ -30,21 +30,21 @@ target_compile_options(sqlpp11_testing INTERFACE -Wall -Wextra -pedantic)
endif ()
set(test_names
#BooleanExpression
#CustomQuery
#DateTime
#Interpret
#Insert
#Remove
#Update
#Select
#SelectType
#Function
#Prepared
#Minimalistic
#Result
BooleanExpression
CustomQuery
DateTime
Interpret
Insert
Remove
Update
Select
SelectType
Function
Prepared
Minimalistic
Result
Union
#With
With
)
create_test_sourcelist(test_sources test_main.cpp ${test_names})