From 0e27cd7138d9587945c12223e617d558d75d1bec Mon Sep 17 00:00:00 2001 From: rbock Date: Wed, 26 Nov 2014 10:02:48 +0100 Subject: [PATCH] Added serialize checks for dynamically added stuff --- include/sqlpp11/from.h | 5 ++-- include/sqlpp11/group_by.h | 4 ++- include/sqlpp11/having.h | 4 ++- include/sqlpp11/insert_value_list.h | 5 +++- include/sqlpp11/on.h | 45 +++++++++++++++++++--------- include/sqlpp11/order_by.h | 4 ++- include/sqlpp11/select_column_list.h | 5 +++- include/sqlpp11/select_flag_list.h | 4 ++- include/sqlpp11/update_list.h | 5 +++- include/sqlpp11/using.h | 4 ++- include/sqlpp11/where.h | 4 ++- 11 files changed, 64 insertions(+), 25 deletions(-) diff --git a/include/sqlpp11/from.h b/include/sqlpp11/from.h index efc338ba..1534be1f 100644 --- a/include/sqlpp11/from.h +++ b/include/sqlpp11/from.h @@ -78,9 +78,10 @@ namespace sqlpp using _known_tables = detail::make_joined_set_t...>; // Hint: Joins contain more than one table using _known_table_names = detail::transform_set_t; static_assert(not detail::is_element_of::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; + _serialize_check::_(); - using ok = detail::all_t<_is_dynamic::value, is_table_t::value>; + using ok = detail::all_t<_is_dynamic::value, is_table_t
::value, _serialize_check::type::value>; _add_impl(table, ok()); // dispatch to prevent compile messages after the static_assert } diff --git a/include/sqlpp11/group_by.h b/include/sqlpp11/group_by.h index be7d01aa..3871d341 100644 --- a/include/sqlpp11/group_by.h +++ b/include/sqlpp11/group_by.h @@ -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::value, "invalid expression argument in group_by::add()"); static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in group_by::add()"); + using _serialize_check = sqlpp::serialize_check_t; + _serialize_check::_(); - using ok = detail::all_t<_is_dynamic::value, is_expression_t::value>; + using ok = detail::all_t<_is_dynamic::value, is_expression_t::value, _serialize_check::type::value>; _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert } diff --git a/include/sqlpp11/having.h b/include/sqlpp11/having.h index e524da76..96764184 100644 --- a/include/sqlpp11/having.h +++ b/include/sqlpp11/having.h @@ -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::value, "invalid expression argument in having::add()"); static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in having::add()"); + using _serialize_check = sqlpp::serialize_check_t; + _serialize_check::_(); - using ok = detail::all_t<_is_dynamic::value, is_expression_t::value>; + using ok = detail::all_t<_is_dynamic::value, is_expression_t::value, _serialize_check::type::value>; _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert } diff --git a/include/sqlpp11/insert_value_list.h b/include/sqlpp11/insert_value_list.h index 8190829b..077af67d 100644 --- a/include/sqlpp11/insert_value_list.h +++ b/include/sqlpp11/insert_value_list.h @@ -168,10 +168,13 @@ namespace sqlpp static_assert(not detail::is_element_of, _assigned_columns>::value, "Must not assign value to column twice"); static_assert(not must_not_insert_t>::value, "add() argument must not be used in insert"); static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables::value, "add() contains a column from a foreign table"); + using _serialize_check = sqlpp::serialize_check_t; + _serialize_check::_(); using ok = detail::all_t< _is_dynamic::value, - is_assignment_t::value>; + is_assignment_t::value, + _serialize_check::type::value>; _add_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert } diff --git a/include/sqlpp11/on.h b/include/sqlpp11/on.h index 8762d3c0..43bd7c80 100644 --- a/include/sqlpp11/on.h +++ b/include/sqlpp11/on.h @@ -34,40 +34,57 @@ namespace sqlpp { - template + template struct on_t { using _traits = make_traits; - using _recursive_traits = make_recursive_traits; + using _recursive_traits = make_recursive_traits; using _is_dynamic = is_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 - void add(E expr) + template + void add(Expr expr) { - static_assert(is_expression_t::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::value, "invalid expression argument in on::add()"); + using _serialize_check = sqlpp::serialize_check_t; + _serialize_check::_(); + + using ok = detail::all_t<_is_dynamic::value, is_expression_t::value, _serialize_check::type::value>; + + _add_impl(expr, ok()); // dispatch to prevent compile messages after the static_assert } - std::tuple _expressions; + private: + template + void _add_impl(Expr expr, const std::true_type&) + { + return _dynamic_expressions.emplace_back(expr); + } + + template + void _add_impl(Expr expr, const std::false_type&); + + public: + std::tuple _expressions; interpretable_list_t _dynamic_expressions; }; - template - struct serializer_t> + template + struct serializer_t> { - using _serialize_check = serialize_check_of; - using T = on_t; + using _serialize_check = serialize_check_of; + using T = on_t; 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; diff --git a/include/sqlpp11/order_by.h b/include/sqlpp11/order_by.h index afac7e97..ca7c0920 100644 --- a/include/sqlpp11/order_by.h +++ b/include/sqlpp11/order_by.h @@ -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::value, "invalid expression argument in order_by::add()"); static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in order_by::add()"); + using _serialize_check = sqlpp::serialize_check_t; + _serialize_check::_(); - using ok = detail::all_t<_is_dynamic::value, is_expression_t::value>; + using ok = detail::all_t<_is_dynamic::value, is_expression_t::value, _serialize_check::type::value>; _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert } diff --git a/include/sqlpp11/select_column_list.h b/include/sqlpp11/select_column_list.h index 4688b3cb..5b6fcf69 100644 --- a/include/sqlpp11/select_column_list.h +++ b/include/sqlpp11/select_column_list.h @@ -198,10 +198,13 @@ namespace sqlpp static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "named expression uses tables unknown to this statement in selected_columns::add()"); using column_names = detail::make_type_set_t; static_assert(not detail::is_element_of::value, "a column of this name is present in the select already"); + using _serialize_check = sqlpp::serialize_check_t; + _serialize_check::_(); using ok = detail::all_t< _is_dynamic::value, - is_selectable_t::value + is_selectable_t::value, + _serialize_check::type::value >; _add_impl(namedExpression, ok()); // dispatch to prevent compile messages after the static_assert diff --git a/include/sqlpp11/select_flag_list.h b/include/sqlpp11/select_flag_list.h index faa41cdf..78a42e2b 100644 --- a/include/sqlpp11/select_flag_list.h +++ b/include/sqlpp11/select_flag_list.h @@ -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::value, "invalid select flag argument in select_flags::add()"); static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "flag uses tables unknown to this statement in select_flags::add()"); + using _serialize_check = sqlpp::serialize_check_t; + _serialize_check::_(); - using ok = detail::all_t<_is_dynamic::value, is_select_flag_t::value>; + using ok = detail::all_t<_is_dynamic::value, is_select_flag_t::value, _serialize_check::type::value>; _add_impl(flag, ok()); // dispatch to prevent compile messages after the static_assert } diff --git a/include/sqlpp11/update_list.h b/include/sqlpp11/update_list.h index f17e2c7b..26b6a7e7 100644 --- a/include/sqlpp11/update_list.h +++ b/include/sqlpp11/update_list.h @@ -93,10 +93,13 @@ namespace sqlpp static_assert(not detail::is_element_of, _assigned_columns>::value, "Must not assign value to column twice"); static_assert(detail::not_t>::value, "add() argument must not be updated"); static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "assignment uses tables unknown to this statement in add()"); + using _serialize_check = sqlpp::serialize_check_t; + _serialize_check::_(); using ok = detail::all_t< _is_dynamic::value, - is_assignment_t::value>; + is_assignment_t::value, + _serialize_check::type::value>; _add_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert } diff --git a/include/sqlpp11/using.h b/include/sqlpp11/using.h index 6e2be749..cfc0858a 100644 --- a/include/sqlpp11/using.h +++ b/include/sqlpp11/using.h @@ -80,8 +80,10 @@ namespace sqlpp { static_assert(_is_dynamic::value, "add must not be called for static using()"); static_assert(is_table_t
::value, "invalid table argument in add()"); + using _serialize_check = sqlpp::serialize_check_t; + _serialize_check::_(); - using ok = detail::all_t<_is_dynamic::value, is_table_t
::value>; + using ok = detail::all_t<_is_dynamic::value, is_table_t
::value, _serialize_check::type::value>; _add_impl(table, ok()); // dispatch to prevent compile messages after the static_assert } diff --git a/include/sqlpp11/where.h b/include/sqlpp11/where.h index 983e2658..c518b5af 100644 --- a/include/sqlpp11/where.h +++ b/include/sqlpp11/where.h @@ -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::value, "invalid expression argument in where::add()"); static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in where::add()"); + using _serialize_check = sqlpp::serialize_check_t; + _serialize_check::_(); - using ok = detail::all_t<_is_dynamic::value, is_expression_t::value>; + using ok = detail::all_t<_is_dynamic::value, is_expression_t::value, _serialize_check::type::value>; _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert }