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

Added table checks to add_column and added add_column_ntc

This commit is contained in:
rbock 2014-04-21 11:49:26 +02:00
parent 815c061979
commit 1f3e611fdf
4 changed files with 16 additions and 4 deletions

View File

@ -113,6 +113,11 @@ namespace sqlpp
static_assert(is_noop_t<ColumnList>::value or sqlpp::is_select_column_list_t<ColumnList>::value, "column list of select is neither naught nor a valid column list");
static_assert(is_noop_t<From>::value or sqlpp::is_from_t<From>::value, "from() part of select is neither naught nor a valid from()");
using _known_tables = detail::make_joined_set_t<typename _from_t::_table_set, typename _extra_tables_t::_table_set>;
template<typename Expression>
using _no_unknown_tables = detail::is_subset_of<typename Expression::_table_set, _known_tables>;
using _required_tables =
detail::make_joined_set_t<
typename _flag_list_t::_table_set,

View File

@ -186,10 +186,17 @@ namespace sqlpp
struct _methods_t
{
template<typename NamedExpression>
void add_column_ntc(NamedExpression namedExpression)
{
add_column<NamedExpression, std::true_type>(namedExpression);
}
template<typename NamedExpression, typename Ntc = std::false_type>
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<NamedExpression>::value, "invalid named expression argument in add_column()");
static_assert(Ntc::value or Policies::template _no_unknown_tables<NamedExpression>::value, "named expression uses tables unknown to this statement in add_column()");
using ok = ::sqlpp::detail::all_t<sqlpp::detail::identity_t, _is_dynamic, is_named_expression_t<NamedExpression>>;

View File

@ -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);

View File

@ -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();
}