any_execution_request.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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_DETAIL_ANY_EXECUTION_REQUEST_HPP
  8. #define BOOST_MYSQL_DETAIL_ANY_EXECUTION_REQUEST_HPP
  9. #include <boost/mysql/constant_string_view.hpp>
  10. #include <boost/mysql/string_view.hpp>
  11. #include <boost/core/span.hpp>
  12. #include <cstdint>
  13. #include <type_traits>
  14. #include <vector>
  15. namespace boost {
  16. namespace mysql {
  17. class field_view;
  18. class format_arg;
  19. namespace detail {
  20. struct any_execution_request
  21. {
  22. enum class type_t
  23. {
  24. query,
  25. query_with_params,
  26. stmt
  27. };
  28. union data_t
  29. {
  30. string_view query;
  31. struct query_with_params_t
  32. {
  33. constant_string_view query;
  34. span<const format_arg> args;
  35. } query_with_params;
  36. struct stmt_t
  37. {
  38. std::uint32_t stmt_id;
  39. std::uint16_t num_params;
  40. span<const field_view> params;
  41. } stmt;
  42. data_t(string_view q) noexcept : query(q) {}
  43. data_t(query_with_params_t v) noexcept : query_with_params(v) {}
  44. data_t(stmt_t v) noexcept : stmt(v) {}
  45. };
  46. type_t type;
  47. data_t data;
  48. any_execution_request(string_view q) noexcept : type(type_t::query), data(q) {}
  49. any_execution_request(data_t::query_with_params_t v) noexcept : type(type_t::query_with_params), data(v)
  50. {
  51. }
  52. any_execution_request(data_t::stmt_t v) noexcept : type(type_t::stmt), data(v) {}
  53. };
  54. struct no_execution_request_traits
  55. {
  56. };
  57. template <class T, class = void>
  58. struct execution_request_traits : no_execution_request_traits
  59. {
  60. };
  61. template <class T>
  62. struct execution_request_traits<T, typename std::enable_if<std::is_convertible<T, string_view>::value>::type>
  63. {
  64. static any_execution_request make_request(string_view input, std::vector<field_view>&) { return input; }
  65. };
  66. } // namespace detail
  67. } // namespace mysql
  68. } // namespace boost
  69. #endif