diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 876acc3a..dc54621a 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -113,6 +113,11 @@ namespace sqlpp static_assert(is_noop_t::value or sqlpp::is_select_column_list_t::value, "column list of select is neither naught nor a valid column list"); static_assert(is_noop_t::value or sqlpp::is_from_t::value, "from() part of select is neither naught nor a valid from()"); + using _known_tables = detail::make_joined_set_t; + + template + using _no_unknown_tables = detail::is_subset_of; + using _required_tables = detail::make_joined_set_t< typename _flag_list_t::_table_set, diff --git a/include/sqlpp11/vendor/select_column_list.h b/include/sqlpp11/vendor/select_column_list.h index 7f38fad4..ebff2552 100644 --- a/include/sqlpp11/vendor/select_column_list.h +++ b/include/sqlpp11/vendor/select_column_list.h @@ -186,10 +186,17 @@ namespace sqlpp struct _methods_t { template + void add_column_ntc(NamedExpression namedExpression) + { + add_column(namedExpression); + } + + template void add_column(NamedExpression namedExpression) { static_assert(_is_dynamic::value, "add_column can only be called for dynamic_column"); static_assert(is_named_expression_t::value, "invalid named expression argument in add_column()"); + static_assert(Ntc::value or Policies::template _no_unknown_tables::value, "named expression uses tables unknown to this statement in add_column()"); using ok = ::sqlpp::detail::all_t>; diff --git a/tests/InterpretTest.cpp b/tests/InterpretTest.cpp index c931fb5a..2fd5c3a3 100644 --- a/tests/InterpretTest.cpp +++ b/tests/InterpretTest.cpp @@ -133,20 +133,20 @@ int main() // dynamic select { - auto s = dynamic_select(db).dynamic_flags().dynamic_columns(); + auto s = dynamic_select(db).dynamic_flags().dynamic_columns().from(t); s.add_column(t.beta); s.add_column(t.gamma); serialize(s, printer).str(); } { - auto s = dynamic_select(db).dynamic_flags().dynamic_columns(); + auto s = dynamic_select(db).dynamic_flags().dynamic_columns().from(t); s.add_flag(sqlpp::distinct); s.add_column(t.beta); s.add_column(t.gamma); serialize(s, printer).str(); } { - auto s = dynamic_select(db).dynamic_flags(sqlpp::distinct).dynamic_columns(t.alpha); + auto s = dynamic_select(db).dynamic_flags(sqlpp::distinct).dynamic_columns(t.alpha).extra_tables(t); // Would fail to run() s.add_flag(sqlpp::all); s.add_column(t.beta); s.add_column(t.gamma); diff --git a/tests/SelectTypeTest.cpp b/tests/SelectTypeTest.cpp index e0a4af64..12cf9c56 100644 --- a/tests/SelectTypeTest.cpp +++ b/tests/SelectTypeTest.cpp @@ -324,7 +324,7 @@ int main() // Test that select can be called with zero columns if it is used with dynamic columns. { - auto s = dynamic_select(db).dynamic_columns(); + auto s = dynamic_select(db).dynamic_columns().extra_tables(t); s.add_column(t.alpha); serialize(s, printer).str(); }