diff --git a/include/mysql/connection.hpp b/include/mysql/connection.hpp index c3241fe8..2cbd7030 100644 --- a/include/mysql/connection.hpp +++ b/include/mysql/connection.hpp @@ -124,6 +124,9 @@ public: prepared_statement prepare_statement(std::string_view statement, error_code&, error_info&); prepared_statement prepare_statement(std::string_view statement); + + template + auto async_prepare_statement(std::string_view statement, CompletionToken&& token); }; /// A connection to MySQL over TCP. diff --git a/include/mysql/impl/connection.ipp b/include/mysql/impl/connection.ipp index 6f48620c..86970375 100644 --- a/include/mysql/impl/connection.ipp +++ b/include/mysql/impl/connection.ipp @@ -145,5 +145,15 @@ mysql::prepared_statement mysql::connection::prepare_statement( return res; } +template +template +auto mysql::connection::async_prepare_statement( + std::string_view statement, + CompletionToken&& token +) +{ + return detail::async_prepare_statement(channel_, statement, std::forward(token)); +} + #endif diff --git a/include/mysql/impl/prepared_statement.ipp b/include/mysql/impl/prepared_statement.ipp index e575143c..0f677874 100644 --- a/include/mysql/impl/prepared_statement.ipp +++ b/include/mysql/impl/prepared_statement.ipp @@ -56,4 +56,24 @@ mysql::resultset mysql::prepared_statement::execute( return res; } +template +template +auto mysql::prepared_statement::async_execute( + ForwardIterator params_first, + ForwardIterator params_last, + CompletionToken&& token +) const +{ + // TODO: actually return an error message here instead of crashing + assert(std::distance(params_first, params_last) == num_params()); + return detail::async_execute_statement( + *channel_, + stmt_msg_.statement_id.value, + params_first, + params_last, + std::forward(token) + ); +} + + #endif /* INCLUDE_MYSQL_IMPL_PREPARED_STATEMENT_IPP_ */ diff --git a/include/mysql/prepared_statement.hpp b/include/mysql/prepared_statement.hpp index 1cd960cb..fdd00880 100644 --- a/include/mysql/prepared_statement.hpp +++ b/include/mysql/prepared_statement.hpp @@ -37,6 +37,12 @@ public: return execute(std::begin(params), std::end(params)); } + template + auto async_execute(const Collection& params, CompletionToken&& token) const + { + return async_execute(std::begin(params), std::end(params), std::forward(token)); + } + template resultset execute(ForwardIterator params_first, ForwardIterator params_last, error_code&, error_info&) const; @@ -44,6 +50,9 @@ public: template resultset execute(ForwardIterator params_first, ForwardIterator params_last) const; + + template + auto async_execute(ForwardIterator params_first, ForwardIterator params_last, CompletionToken&& token) const; }; using tcp_prepared_statement = prepared_statement;