any_connection.hpp 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  1. //
  2. // Copyright (c) 2019-2024 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. #ifndef BOOST_MYSQL_ANY_CONNECTION_HPP
  8. #define BOOST_MYSQL_ANY_CONNECTION_HPP
  9. #include <boost/mysql/character_set.hpp>
  10. #include <boost/mysql/connect_params.hpp>
  11. #include <boost/mysql/defaults.hpp>
  12. #include <boost/mysql/diagnostics.hpp>
  13. #include <boost/mysql/error_code.hpp>
  14. #include <boost/mysql/execution_state.hpp>
  15. #include <boost/mysql/handshake_params.hpp>
  16. #include <boost/mysql/metadata_mode.hpp>
  17. #include <boost/mysql/results.hpp>
  18. #include <boost/mysql/rows_view.hpp>
  19. #include <boost/mysql/statement.hpp>
  20. #include <boost/mysql/string_view.hpp>
  21. #include <boost/mysql/detail/access.hpp>
  22. #include <boost/mysql/detail/algo_params.hpp>
  23. #include <boost/mysql/detail/any_stream.hpp>
  24. #include <boost/mysql/detail/config.hpp>
  25. #include <boost/mysql/detail/connect_params_helpers.hpp>
  26. #include <boost/mysql/detail/connection_impl.hpp>
  27. #include <boost/mysql/detail/execution_concepts.hpp>
  28. #include <boost/mysql/detail/throw_on_error_loc.hpp>
  29. #include <boost/asio/any_io_executor.hpp>
  30. #include <boost/asio/consign.hpp>
  31. #include <boost/asio/execution_context.hpp>
  32. #include <boost/asio/ssl/context.hpp>
  33. #include <boost/assert.hpp>
  34. #include <boost/system/result.hpp>
  35. #include <boost/variant2/variant.hpp>
  36. #include <cstddef>
  37. #include <memory>
  38. #include <type_traits>
  39. #include <utility>
  40. namespace boost {
  41. namespace mysql {
  42. // Forward declarations
  43. template <class... StaticRow>
  44. class static_execution_state;
  45. /**
  46. * \brief (EXPERIMENTAL) Configuration parameters that can be passed to \ref any_connection's constructor.
  47. *
  48. * \par Experimental
  49. * This part of the API is experimental, and may change in successive
  50. * releases without previous notice.
  51. */
  52. struct any_connection_params
  53. {
  54. /**
  55. * \brief An external SSL context containing options to configure TLS.
  56. * \details
  57. * Relevant only for SSL connections (those that result on \ref
  58. * any_connection::uses_ssl returning `true`).
  59. * \n
  60. * If the connection is configured to use TLS, an internal `asio::ssl::stream`
  61. * object will be created. If this member is set to a non-null value,
  62. * this internal object will be initialized using the passed context.
  63. * This is the only way to configure TLS options in `any_connection`.
  64. * \n
  65. * If the connection is configured to use TLS and this member is `nullptr`,
  66. * an internal `asio::ssl::context` object with suitable default options
  67. * will be created.
  68. *
  69. * \par Object lifetimes
  70. * If set to non-null, the pointee object must be kept alive until
  71. * all \ref any_connection objects constructed from `*this` are destroyed.
  72. */
  73. asio::ssl::context* ssl_context{};
  74. /**
  75. * \brief The initial size of the connection's read buffer.
  76. * \details A bigger read buffer can increase the number of rows
  77. * returned by \ref any_connection::read_some_rows.
  78. */
  79. std::size_t initial_read_buffer_size{default_initial_read_buffer_size};
  80. };
  81. /**
  82. * \brief (EXPERIMENTAL) A type-erased connection to a MySQL server.
  83. * \details
  84. * Represents a connection to a MySQL server. Compared to \ref connection, this class:
  85. * \n
  86. * \li Is type-erased. The type of the connection doesn't depend on the transport being used.
  87. * Supported transports include plaintext TCP, SSL over TCP and UNIX domain sockets.
  88. * \li Is easier to connect, as \ref connect and \ref async_connect handle hostname resolution.
  89. * \li Can always be re-connected after being used or encountering an error.
  90. * \li Doesn't support default completion tokens.
  91. * \n
  92. * Provides a level of performance similar to \ref connection.
  93. * \n
  94. * This is a move-only type.
  95. * \n
  96. * \par Thread safety
  97. * Distinct objects: safe. \n
  98. * Shared objects: unsafe. \n
  99. * This class is <b>not thread-safe</b>: for a single object, if you
  100. * call its member functions concurrently from separate threads, you will get a race condition.
  101. *
  102. * \par Experimental
  103. * This part of the API is experimental, and may change in successive
  104. * releases without previous notice.
  105. */
  106. class any_connection
  107. {
  108. detail::connection_impl impl_;
  109. #ifndef BOOST_MYSQL_DOXYGEN
  110. friend struct detail::access;
  111. #endif
  112. BOOST_MYSQL_DECL
  113. static std::unique_ptr<detail::any_stream> create_stream(
  114. asio::any_io_executor ex,
  115. asio::ssl::context* ctx
  116. );
  117. template <class CompletionToken>
  118. using async_connect_owning_t = detail::async_connect_t<
  119. detail::any_address_view,
  120. decltype(asio::consign(std::declval<CompletionToken>(), std::unique_ptr<char[]>()))>;
  121. public:
  122. /**
  123. * \brief Constructs a connection object from an executor and an optional set of parameters.
  124. * \details
  125. * The resulting connection has `this->get_executor() == ex`. Any internally required I/O objects
  126. * will be constructed using this executor.
  127. * \n
  128. * You can configure extra parameters, like the SSL context and buffer sizes, by passing
  129. * an \ref any_connection_params object to this constructor.
  130. */
  131. any_connection(boost::asio::any_io_executor ex, any_connection_params params = {})
  132. : impl_(params.initial_read_buffer_size, create_stream(std::move(ex), params.ssl_context))
  133. {
  134. }
  135. /**
  136. * \brief Constructs a connection object from an execution context and an optional set of parameters.
  137. * \details
  138. * The resulting connection has `this->get_executor() == ctx.get_executor()`.
  139. * Any internally required I/O objects will be constructed using this executor.
  140. * \n
  141. * You can configure extra parameters, like the SSL context and buffer sizes, by passing
  142. * an \ref any_connection_params object to this constructor.
  143. * \n
  144. * This function participates in overload resolution only if `ExecutionContext`
  145. * satisfies the `ExecutionContext` requirements imposed by Boost.Asio.
  146. */
  147. template <
  148. class ExecutionContext
  149. #ifndef BOOST_MYSQL_DOXYGEN
  150. ,
  151. class = typename std::enable_if<std::is_convertible<
  152. decltype(std::declval<ExecutionContext&>().get_executor()),
  153. asio::any_io_executor>::value>::type
  154. #endif
  155. >
  156. any_connection(ExecutionContext& ctx, any_connection_params params = {})
  157. : any_connection(ctx.get_executor(), params)
  158. {
  159. }
  160. /**
  161. * \brief Move constructor.
  162. */
  163. any_connection(any_connection&& other) = default;
  164. /**
  165. * \brief Move assignment.
  166. */
  167. any_connection& operator=(any_connection&& rhs) = default;
  168. #ifndef BOOST_MYSQL_DOXYGEN
  169. any_connection(const any_connection&) = delete;
  170. any_connection& operator=(const any_connection&) = delete;
  171. #endif
  172. /**
  173. * \brief Destructor.
  174. * \details
  175. * Closes the connection at the transport layer (by closing any underlying socket objects).
  176. * If you require a clean close, call \ref close or \ref async_close before the connection
  177. * is destroyed.
  178. */
  179. ~any_connection() = default;
  180. /// The executor type associated to this object.
  181. using executor_type = asio::any_io_executor;
  182. /**
  183. * \brief Retrieves the executor associated to this object.
  184. * \par Exception safety
  185. * No-throw guarantee.
  186. */
  187. executor_type get_executor() noexcept { return impl_.stream().get_executor(); }
  188. /**
  189. * \brief Returns whether the connection negotiated the use of SSL or not.
  190. * \details
  191. * This function can be used to determine whether you are using a SSL
  192. * connection or not when using SSL negotiation.
  193. * \n
  194. * This function always returns `false`
  195. * for connections that haven't been established yet. If the connection establishment fails,
  196. * the return value is undefined.
  197. *
  198. * \par Exception safety
  199. * No-throw guarantee.
  200. */
  201. bool uses_ssl() const noexcept { return impl_.ssl_active(); }
  202. /**
  203. * \brief Returns whether backslashes are being treated as escape sequences.
  204. * \details
  205. * By default, the server treats backslashes in string values as escape characters.
  206. * This behavior can be disabled by activating the <a
  207. * href="https://dev.mysql.com/doc/refman/8.0/en/sql-mode.html#sqlmode_no_backslash_escapes">`NO_BACKSLASH_ESCAPES`</a>
  208. * SQL mode.
  209. * \n
  210. * Every time an operation involving server communication completes, the server reports whether
  211. * this mode was activated or not as part of the response. Connections store this information
  212. * and make it available through this function.
  213. * \n
  214. * \li If backslash are treated like escape characters, returns `true`.
  215. * \li If `NO_BACKSLASH_ESCAPES` has been activated, returns `false`.
  216. * \li If connection establishment hasn't happened yet, returns `true`.
  217. * \li Calling this function while an async operation that changes backslash behavior
  218. * is outstanding may return `true` or `false`.
  219. * \n
  220. * This function does not involve server communication.
  221. *
  222. * \par Exception safety
  223. * No-throw guarantee.
  224. */
  225. bool backslash_escapes() const noexcept { return impl_.backslash_escapes(); }
  226. /**
  227. * \brief Returns the character set used by this connection.
  228. * \details
  229. * Connections attempt to keep track of the current character set.
  230. * Deficiencies in the protocol can cause the character set to be unknown, though.
  231. * When the character set is known, this function returns
  232. * the character set currently in use. Otherwise, returns \ref client_errc::unknown_character_set.
  233. * \n
  234. * The following functions can modify the return value of this function: \n
  235. * \li Prior to connection, the character set is always unknown.
  236. * \li \ref connect and \ref async_connect may set the current character set
  237. * to a known value, depending on the requested collation.
  238. * \li \ref set_character_set always and \ref async_set_character_set always
  239. * set the current character set to the passed value.
  240. * \li \ref reset_connection and \ref async_reset_connection always makes the current character
  241. * unknown.
  242. *
  243. * \par Avoid changing the character set directly
  244. * If you change the connection's character set directly using SQL statements
  245. * like `"SET NAMES utf8mb4"`, the client has no way to track this change,
  246. * and this function will return incorrect results.
  247. *
  248. * \par Errors
  249. * \li \ref client_errc::unknown_character_set if the current character set is unknown.
  250. *
  251. * \par Exception safety
  252. * No-throw guarantee.
  253. */
  254. system::result<character_set> current_character_set() const noexcept
  255. {
  256. return impl_.current_character_set();
  257. }
  258. /**
  259. * \brief Returns format options suitable to format SQL according to the current connection configuation.
  260. * \details
  261. * If the current character set is known (as given by \ref current_character_set), returns
  262. * a value suitable to be passed to SQL formatting functions. Otherwise, returns an error.
  263. *
  264. * \par Errors
  265. * \li \ref client_errc::unknown_character_set if the current character set is unknown.
  266. *
  267. * \par Exception safety
  268. * No-throw guarantee.
  269. */
  270. system::result<format_options> format_opts() const noexcept
  271. {
  272. auto res = current_character_set();
  273. if (res.has_error())
  274. return res.error();
  275. return format_options{res.value(), backslash_escapes()};
  276. }
  277. /// \copydoc connection::meta_mode
  278. metadata_mode meta_mode() const noexcept { return impl_.meta_mode(); }
  279. /// \copydoc connection::set_meta_mode
  280. void set_meta_mode(metadata_mode v) noexcept { impl_.set_meta_mode(v); }
  281. /**
  282. * \brief Establishes a connection to a MySQL server.
  283. * \details
  284. * This function performs the following:
  285. * \n
  286. * \li If a connection has already been established (by a previous call to \ref connect
  287. * or \ref async_connect), closes it at the transport layer (by closing any underlying socket)
  288. * and discards any protocol state associated to it. (If you require
  289. * a clean close, call \ref close or \ref async_close before using this function).
  290. * \li If the connection is configured to use TCP (`params.server_address.type() ==
  291. * address_type::host_and_port`), resolves the passed hostname to a set of endpoints. An empty
  292. * hostname is equivalent to `"localhost"`.
  293. * \li Establishes the physical connection (performing the
  294. * TCP or UNIX socket connect).
  295. * \li Performs the MySQL handshake to establish a session. If the
  296. * connection is configured to use TLS, the TLS handshake is performed as part of this step.
  297. * \li If any of the above steps fail, the TCP or UNIX socket connection is closed.
  298. * \n
  299. * You can configure some options using the \ref connect_params struct.
  300. * \n
  301. * The decision to use TLS or not is performed using the following:
  302. * \n
  303. * \li If the transport is not TCP (`params.server_address.type() != address_type::host_and_port`),
  304. * the connection will never use TLS.
  305. * \li If the transport is TCP, and `params.ssl == ssl_mode::disable`, the connection will not use TLS.
  306. * \li If the transport is TCP, and `params.ssl == ssl_mode::enable`, the connection will use TLS
  307. * only if the server supports it.
  308. * \li If the transport is TCP, and `params.ssl == ssl_mode::require`, the connection will always use TLS.
  309. * If the server doesn't support it, this function will fail with \ref
  310. * client_errc::server_doesnt_support_ssl.
  311. * \n
  312. * If `params.connection_collation` is within a set of well-known collations, this function
  313. * sets the current character set, such that \ref current_character_set returns a non-null value.
  314. * The default collation (`utf8mb4_general_ci`) is the only one guaranteed to be in the set of well-known
  315. * collations.
  316. */
  317. void connect(const connect_params& params, error_code& ec, diagnostics& diag)
  318. {
  319. impl_.connect(detail::make_view(params.server_address), detail::make_hparams(params), ec, diag);
  320. }
  321. /// \copydoc connect
  322. void connect(const connect_params& params)
  323. {
  324. error_code err;
  325. diagnostics diag;
  326. connect(params, err, diag);
  327. detail::throw_on_error_loc(err, diag, BOOST_CURRENT_LOCATION);
  328. }
  329. /**
  330. * \copydoc connect
  331. *
  332. * \par Object lifetimes
  333. * The implementation will copy `params` as required, so it needs not be
  334. * kept alive.
  335. *
  336. * \par Handler signature
  337. * The handler signature for this operation is `void(boost::mysql::error_code)`.
  338. */
  339. template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code)) CompletionToken>
  340. auto async_connect(const connect_params& params, diagnostics& diag, CompletionToken&& token)
  341. BOOST_MYSQL_RETURN_TYPE(async_connect_owning_t<CompletionToken&&>)
  342. {
  343. auto stable_prms = detail::make_stable(params);
  344. return impl_.async_connect(
  345. stable_prms.address,
  346. stable_prms.hparams,
  347. diag,
  348. asio::consign(std::forward<CompletionToken>(token), std::move(stable_prms.string_buffer))
  349. );
  350. }
  351. /// \copydoc async_connect
  352. template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code)) CompletionToken>
  353. auto async_connect(const connect_params& params, CompletionToken&& token)
  354. BOOST_MYSQL_RETURN_TYPE(async_connect_owning_t<CompletionToken&&>)
  355. {
  356. return async_connect(params, impl_.shared_diag(), std::forward<CompletionToken>(token));
  357. }
  358. /**
  359. * \copydoc connect
  360. * This function has the same behavior as the other `async_connect` overloads,
  361. * but perform less copies.
  362. * \par Object lifetimes
  363. * Zero-copy overload: no copies of the value pointed to by `params`
  364. * will be made. It must be kept alive for the duration of the operation,
  365. * until the final completion handler is called. If you are in doubt,
  366. * prefer the overloads taking a `const connect_params&`, which will ensure
  367. * lifetime correctness for you.
  368. *
  369. * \par Preconditions
  370. * `params != nullptr`
  371. *
  372. * \par Handler signature
  373. * The handler signature for this operation is `void(boost::mysql::error_code)`.
  374. */
  375. template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code)) CompletionToken>
  376. auto async_connect(const connect_params* params, diagnostics& diag, CompletionToken&& token)
  377. BOOST_MYSQL_RETURN_TYPE(detail::async_connect_t<detail::any_address_view, CompletionToken&&>)
  378. {
  379. BOOST_ASSERT(params != nullptr);
  380. return impl_.async_connect(
  381. detail::make_view(params->server_address),
  382. detail::make_hparams(*params),
  383. diag,
  384. std::forward<CompletionToken>(token)
  385. );
  386. }
  387. /// \copydoc connection::execute
  388. template <BOOST_MYSQL_EXECUTION_REQUEST ExecutionRequest, BOOST_MYSQL_RESULTS_TYPE ResultsType>
  389. void execute(const ExecutionRequest& req, ResultsType& result, error_code& err, diagnostics& diag)
  390. {
  391. impl_.execute(req, result, err, diag);
  392. }
  393. /// \copydoc execute
  394. template <BOOST_MYSQL_EXECUTION_REQUEST ExecutionRequest, BOOST_MYSQL_RESULTS_TYPE ResultsType>
  395. void execute(const ExecutionRequest& req, ResultsType& result)
  396. {
  397. error_code err;
  398. diagnostics diag;
  399. execute(req, result, err, diag);
  400. detail::throw_on_error_loc(err, diag, BOOST_CURRENT_LOCATION);
  401. }
  402. /// \copydoc connection::async_execute
  403. template <
  404. BOOST_MYSQL_EXECUTION_REQUEST ExecutionRequest,
  405. BOOST_MYSQL_RESULTS_TYPE ResultsType,
  406. BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
  407. auto async_execute(ExecutionRequest&& req, ResultsType& result, CompletionToken&& token)
  408. BOOST_MYSQL_RETURN_TYPE(detail::async_execute_t<ExecutionRequest&&, ResultsType, CompletionToken&&>)
  409. {
  410. return async_execute(
  411. std::forward<ExecutionRequest>(req),
  412. result,
  413. impl_.shared_diag(),
  414. std::forward<CompletionToken>(token)
  415. );
  416. }
  417. /// \copydoc async_execute
  418. template <
  419. BOOST_MYSQL_EXECUTION_REQUEST ExecutionRequest,
  420. BOOST_MYSQL_RESULTS_TYPE ResultsType,
  421. BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
  422. auto async_execute(
  423. ExecutionRequest&& req,
  424. ResultsType& result,
  425. diagnostics& diag,
  426. CompletionToken&& token
  427. ) BOOST_MYSQL_RETURN_TYPE(detail::async_execute_t<ExecutionRequest&&, ResultsType, CompletionToken&&>)
  428. {
  429. return impl_.async_execute(
  430. std::forward<ExecutionRequest>(req),
  431. result,
  432. diag,
  433. std::forward<CompletionToken>(token)
  434. );
  435. }
  436. /// \copydoc connection::start_execution
  437. template <
  438. BOOST_MYSQL_EXECUTION_REQUEST ExecutionRequest,
  439. BOOST_MYSQL_EXECUTION_STATE_TYPE ExecutionStateType>
  440. void start_execution(
  441. const ExecutionRequest& req,
  442. ExecutionStateType& st,
  443. error_code& err,
  444. diagnostics& diag
  445. )
  446. {
  447. impl_.start_execution(req, st, err, diag);
  448. }
  449. /// \copydoc start_execution
  450. template <
  451. BOOST_MYSQL_EXECUTION_REQUEST ExecutionRequest,
  452. BOOST_MYSQL_EXECUTION_STATE_TYPE ExecutionStateType>
  453. void start_execution(const ExecutionRequest& req, ExecutionStateType& st)
  454. {
  455. error_code err;
  456. diagnostics diag;
  457. start_execution(req, st, err, diag);
  458. detail::throw_on_error_loc(err, diag, BOOST_CURRENT_LOCATION);
  459. }
  460. /// \copydoc connection::async_start_execution
  461. template <
  462. BOOST_MYSQL_EXECUTION_REQUEST ExecutionRequest,
  463. BOOST_MYSQL_EXECUTION_STATE_TYPE ExecutionStateType,
  464. BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
  465. auto async_start_execution(ExecutionRequest&& req, ExecutionStateType& st, CompletionToken&& token)
  466. BOOST_MYSQL_RETURN_TYPE(detail::async_start_execution_t<
  467. ExecutionRequest&&,
  468. ExecutionStateType,
  469. CompletionToken&&>)
  470. {
  471. return async_start_execution(
  472. std::forward<ExecutionRequest>(req),
  473. st,
  474. impl_.shared_diag(),
  475. std::forward<CompletionToken>(token)
  476. );
  477. }
  478. /// \copydoc async_start_execution
  479. template <
  480. BOOST_MYSQL_EXECUTION_REQUEST ExecutionRequest,
  481. BOOST_MYSQL_EXECUTION_STATE_TYPE ExecutionStateType,
  482. BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
  483. auto async_start_execution(
  484. ExecutionRequest&& req,
  485. ExecutionStateType& st,
  486. diagnostics& diag,
  487. CompletionToken&& token
  488. )
  489. BOOST_MYSQL_RETURN_TYPE(detail::async_start_execution_t<
  490. ExecutionRequest&&,
  491. ExecutionStateType,
  492. CompletionToken&&>)
  493. {
  494. return impl_.async_start_execution(
  495. std::forward<ExecutionRequest>(req),
  496. st,
  497. diag,
  498. std::forward<CompletionToken>(token)
  499. );
  500. }
  501. /// \copydoc connection::prepare_statement
  502. statement prepare_statement(string_view stmt, error_code& err, diagnostics& diag)
  503. {
  504. return impl_.run(detail::prepare_statement_algo_params{&diag, stmt}, err);
  505. }
  506. /// \copydoc prepare_statement
  507. statement prepare_statement(string_view stmt)
  508. {
  509. error_code err;
  510. diagnostics diag;
  511. statement res = prepare_statement(stmt, err, diag);
  512. detail::throw_on_error_loc(err, diag, BOOST_CURRENT_LOCATION);
  513. return res;
  514. }
  515. /// \copydoc connection::async_prepare_statement
  516. template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code, ::boost::mysql::statement))
  517. CompletionToken>
  518. auto async_prepare_statement(string_view stmt, CompletionToken&& token)
  519. BOOST_MYSQL_RETURN_TYPE(detail::async_prepare_statement_t<CompletionToken&&>)
  520. {
  521. return async_prepare_statement(stmt, impl_.shared_diag(), std::forward<CompletionToken>(token));
  522. }
  523. /// \copydoc async_prepare_statement
  524. template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code, ::boost::mysql::statement))
  525. CompletionToken>
  526. auto async_prepare_statement(string_view stmt, diagnostics& diag, CompletionToken&& token)
  527. BOOST_MYSQL_RETURN_TYPE(detail::async_prepare_statement_t<CompletionToken&&>)
  528. {
  529. return impl_.async_run(
  530. detail::prepare_statement_algo_params{&diag, stmt},
  531. std::forward<CompletionToken>(token)
  532. );
  533. }
  534. /// \copydoc connection::close_statement
  535. void close_statement(const statement& stmt, error_code& err, diagnostics& diag)
  536. {
  537. impl_.run(impl_.make_params_close_statement(stmt, diag), err);
  538. }
  539. /// \copydoc close_statement
  540. void close_statement(const statement& stmt)
  541. {
  542. error_code err;
  543. diagnostics diag;
  544. close_statement(stmt, err, diag);
  545. detail::throw_on_error_loc(err, diag, BOOST_CURRENT_LOCATION);
  546. }
  547. /// \copydoc connection::async_close_statement
  548. template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
  549. auto async_close_statement(const statement& stmt, CompletionToken&& token)
  550. BOOST_MYSQL_RETURN_TYPE(detail::async_close_statement_t<CompletionToken&&>)
  551. {
  552. return async_close_statement(stmt, impl_.shared_diag(), std::forward<CompletionToken>(token));
  553. }
  554. /// \copydoc async_close_statement
  555. template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
  556. auto async_close_statement(const statement& stmt, diagnostics& diag, CompletionToken&& token)
  557. BOOST_MYSQL_RETURN_TYPE(detail::async_close_statement_t<CompletionToken&&>)
  558. {
  559. return impl_.async_run(
  560. impl_.make_params_close_statement(stmt, diag),
  561. std::forward<CompletionToken>(token)
  562. );
  563. }
  564. /// \copydoc connection::read_some_rows
  565. rows_view read_some_rows(execution_state& st, error_code& err, diagnostics& diag)
  566. {
  567. return impl_.run(impl_.make_params_read_some_rows(st, diag), err);
  568. }
  569. /// \copydoc read_some_rows(execution_state&,error_code&,diagnostics&)
  570. rows_view read_some_rows(execution_state& st)
  571. {
  572. error_code err;
  573. diagnostics diag;
  574. rows_view res = read_some_rows(st, err, diag);
  575. detail::throw_on_error_loc(err, diag, BOOST_CURRENT_LOCATION);
  576. return res;
  577. }
  578. /// \copydoc connection::async_read_some_rows(execution_state&,CompletionToken&&)
  579. template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code, ::boost::mysql::rows_view))
  580. CompletionToken>
  581. auto async_read_some_rows(execution_state& st, CompletionToken&& token)
  582. BOOST_MYSQL_RETURN_TYPE(detail::async_read_some_rows_dynamic_t<CompletionToken&&>)
  583. {
  584. return async_read_some_rows(st, impl_.shared_diag(), std::forward<CompletionToken>(token));
  585. }
  586. /// \copydoc async_read_some_rows(execution_state&,CompletionToken&&)
  587. template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code, ::boost::mysql::rows_view))
  588. CompletionToken>
  589. auto async_read_some_rows(execution_state& st, diagnostics& diag, CompletionToken&& token)
  590. BOOST_MYSQL_RETURN_TYPE(detail::async_read_some_rows_dynamic_t<CompletionToken&&>)
  591. {
  592. return impl_.async_run(
  593. impl_.make_params_read_some_rows(st, diag),
  594. std::forward<CompletionToken>(token)
  595. );
  596. }
  597. #ifdef BOOST_MYSQL_CXX14
  598. /**
  599. * \brief Reads a batch of rows.
  600. * \details
  601. * Reads a batch of rows of unspecified size into the storage given by `output`.
  602. * At most `output.size()` rows will be read. If the operation represented by `st`
  603. * has still rows to read, and `output.size() > 0`, at least one row will be read.
  604. * \n
  605. * Returns the number of read rows.
  606. * \n
  607. * If there are no more rows, or `st.should_read_rows() == false`, this function is a no-op and returns
  608. * zero.
  609. * \n
  610. * The number of rows that will be read depends on the input buffer size. The bigger the buffer,
  611. * the greater the batch size (up to a maximum). You can set the initial buffer size in the
  612. * constructor. The buffer may be grown bigger by other read operations, if required.
  613. * \n
  614. * Rows read by this function are owning objects, and don't hold any reference to
  615. * the connection's internal buffers (contrary what happens with the dynamic interface's counterpart).
  616. * \n
  617. * `SpanStaticRow` must exactly be one of the types in the `StaticRow` parameter pack.
  618. * The type must match the resultset that is currently being processed by `st`. For instance,
  619. * given `static_execution_state<T1, T2>`, when reading rows for the second resultset, `SpanStaticRow`
  620. * must exactly be `T2`. If this is not the case, a runtime error will be issued.
  621. * \n
  622. * This function can report schema mismatches.
  623. */
  624. template <class SpanStaticRow, class... StaticRow>
  625. std::size_t read_some_rows(
  626. static_execution_state<StaticRow...>& st,
  627. span<SpanStaticRow> output,
  628. error_code& err,
  629. diagnostics& diag
  630. )
  631. {
  632. return impl_.run(impl_.make_params_read_some_rows(st, output, diag), err);
  633. }
  634. /**
  635. * \brief Reads a batch of rows.
  636. * \details
  637. * Reads a batch of rows of unspecified size into the storage given by `output`.
  638. * At most `output.size()` rows will be read. If the operation represented by `st`
  639. * has still rows to read, and `output.size() > 0`, at least one row will be read.
  640. * \n
  641. * Returns the number of read rows.
  642. * \n
  643. * If there are no more rows, or `st.should_read_rows() == false`, this function is a no-op and returns
  644. * zero.
  645. * \n
  646. * The number of rows that will be read depends on the input buffer size. The bigger the buffer,
  647. * the greater the batch size (up to a maximum). You can set the initial buffer size in the
  648. * constructor. The buffer may be grown bigger by other read operations, if required.
  649. * \n
  650. * Rows read by this function are owning objects, and don't hold any reference to
  651. * the connection's internal buffers (contrary what happens with the dynamic interface's counterpart).
  652. * \n
  653. * `SpanStaticRow` must exactly be one of the types in the `StaticRow` parameter pack.
  654. * The type must match the resultset that is currently being processed by `st`. For instance,
  655. * given `static_execution_state<T1, T2>`, when reading rows for the second resultset, `SpanStaticRow`
  656. * must exactly be `T2`. If this is not the case, a runtime error will be issued.
  657. * \n
  658. * This function can report schema mismatches.
  659. */
  660. template <class SpanStaticRow, class... StaticRow>
  661. std::size_t read_some_rows(static_execution_state<StaticRow...>& st, span<SpanStaticRow> output)
  662. {
  663. error_code err;
  664. diagnostics diag;
  665. std::size_t res = read_some_rows(st, output, err, diag);
  666. detail::throw_on_error_loc(err, diag, BOOST_CURRENT_LOCATION);
  667. return res;
  668. }
  669. /**
  670. * \brief Reads a batch of rows.
  671. * \details
  672. * Reads a batch of rows of unspecified size into the storage given by `output`.
  673. * At most `output.size()` rows will be read. If the operation represented by `st`
  674. * has still rows to read, and `output.size() > 0`, at least one row will be read.
  675. * \n
  676. * Returns the number of read rows.
  677. * \n
  678. * If there are no more rows, or `st.should_read_rows() == false`, this function is a no-op and returns
  679. * zero.
  680. * \n
  681. * The number of rows that will be read depends on the input buffer size. The bigger the buffer,
  682. * the greater the batch size (up to a maximum). You can set the initial buffer size in the
  683. * constructor. The buffer may be grown bigger by other read operations, if required.
  684. * \n
  685. * Rows read by this function are owning objects, and don't hold any reference to
  686. * the connection's internal buffers (contrary what happens with the dynamic interface's counterpart).
  687. * \n
  688. * `SpanStaticRow` must exactly be one of the types in the `StaticRow` parameter pack.
  689. * The type must match the resultset that is currently being processed by `st`. For instance,
  690. * given `static_execution_state<T1, T2>`, when reading rows for the second resultset, `SpanStaticRow`
  691. * must exactly be `T2`. If this is not the case, a runtime error will be issued.
  692. * \n
  693. * This function can report schema mismatches.
  694. *
  695. * \par Handler signature
  696. * The handler signature for this operation is
  697. * `void(boost::mysql::error_code, std::size_t)`.
  698. *
  699. * \par Object lifetimes
  700. * The storage that `output` references must be kept alive until the operation completes.
  701. */
  702. template <
  703. class SpanStaticRow,
  704. class... StaticRow,
  705. BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code, std::size_t))
  706. CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
  707. auto async_read_some_rows(
  708. static_execution_state<StaticRow...>& st,
  709. span<SpanStaticRow> output,
  710. CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)
  711. )
  712. {
  713. return async_read_some_rows(st, output, impl_.shared_diag(), std::forward<CompletionToken>(token));
  714. }
  715. /**
  716. * \brief Reads a batch of rows.
  717. * \details
  718. * Reads a batch of rows of unspecified size into the storage given by `output`.
  719. * At most `output.size()` rows will be read. If the operation represented by `st`
  720. * has still rows to read, and `output.size() > 0`, at least one row will be read.
  721. * \n
  722. * Returns the number of read rows.
  723. * \n
  724. * If there are no more rows, or `st.should_read_rows() == false`, this function is a no-op and returns
  725. * zero.
  726. * \n
  727. * The number of rows that will be read depends on the input buffer size. The bigger the buffer,
  728. * the greater the batch size (up to a maximum). You can set the initial buffer size in the
  729. * constructor. The buffer may be grown bigger by other read operations, if required.
  730. * \n
  731. * Rows read by this function are owning objects, and don't hold any reference to
  732. * the connection's internal buffers (contrary what happens with the dynamic interface's counterpart).
  733. * \n
  734. * `SpanStaticRow` must exactly be one of the types in the `StaticRow` parameter pack.
  735. * The type must match the resultset that is currently being processed by `st`. For instance,
  736. * given `static_execution_state<T1, T2>`, when reading rows for the second resultset, `SpanStaticRow`
  737. * must exactly be `T2`. If this is not the case, a runtime error will be issued.
  738. * \n
  739. * This function can report schema mismatches.
  740. *
  741. * \par Handler signature
  742. * The handler signature for this operation is
  743. * `void(boost::mysql::error_code, std::size_t)`.
  744. *
  745. * \par Object lifetimes
  746. * The storage that `output` references must be kept alive until the operation completes.
  747. */
  748. template <
  749. class SpanStaticRow,
  750. class... StaticRow,
  751. BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code, std::size_t))
  752. CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
  753. auto async_read_some_rows(
  754. static_execution_state<StaticRow...>& st,
  755. span<SpanStaticRow> output,
  756. diagnostics& diag,
  757. CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)
  758. )
  759. {
  760. return impl_.async_run(
  761. impl_.make_params_read_some_rows(st, output, diag),
  762. std::forward<CompletionToken>(token)
  763. );
  764. }
  765. #endif
  766. /// \copydoc connection::read_resultset_head
  767. template <BOOST_MYSQL_EXECUTION_STATE_TYPE ExecutionStateType>
  768. void read_resultset_head(ExecutionStateType& st, error_code& err, diagnostics& diag)
  769. {
  770. return impl_.run(impl_.make_params_read_resultset_head(st, diag), err);
  771. }
  772. /// \copydoc read_resultset_head
  773. template <BOOST_MYSQL_EXECUTION_STATE_TYPE ExecutionStateType>
  774. void read_resultset_head(ExecutionStateType& st)
  775. {
  776. error_code err;
  777. diagnostics diag;
  778. read_resultset_head(st, err, diag);
  779. detail::throw_on_error_loc(err, diag, BOOST_CURRENT_LOCATION);
  780. }
  781. /// \copydoc connection::async_read_resultset_head
  782. template <
  783. BOOST_MYSQL_EXECUTION_STATE_TYPE ExecutionStateType,
  784. BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
  785. auto async_read_resultset_head(ExecutionStateType& st, CompletionToken&& token)
  786. BOOST_MYSQL_RETURN_TYPE(detail::async_read_resultset_head_t<CompletionToken&&>)
  787. {
  788. return async_read_resultset_head(st, impl_.shared_diag(), std::forward<CompletionToken>(token));
  789. }
  790. /// \copydoc async_read_resultset_head
  791. template <
  792. BOOST_MYSQL_EXECUTION_STATE_TYPE ExecutionStateType,
  793. BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
  794. auto async_read_resultset_head(ExecutionStateType& st, diagnostics& diag, CompletionToken&& token)
  795. BOOST_MYSQL_RETURN_TYPE(detail::async_read_resultset_head_t<CompletionToken&&>)
  796. {
  797. return impl_.async_run(
  798. impl_.make_params_read_resultset_head(st, diag),
  799. std::forward<CompletionToken>(token)
  800. );
  801. }
  802. /**
  803. * \brief Sets the connection's character set, as per SET NAMES.
  804. * \details
  805. * Sets the connection's character set by running a
  806. * <a href="https://dev.mysql.com/doc/refman/8.0/en/set-names.html">`SET NAMES`</a>
  807. * SQL statement, using the passed \ref character_set::name as the charset name to set.
  808. * \n
  809. * This function will also update the value returned by \ref current_character_set, so
  810. * prefer using this function over raw SQL statements.
  811. * \n
  812. * If the server was unable to set the character set to the requested value (e.g. because
  813. * the server does not support the requested charset), this function will fail,
  814. * as opposed to how \ref connect behaves when an unsupported collation is passed.
  815. * This is a limitation of MySQL servers.
  816. * \n
  817. * You need to perform connection establishment for this function to succeed, since it
  818. * involves communicating with the server.
  819. *
  820. * \par Object lifetimes
  821. * `charset` will be copied as required, and does not need to be kept alive.
  822. */
  823. void set_character_set(const character_set& charset, error_code& err, diagnostics& diag)
  824. {
  825. impl_.run(impl_.make_params_set_character_set(charset, diag), err);
  826. }
  827. /// \copydoc set_character_set
  828. void set_character_set(const character_set& charset)
  829. {
  830. error_code err;
  831. diagnostics diag;
  832. set_character_set(charset, err, diag);
  833. detail::throw_on_error_loc(err, diag, BOOST_CURRENT_LOCATION);
  834. }
  835. /**
  836. * \copydoc set_character_set
  837. * \details
  838. * \n
  839. * \par Handler signature
  840. * The handler signature for this operation is `void(boost::mysql::error_code)`.
  841. */
  842. template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
  843. auto async_set_character_set(const character_set& charset, CompletionToken&& token)
  844. BOOST_MYSQL_RETURN_TYPE(detail::async_set_character_set_t<CompletionToken&&>)
  845. {
  846. return async_set_character_set(charset, impl_.shared_diag(), std::forward<CompletionToken>(token));
  847. }
  848. /// \copydoc async_set_character_set
  849. template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
  850. auto async_set_character_set(const character_set& charset, diagnostics& diag, CompletionToken&& token)
  851. BOOST_MYSQL_RETURN_TYPE(detail::async_set_character_set_t<CompletionToken&&>)
  852. {
  853. return impl_.async_run(
  854. impl_.make_params_set_character_set(charset, diag),
  855. std::forward<CompletionToken>(token)
  856. );
  857. }
  858. /// \copydoc connection::ping
  859. void ping(error_code& err, diagnostics& diag) { impl_.run(impl_.make_params_ping(diag), err); }
  860. /// \copydoc ping
  861. void ping()
  862. {
  863. error_code err;
  864. diagnostics diag;
  865. ping(err, diag);
  866. detail::throw_on_error_loc(err, diag, BOOST_CURRENT_LOCATION);
  867. }
  868. /// \copydoc connection::async_ping
  869. template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
  870. auto async_ping(CompletionToken&& token) BOOST_MYSQL_RETURN_TYPE(detail::async_ping_t<CompletionToken&&>)
  871. {
  872. return async_ping(impl_.shared_diag(), std::forward<CompletionToken>(token));
  873. }
  874. /// \copydoc async_ping
  875. template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
  876. auto async_ping(diagnostics& diag, CompletionToken&& token)
  877. BOOST_MYSQL_RETURN_TYPE(detail::async_ping_t<CompletionToken&&>)
  878. {
  879. return impl_.async_run(impl_.make_params_ping(diag), std::forward<CompletionToken>(token));
  880. }
  881. /**
  882. * \brief Resets server-side session state, like variables and prepared statements.
  883. * \details
  884. * Resets all server-side state for the current session:
  885. * \n
  886. * \li Rolls back any active transactions and resets autocommit mode.
  887. * \li Releases all table locks.
  888. * \li Drops all temporary tables.
  889. * \li Resets all session system variables to their default values (including the ones set by `SET
  890. * NAMES`) and clears all user-defined variables.
  891. * \li Closes all prepared statements.
  892. * \n
  893. * A full reference on the affected session state can be found
  894. * <a href="https://dev.mysql.com/doc/c-api/8.0/en/mysql-reset-connection.html">here</a>.
  895. * \n
  896. * \n
  897. * This function will not reset the current physical connection and won't cause re-authentication.
  898. * It is faster than closing and re-opening a connection.
  899. * \n
  900. * The connection must be connected and authenticated before calling this function.
  901. * This function involves communication with the server, and thus may fail.
  902. *
  903. * \par Warning on character sets
  904. * This function will restore the connection's character set and collation **to the server's default**,
  905. * and not to the one specified during connection establishment. Some servers have `latin1` as their
  906. * default character set, which is not usually what you want. Since there is no way to know this
  907. * character set, \ref current_character_set will return `nullptr` after the operation succeeds.
  908. * We recommend always using \ref set_character_set or \ref async_set_character_set after calling this
  909. * function.
  910. * \n
  911. * You can find the character set that your server will use after the reset by running:
  912. * \code
  913. * "SELECT @@global.character_set_client, @@global.character_set_results;"
  914. * \endcode
  915. */
  916. void reset_connection(error_code& err, diagnostics& diag)
  917. {
  918. impl_.run(impl_.make_params_reset_connection(diag), err);
  919. }
  920. /// \copydoc reset_connection
  921. void reset_connection()
  922. {
  923. error_code err;
  924. diagnostics diag;
  925. reset_connection(err, diag);
  926. detail::throw_on_error_loc(err, diag, BOOST_CURRENT_LOCATION);
  927. }
  928. /**
  929. * \copydoc reset_connection
  930. * \details
  931. * \n
  932. * \par Handler signature
  933. * The handler signature for this operation is `void(boost::mysql::error_code)`.
  934. */
  935. template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
  936. auto async_reset_connection(CompletionToken&& token)
  937. BOOST_MYSQL_RETURN_TYPE(detail::async_reset_connection_t<CompletionToken&&>)
  938. {
  939. return async_reset_connection(impl_.shared_diag(), std::forward<CompletionToken>(token));
  940. }
  941. /// \copydoc async_reset_connection
  942. template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
  943. auto async_reset_connection(diagnostics& diag, CompletionToken&& token)
  944. BOOST_MYSQL_RETURN_TYPE(detail::async_reset_connection_t<CompletionToken&&>)
  945. {
  946. return impl_.async_run(
  947. impl_.make_params_reset_connection(diag),
  948. std::forward<CompletionToken>(token)
  949. );
  950. }
  951. /**
  952. * \brief Cleanly closes the connection to the server.
  953. * \details
  954. * This function does the following:
  955. * \n
  956. * \li Sends a quit request. This is required by the MySQL protocol, to inform
  957. * the server that we're closing the connection gracefully.
  958. * \li If the connection is using TLS (`this->uses_ssl() == true`), performs
  959. * the TLS shutdown.
  960. * \li Closes the transport-level connection (the TCP or UNIX socket).
  961. * \n
  962. * Since this function involves writing a message to the server, it can fail.
  963. * Only use this function if you know that the connection is healthy and you want
  964. * to cleanly close it.
  965. * \n
  966. * If you don't call this function, the destructor or successive connects will
  967. * perform a transport-layer close. This doesn't cause any resource leaks, but may
  968. * cause warnings to be written to the server logs.
  969. */
  970. void close(error_code& err, diagnostics& diag)
  971. {
  972. this->impl_.run(this->impl_.make_params_close(diag), err);
  973. }
  974. /// \copydoc close
  975. void close()
  976. {
  977. error_code err;
  978. diagnostics diag;
  979. close(err, diag);
  980. detail::throw_on_error_loc(err, diag, BOOST_CURRENT_LOCATION);
  981. }
  982. /**
  983. * \copydoc close
  984. * \details
  985. * \par Handler signature
  986. * The handler signature for this operation is `void(boost::mysql::error_code)`.
  987. */
  988. template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code)) CompletionToken>
  989. auto async_close(CompletionToken&& token)
  990. BOOST_MYSQL_RETURN_TYPE(detail::async_close_connection_t<CompletionToken&&>)
  991. {
  992. return async_close(impl_.shared_diag(), std::forward<CompletionToken>(token));
  993. }
  994. /// \copydoc async_close
  995. template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code)) CompletionToken>
  996. auto async_close(diagnostics& diag, CompletionToken&& token)
  997. BOOST_MYSQL_RETURN_TYPE(detail::async_close_connection_t<CompletionToken&&>)
  998. {
  999. return this->impl_.async_run(
  1000. this->impl_.make_params_close(diag),
  1001. std::forward<CompletionToken>(token)
  1002. );
  1003. }
  1004. };
  1005. } // namespace mysql
  1006. } // namespace boost
  1007. #ifdef BOOST_MYSQL_HEADER_ONLY
  1008. #include <boost/mysql/impl/any_connection.ipp>
  1009. #endif
  1010. #endif