diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index 90b0b417..7c2db471 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -257,7 +257,7 @@ namespace sqlpp template using serialize_check_of = detail::get_first_if::_serialize_check...>; - struct assert_statement_or_prepared_t + struct assert_run_statement_or_prepared_t { using type = std::false_type; @@ -268,10 +268,21 @@ namespace sqlpp }; }; + struct assert_prepare_statement_t + { + using type = std::false_type; + + template + static void _() + { + static_assert(wrong_t::value, "connection cannot prepare something that is not a statement"); + }; + }; + template struct run_check { - using type = assert_statement_or_prepared_t; + using type = assert_run_statement_or_prepared_t; }; template @@ -283,6 +294,21 @@ namespace sqlpp template using run_check_t = typename run_check::type; + template + struct prepare_check + { + using type = assert_prepare_statement_t; + }; + + template + struct prepare_check::value>::type> + { + using type = typename T::_prepare_check; + }; + + template + using prepare_check_t = typename prepare_check::type; + template struct serialize_check diff --git a/tests/MockDb.h b/tests/MockDb.h index 540af0a2..567b24aa 100644 --- a/tests/MockDb.h +++ b/tests/MockDb.h @@ -170,9 +170,22 @@ struct MockDbT: public sqlpp::connection // Prepared statements start here using _prepared_statement_t = std::nullptr_t; + template + auto prepare(const T& t, const std::true_type&) -> decltype(t._prepare(*this)) + { + return t._prepare(*this); + } + + template + auto prepare(const T& t, const std::false_type&) -> decltype(t._prepare(*this)); + template auto prepare(const T& t) -> decltype(t._prepare(*this)) { + sqlpp::prepare_check_t::_(); + sqlpp::serialize_check_t<_serializer_context_t, T>::_(); + using _ok = sqlpp::detail::all_t::type::value, + sqlpp::serialize_check_t<_serializer_context_t, T>::type::value>; return t._prepare(*this); }