diff --git a/include/sqlpp11/pool_connection.h b/include/sqlpp11/pool_connection.h index cc9bfe09..436a5d5d 100644 --- a/include/sqlpp11/pool_connection.h +++ b/include/sqlpp11/pool_connection.h @@ -29,6 +29,7 @@ #include #include +#include #include namespace sqlpp @@ -88,6 +89,30 @@ namespace sqlpp { return _impl->prepare(t); } + + template::value || + is_invocable::value || + is_invocable::value && + !is_invocable::value, int>::type = 0> + void operator()(Query query, Lambda callback) + { + try + { + invoke_callback(sqlpp::exception(sqlpp::exception::ok), pool_connection(), std::move(operator()(query)), callback); + } + catch (const std::exception& e) + { + invoke_callback(sqlpp::exception(sqlpp::exception::query_error, e.what()), pool_connection(), decltype(pool_connection()(Query()))(), callback); + } + } + + template::value, int>::type = 0> + void operator()(Query query, Lambda callback) + { + static_assert(false, "Direct query with pool connection forbids callback with parameter of type connection."); + } }; }