0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 04:47:18 +08:00

Added check to prevent multicolumns in sub selects

This commit is contained in:
rbock 2014-06-28 21:02:49 +02:00
parent 7900cba1ca
commit 0f9c1dbfb2
3 changed files with 3 additions and 5 deletions

View File

@ -76,7 +76,7 @@ namespace sqlpp
template<typename AliasProvider, typename... Columns> template<typename AliasProvider, typename... Columns>
struct multi_column_alias_t struct multi_column_alias_t
{ {
using _traits = make_traits<no_value_t, tag::alias, tag::named_expression>; using _traits = make_traits<no_value_t, tag::alias, tag::multi_column, tag::named_expression>;
using _recursive_traits = make_recursive_traits<Columns...>; using _recursive_traits = make_recursive_traits<Columns...>;
static_assert(detail::all_t<is_named_expression_t<Columns>::value...>::value, "multi_column parameters need to be named expressions"); static_assert(detail::all_t<is_named_expression_t<Columns>::value...>::value, "multi_column parameters need to be named expressions");

View File

@ -269,6 +269,7 @@ namespace sqlpp
_alias_t<AliasProvider> as(const AliasProvider& aliasProvider) const _alias_t<AliasProvider> as(const AliasProvider& aliasProvider) const
{ {
static_assert(Policies::_can_be_used_as_table::value, "statement cannot be used as table, e.g. due to missing tables"); static_assert(Policies::_can_be_used_as_table::value, "statement cannot be used as table, e.g. due to missing tables");
static_assert(::sqlpp::detail::none_t<is_multi_column_t<Columns>::value...>::value, "cannot use multi-columns in sub selects");
return _table_t<AliasProvider>(_get_statement()).as(aliasProvider); return _table_t<AliasProvider>(_get_statement()).as(aliasProvider);
} }

View File

@ -290,11 +290,8 @@ int main()
{ {
auto m = multi_column(t.alpha, t.beta).as(alias::a); auto m = multi_column(t.alpha, t.beta).as(alias::a);
static_assert(not sqlpp::is_expression_t<decltype(m)>::value, "a multi_column is not a value"); static_assert(not sqlpp::is_expression_t<decltype(m)>::value, "a multi_column is not a value");
#warning: A multicolumn cannot be used if the select is to be used like a table
auto a = select(m).from(t).as(alias::b).a;
//static_assert(not sqlpp::is_expression_t<decltype(a)>::value, "a multi_column is not a value");
} }
// Test that result sets with identical name/value combinations have identical types // Test that result sets with identical name/value combinations have identical types
{ {
auto a = select(t.alpha); auto a = select(t.alpha);