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

Added serialize checks for dynamically added stuff

This commit is contained in:
rbock 2014-11-26 10:02:48 +01:00
parent 935baebedb
commit 0e27cd7138
11 changed files with 64 additions and 25 deletions

View File

@ -78,9 +78,10 @@ namespace sqlpp
using _known_tables = detail::make_joined_set_t<provided_tables_of<Tables>...>; // Hint: Joins contain more than one table
using _known_table_names = detail::transform_set_t<name_of, _known_tables>;
static_assert(not detail::is_element_of<typename Table::_name_t, _known_table_names>::value, "Must not use the same table name twice in from()");
#warning: need to add a check if the argument is serializable!
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Table>;
_serialize_check::_();
using ok = detail::all_t<_is_dynamic::value, is_table_t<Table>::value>;
using ok = detail::all_t<_is_dynamic::value, is_table_t<Table>::value, _serialize_check::type::value>;
_add_impl(table, ok()); // dispatch to prevent compile messages after the static_assert
}

View File

@ -100,8 +100,10 @@ namespace sqlpp
static_assert(_is_dynamic::value, "add() must not be called for static group_by");
static_assert(is_expression_t<Expression>::value, "invalid expression argument in group_by::add()");
static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<Expression>::value, "expression uses tables unknown to this statement in group_by::add()");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Expression>;
_serialize_check::_();
using ok = detail::all_t<_is_dynamic::value, is_expression_t<Expression>::value>;
using ok = detail::all_t<_is_dynamic::value, is_expression_t<Expression>::value, _serialize_check::type::value>;
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
}

View File

@ -96,8 +96,10 @@ namespace sqlpp
static_assert(_is_dynamic::value, "having::add() can only be called for dynamic_having");
static_assert(is_expression_t<Expression>::value, "invalid expression argument in having::add()");
static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables<Expression>::value, "expression uses tables unknown to this statement in having::add()");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Expression>;
_serialize_check::_();
using ok = detail::all_t<_is_dynamic::value, is_expression_t<Expression>::value>;
using ok = detail::all_t<_is_dynamic::value, is_expression_t<Expression>::value, _serialize_check::type::value>;
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
}

View File

@ -168,10 +168,13 @@ namespace sqlpp
static_assert(not detail::is_element_of<lhs_t<Assignment>, _assigned_columns>::value, "Must not assign value to column twice");
static_assert(not must_not_insert_t<lhs_t<Assignment>>::value, "add() argument must not be used in insert");
static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables<Assignment>::value, "add() contains a column from a foreign table");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Assignment>;
_serialize_check::_();
using ok = detail::all_t<
_is_dynamic::value,
is_assignment_t<Assignment>::value>;
is_assignment_t<Assignment>::value,
_serialize_check::type::value>;
_add_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert
}

View File

@ -34,40 +34,57 @@
namespace sqlpp
{
template<typename Database, typename... Expr>
template<typename Database, typename... Expressions>
struct on_t
{
using _traits = make_traits<no_value_t, tag::is_on>;
using _recursive_traits = make_recursive_traits<Expr...>;
using _recursive_traits = make_recursive_traits<Expressions...>;
using _is_dynamic = is_database<Database>;
static_assert(_is_dynamic::value or sizeof...(Expr), "at least one expression argument required in on()");
static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression argument required in on()");
template<typename E>
void add(E expr)
template<typename Expr>
void add(Expr expr)
{
static_assert(is_expression_t<E>::value, "invalid expression argument in add_on()");
_dynamic_expressions.emplace_back(expr);
static_assert(_is_dynamic::value, "on::add() must not be called for static on()");
static_assert(is_expression_t<Expr>::value, "invalid expression argument in on::add()");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Expr>;
_serialize_check::_();
using ok = detail::all_t<_is_dynamic::value, is_expression_t<Expr>::value, _serialize_check::type::value>;
_add_impl(expr, ok()); // dispatch to prevent compile messages after the static_assert
}
std::tuple<Expr...> _expressions;
private:
template<typename Expr>
void _add_impl(Expr expr, const std::true_type&)
{
return _dynamic_expressions.emplace_back(expr);
}
template<typename Expr>
void _add_impl(Expr expr, const std::false_type&);
public:
std::tuple<Expressions...> _expressions;
interpretable_list_t<Database> _dynamic_expressions;
};
template<typename Context, typename Database, typename... Expr>
struct serializer_t<Context, on_t<Database, Expr...>>
template<typename Context, typename Database, typename... Expressions>
struct serializer_t<Context, on_t<Database, Expressions...>>
{
using _serialize_check = serialize_check_of<Context, Expr...>;
using T = on_t<Database, Expr...>;
using _serialize_check = serialize_check_of<Context, Expressions...>;
using T = on_t<Database, Expressions...>;
static Context& _(const T& t, Context& context)
{
if (sizeof...(Expr) == 0 and t._dynamic_expressions.empty())
if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty())
return context;
context << " ON ";
interpret_tuple(t._expressions, " AND ", context);
if (sizeof...(Expr) and not t._dynamic_expressions.empty())
if (sizeof...(Expressions) and not t._dynamic_expressions.empty())
context << " AND ";
interpret_list(t._dynamic_expressions, " AND ", context);
return context;

View File

@ -100,8 +100,10 @@ namespace sqlpp
static_assert(_is_dynamic::value, "add() must not be called for static order_by");
static_assert(is_expression_t<Expression>::value, "invalid expression argument in order_by::add()");
static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<Expression>::value, "expression uses tables unknown to this statement in order_by::add()");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Expression>;
_serialize_check::_();
using ok = detail::all_t<_is_dynamic::value, is_expression_t<Expression>::value>;
using ok = detail::all_t<_is_dynamic::value, is_expression_t<Expression>::value, _serialize_check::type::value>;
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
}

