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

Added check to prevent add_column to use a column name known in the static part

This commit is contained in:
rbock 2014-04-22 21:41:53 +02:00
parent 8f16ded277
commit d342973ef4
2 changed files with 7 additions and 3 deletions

View File

@ -198,8 +198,13 @@ namespace sqlpp
static_assert(_is_dynamic::value, "add_column can only be called for dynamic_column"); 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(is_named_expression_t<NamedExpression>::value, "invalid named expression argument in add_column()");
static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<NamedExpression>::value, "named expression uses tables unknown to this statement in add_column()"); static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<NamedExpression>::value, "named expression uses tables unknown to this statement in add_column()");
using column_names = ::sqlpp::detail::make_type_set_t<typename Columns::_name_t...>;
static_assert(not ::sqlpp::detail::is_element_of<typename NamedExpression::_name_t, column_names>::value, "a column of this name is present in the select already");
using ok = ::sqlpp::detail::all_t<sqlpp::detail::identity_t, _is_dynamic, is_named_expression_t<NamedExpression>>; using ok = ::sqlpp::detail::all_t<sqlpp::detail::identity_t,
_is_dynamic,
is_named_expression_t<NamedExpression>
>;
_add_column_impl(namedExpression, ok()); // dispatch to prevent compile messages after the static_assert _add_column_impl(namedExpression, ok()); // dispatch to prevent compile messages after the static_assert
} }

View File

@ -70,8 +70,7 @@ int main()
auto s = dynamic_select(db).dynamic_columns(all_of(t)).dynamic_flags().dynamic_from(t).extra_tables(f,t).dynamic_where().dynamic_group_by(t.alpha).dynamic_order_by().dynamic_having(t.gamma).dynamic_limit().dynamic_offset(); auto s = dynamic_select(db).dynamic_columns(all_of(t)).dynamic_flags().dynamic_from(t).extra_tables(f,t).dynamic_where().dynamic_group_by(t.alpha).dynamic_order_by().dynamic_having(t.gamma).dynamic_limit().dynamic_offset();
s.add_flag(sqlpp::distinct); s.add_flag(sqlpp::distinct);
#warning: this should fail because t.beta has been selected already s.add_column(f.omega);
s.add_column(t.beta);
s.add_from(f); s.add_from(f);
s.add_where(t.alpha > 7); s.add_where(t.alpha > 7);
s.add_having(t.alpha > 7); s.add_having(t.alpha > 7);