mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 04:47:18 +08:00
Added prepare_check
This commit is contained in:
parent
809d42e4a1
commit
7ba973d9af
@ -257,7 +257,7 @@ namespace sqlpp
|
|||||||
template<typename Context, typename... T>
|
template<typename Context, typename... T>
|
||||||
using serialize_check_of = detail::get_first_if<is_inconsistent_t, consistent_t, typename serializer_t<Context, T>::_serialize_check...>;
|
using serialize_check_of = detail::get_first_if<is_inconsistent_t, consistent_t, typename serializer_t<Context, T>::_serialize_check...>;
|
||||||
|
|
||||||
struct assert_statement_or_prepared_t
|
struct assert_run_statement_or_prepared_t
|
||||||
{
|
{
|
||||||
using type = std::false_type;
|
using type = std::false_type;
|
||||||
|
|
||||||
@ -268,10 +268,21 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct assert_prepare_statement_t
|
||||||
|
{
|
||||||
|
using type = std::false_type;
|
||||||
|
|
||||||
|
template<typename T = void>
|
||||||
|
static void _()
|
||||||
|
{
|
||||||
|
static_assert(wrong_t<T>::value, "connection cannot prepare something that is not a statement");
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
template<typename T, typename Enable = void>
|
template<typename T, typename Enable = void>
|
||||||
struct run_check
|
struct run_check
|
||||||
{
|
{
|
||||||
using type = assert_statement_or_prepared_t;
|
using type = assert_run_statement_or_prepared_t;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@ -283,6 +294,21 @@ namespace sqlpp
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
using run_check_t = typename run_check<T>::type;
|
using run_check_t = typename run_check<T>::type;
|
||||||
|
|
||||||
|
template<typename T, typename Enable = void>
|
||||||
|
struct prepare_check
|
||||||
|
{
|
||||||
|
using type = assert_prepare_statement_t;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct prepare_check<T, typename std::enable_if<is_statement_t<T>::value>::type>
|
||||||
|
{
|
||||||
|
using type = typename T::_prepare_check;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
using prepare_check_t = typename prepare_check<T>::type;
|
||||||
|
|
||||||
|
|
||||||
template<typename Context, typename T, typename Enable = void>
|
template<typename Context, typename T, typename Enable = void>
|
||||||
struct serialize_check
|
struct serialize_check
|
||||||
|
@ -170,9 +170,22 @@ struct MockDbT: public sqlpp::connection
|
|||||||
// Prepared statements start here
|
// Prepared statements start here
|
||||||
using _prepared_statement_t = std::nullptr_t;
|
using _prepared_statement_t = std::nullptr_t;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
auto prepare(const T& t, const std::true_type&) -> decltype(t._prepare(*this))
|
||||||
|
{
|
||||||
|
return t._prepare(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
auto prepare(const T& t, const std::false_type&) -> decltype(t._prepare(*this));
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
auto prepare(const T& t) -> decltype(t._prepare(*this))
|
auto prepare(const T& t) -> decltype(t._prepare(*this))
|
||||||
{
|
{
|
||||||
|
sqlpp::prepare_check_t<T>::_();
|
||||||
|
sqlpp::serialize_check_t<_serializer_context_t, T>::_();
|
||||||
|
using _ok = sqlpp::detail::all_t<sqlpp::run_check_t<T>::type::value,
|
||||||
|
sqlpp::serialize_check_t<_serializer_context_t, T>::type::value>;
|
||||||
return t._prepare(*this);
|
return t._prepare(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user