From da0d47a805655b7398d832a72c2031cc13a93e02 Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 15 Feb 2015 16:06:14 +0100 Subject: [PATCH] Fixed conditions for using sub select as alias --- include/sqlpp11/select_column_list.h | 2 +- include/sqlpp11/statement.h | 4 ++-- include/sqlpp11/type_traits.h | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/sqlpp11/select_column_list.h b/include/sqlpp11/select_column_list.h index 36e78c91..7fae3d2e 100644 --- a/include/sqlpp11/select_column_list.h +++ b/include/sqlpp11/select_column_list.h @@ -286,7 +286,7 @@ namespace sqlpp template _alias_t 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::value...>::value, "cannot use multi-columns in sub selects"); return _table_t(_get_statement()).as(aliasProvider); diff --git a/include/sqlpp11/statement.h b/include/sqlpp11/statement.h index 8fe803d7..209a62e0 100644 --- a/include/sqlpp11/statement.h +++ b/include/sqlpp11/statement.h @@ -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; } diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index 630457a6..e6dc033f 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -296,6 +296,21 @@ namespace sqlpp } }; + template + struct consistency_check + { + using type = assert_run_statement_or_prepared_t; + }; + + template + struct consistency_check::value or is_prepared_statement_t::value>::type> + { + using type = typename T::_consistency_check; + }; + + template + using consistency_check_t = typename consistency_check::type; + template struct run_check {