client_errc.hpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. //
  2. // Copyright (c) 2019-2025 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_CLIENT_ERRC_HPP
  8. #define BOOST_MYSQL_CLIENT_ERRC_HPP
  9. #include <boost/mysql/error_code.hpp>
  10. #include <boost/mysql/detail/config.hpp>
  11. #include <boost/system/error_category.hpp>
  12. namespace boost {
  13. namespace mysql {
  14. /**
  15. * \brief MySQL client-defined error codes.
  16. * \details These errors are produced by the client itself, rather than the server.
  17. */
  18. enum class client_errc : int
  19. {
  20. /**
  21. * \brief An incomplete message was received from the server (indicates a deserialization error or
  22. * packet mismatch).
  23. */
  24. incomplete_message = 1,
  25. /**
  26. * \brief An unexpected value was found in a server-received message (indicates a deserialization
  27. * error or packet mismatch).
  28. */
  29. protocol_value_error,
  30. /// The server does not support the minimum required capabilities to establish the connection.
  31. server_unsupported,
  32. /**
  33. * \brief Unexpected extra bytes at the end of a message were received (indicates a deserialization
  34. * error or packet mismatch).
  35. */
  36. extra_bytes,
  37. /// Mismatched sequence numbers (usually caused by a packet mismatch).
  38. sequence_number_mismatch,
  39. /// The user employs an authentication plugin not known to this library.
  40. unknown_auth_plugin,
  41. /**
  42. * \brief (Legacy) The authentication plugin requires the connection to use SSL.
  43. * This code is no longer used, since all supported plugins support plaintext connections.
  44. */
  45. auth_plugin_requires_ssl,
  46. /**
  47. * \brief The number of parameters passed to the prepared statement does not match the number of
  48. * actual parameters.
  49. */
  50. wrong_num_params,
  51. /// The connection mandates SSL, but the server doesn't accept SSL connections.
  52. server_doesnt_support_ssl,
  53. /**
  54. * \brief
  55. * The static interface detected a mismatch between your C++ type definitions and what the server
  56. * returned in the query.
  57. */
  58. metadata_check_failed,
  59. /**
  60. * \brief The static interface detected a mismatch between the number of row types passed to
  61. * \ref static_results or \ref static_execution_state and the number of resultsets returned by your query.
  62. */
  63. num_resultsets_mismatch,
  64. /// The `StaticRow` type passed to read_some_rows does not correspond to the resultset type being read.
  65. row_type_mismatch,
  66. /// The static interface encountered an error when parsing a field into a C++ data structure.
  67. static_row_parsing_error,
  68. /**
  69. * \brief Getting a connection from a connection_pool was cancelled before
  70. * the pool was run. Ensure that you're calling connection_pool::async_run.
  71. */
  72. pool_not_running,
  73. /**
  74. * \brief Getting a connection from a connection_pool failed because the
  75. * pool was cancelled.
  76. */
  77. pool_cancelled,
  78. /**
  79. * \brief Getting a connection from a connection_pool was cancelled before
  80. * a connection was available.
  81. */
  82. no_connection_available,
  83. /// An invalid byte sequence was found while trying to decode a string.
  84. invalid_encoding,
  85. /// A formatting operation could not format one of its arguments.
  86. unformattable_value,
  87. /// A format string containing invalid syntax was provided to a SQL formatting function.
  88. format_string_invalid_syntax,
  89. /**
  90. * \brief A format string with an invalid byte sequence was provided to a SQL formatting
  91. * function.
  92. */
  93. format_string_invalid_encoding,
  94. /// A format string mixes manual (e.g. {0}) and automatic (e.g. {}) indexing.
  95. format_string_manual_auto_mix,
  96. /// The supplied format specifier (e.g. {:i}) is not supported by the type being formatted.
  97. format_string_invalid_specifier,
  98. /**
  99. * \brief A format argument referenced by a format string was not found. Check the number
  100. * of format arguments passed and their names.
  101. */
  102. format_arg_not_found,
  103. /**
  104. * \brief The character set used by the connection is not known by the client. Use
  105. * \ref any_connection::set_character_set or \ref any_connection::async_set_character_set
  106. * before invoking operations that require a known charset.
  107. */
  108. unknown_character_set,
  109. /**
  110. * \brief An operation attempted to read or write a packet larger than the maximum buffer
  111. * size. Try increasing \ref any_connection_params::max_buffer_size.
  112. */
  113. max_buffer_size_exceeded,
  114. /**
  115. * \brief Another operation is currently in progress for this connection. Make sure
  116. * that a single connection does not run two asynchronous operations in parallel.
  117. */
  118. operation_in_progress,
  119. /**
  120. * \brief The requested operation requires an established session.
  121. * Call `async_connect` before invoking other operations.
  122. */
  123. not_connected,
  124. /**
  125. * \brief The connection is currently engaged in a multi-function operation.
  126. * Finish the current operation by calling `async_read_some_rows` and `async_read_resultset_head`
  127. * before starting any other operation.
  128. */
  129. engaged_in_multi_function,
  130. /**
  131. * \brief The operation requires the connection to be engaged in a multi-function operation.
  132. * Use `async_start_execution` to start one.
  133. */
  134. not_engaged_in_multi_function,
  135. /**
  136. * \brief During handshake, the server sent a packet type that is not allowed in the current state
  137. * (protocol violation).
  138. */
  139. bad_handshake_packet_type,
  140. /// An OpenSSL function failed and did not provide any extra diagnostics.
  141. unknown_openssl_error,
  142. };
  143. BOOST_MYSQL_DECL
  144. const boost::system::error_category& get_client_category() noexcept;
  145. /// Creates an \ref error_code from a \ref client_errc.
  146. inline error_code make_error_code(client_errc error)
  147. {
  148. return error_code(static_cast<int>(error), get_client_category());
  149. }
  150. } // namespace mysql
  151. #ifndef BOOST_MYSQL_DOXYGEN
  152. namespace system {
  153. template <>
  154. struct is_error_code_enum<::boost::mysql::client_errc>
  155. {
  156. static constexpr bool value = true;
  157. };
  158. } // namespace system
  159. #endif
  160. } // namespace boost
  161. #ifdef BOOST_MYSQL_HEADER_ONLY
  162. #include <boost/mysql/impl/error_categories.ipp>
  163. #endif
  164. #endif