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

Fixed conditions for using sub select as alias

This commit is contained in:
rbock 2015-02-15 16:06:14 +01:00
parent a09c79b234
commit da0d47a805
3 changed files with 18 additions and 3 deletions

View File

@ -286,7 +286,7 @@ namespace sqlpp
template<typename AliasProvider>
_alias_t<AliasProvider> as(const AliasProvider& aliasProvider) const
{
run_check_t<_statement_t>::_();
consistency_check_t<_statement_t>::_();
static_assert(_statement_t::_can_be_used_as_table(), "statement cannot be used as table, e.g. due to missing tables");
static_assert(logic::none_t<is_multi_column_t<Columns>::value...>::value, "cannot use multi-columns in sub selects");
return _table_t<AliasProvider>(_get_statement()).as(aliasProvider);

View File

@ -130,12 +130,12 @@ namespace sqlpp
// A select can be used as a pseudo table if
// - at least one column is selected
// - the select is complete (leaks no tables)
// - the select is complete (leaks no table requirements)
static constexpr bool _can_be_used_as_table()
{
return has_result_row_t<_statement_t>::value
and _required_tables::size::value == 0
and _required_ctes::size::value == 0
and _all_provided_ctes::size::value == 0 // a sub-select must not contain a WITH
? true
: false;
}

View File

@ -296,6 +296,21 @@ namespace sqlpp
}
};
template<typename T, typename Enable = void>
struct consistency_check
{
using type = assert_run_statement_or_prepared_t;
};
template<typename T>
struct consistency_check<T, typename std::enable_if<is_statement_t<T>::value or is_prepared_statement_t<T>::value>::type>
{
using type = typename T::_consistency_check;
};
template<typename T>
using consistency_check_t = typename consistency_check<T>::type;
template<typename T, typename Enable = void>
struct run_check
{