| Home | Libraries | People | FAQ | More

###### connection::async_execute (2 of 2 overloads)

Executes a text query or prepared statement.

###### Synopsis

    template<
        class ExecutionRequest,
        class ResultsType,
        class CompletionToken>
    auto
    async_execute(
        ExecutionRequest&& req,
        ResultsType& result,
        diagnostics& diag,
        CompletionToken&& token);

###### Description

Sends `req` to the server for execution and reads the response into `result`. `result` may be either a `results` or `static_results` object. `req` should may be either a type convertible to `string_view` containing valid SQL or a bound prepared statement, obtained by calling `statement::bind`. If a string, it must be encoded using the connection's character set. Any string parameters provided to `statement::bind` should also be encoded using the connection's character set.

After this operation completes successfully, `result.has_value() == true`.

Metadata in `result` will be populated according to `this->meta_mode()`.

###### Object lifetimes

If `CompletionToken` is a deferred completion token (e.g. `use_awaitable`), the caller is responsible for managing `req`'s validity following these rules:

- If `req` is `string_view`, the string pointed to by `req` must be kept alive by the caller until the operation is initiated.
- If `req` is a `bound_statement_tuple`, and any of the parameters is a reference type (like `string_view`), the caller must keep the values pointed by these references alive until the operation is initiated.
- If `req` is a `bound_statement_iterator_range`, the caller must keep objects in the iterator range passed to `statement::bind` alive until the operation is initiated.

###### Handler signature

The handler signature for this operation is `void(boost::mysql::error_code)`.

###### Executor

Intermediate completion handlers, as well as the final handler, are executed using `token`'s associated executor, or `this->get_executor()` if the token doesn't have an associated executor.

If the final handler has an associated immediate executor, and the operation completes immediately, the final handler is dispatched to it. Otherwise, the final handler is called as if it was submitted using `asio::post`, and is never be called inline from within this function.