View File

@ -198,10 +198,13 @@ namespace sqlpp
static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<NamedExpression>::value, "named expression uses tables unknown to this statement in selected_columns::add()");
using column_names = detail::make_type_set_t<typename Columns::_name_t...>;
static_assert(not detail::is_element_of<typename NamedExpression::_name_t, column_names>::value, "a column of this name is present in the select already");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, NamedExpression>;
_serialize_check::_();
using ok = detail::all_t<
_is_dynamic::value,
is_selectable_t<NamedExpression>::value
is_selectable_t<NamedExpression>::value,
_serialize_check::type::value
>;
_add_impl(namedExpression, ok()); // dispatch to prevent compile messages after the static_assert

View File

@ -87,8 +87,10 @@ namespace sqlpp
static_assert(_is_dynamic::value, "select_flags::add() must not be called for static select flags");
static_assert(is_select_flag_t<Flag>::value, "invalid select flag argument in select_flags::add()");
static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<Flag>::value, "flag uses tables unknown to this statement in select_flags::add()");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Flag>;
_serialize_check::_();
using ok = detail::all_t<_is_dynamic::value, is_select_flag_t<Flag>::value>;
using ok = detail::all_t<_is_dynamic::value, is_select_flag_t<Flag>::value, _serialize_check::type::value>;
_add_impl(flag, ok()); // dispatch to prevent compile messages after the static_assert
}

View File

@ -93,10 +93,13 @@ namespace sqlpp
static_assert(not detail::is_element_of<lhs_t<Assignment>, _assigned_columns>::value, "Must not assign value to column twice");
static_assert(detail::not_t<must_not_update_t, lhs_t<Assignment>>::value, "add() argument must not be updated");
static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<Assignment>::value, "assignment uses tables unknown to this statement in add()");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Assignment>;
_serialize_check::_();
using ok = detail::all_t<
_is_dynamic::value,
is_assignment_t<Assignment>::value>;
is_assignment_t<Assignment>::value,
_serialize_check::type::value>;
_add_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert
}

View File

@ -80,8 +80,10 @@ namespace sqlpp
{
static_assert(_is_dynamic::value, "add must not be called for static using()");
static_assert(is_table_t<Table>::value, "invalid table argument in add()");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Table>;
_serialize_check::_();
using ok = detail::all_t<_is_dynamic::value, is_table_t<Table>::value>;
using ok = detail::all_t<_is_dynamic::value, is_table_t<Table>::value, _serialize_check::type::value>;
_add_impl(table, ok()); // dispatch to prevent compile messages after the static_assert
}

View File

@ -98,8 +98,10 @@ namespace sqlpp
static_assert(_is_dynamic::value, "where::add() can only be called for dynamic_where");
static_assert(is_expression_t<Expression>::value, "invalid expression argument in where::add()");
static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables<Expression>::value, "expression uses tables unknown to this statement in where::add()");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Expression>;
_serialize_check::_();
using ok = detail::all_t<_is_dynamic::value, is_expression_t<Expression>::value>;
using ok = detail::all_t<_is_dynamic::value, is_expression_t<Expression>::value, _serialize_check::type::value>;
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
}