execution_state_impl.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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_DETAIL_EXECUTION_PROCESSOR_EXECUTION_STATE_IMPL_HPP
  8. #define BOOST_MYSQL_DETAIL_EXECUTION_PROCESSOR_EXECUTION_STATE_IMPL_HPP
  9. #include <boost/mysql/diagnostics.hpp>
  10. #include <boost/mysql/error_code.hpp>
  11. #include <boost/mysql/field_view.hpp>
  12. #include <boost/mysql/metadata.hpp>
  13. #include <boost/mysql/metadata_collection_view.hpp>
  14. #include <boost/mysql/string_view.hpp>
  15. #include <boost/mysql/detail/config.hpp>
  16. #include <boost/mysql/detail/execution_processor/execution_processor.hpp>
  17. #include <boost/assert.hpp>
  18. #include <vector>
  19. namespace boost {
  20. namespace mysql {
  21. namespace detail {
  22. class execution_state_impl final : public execution_processor
  23. {
  24. struct ok_data
  25. {
  26. bool has_value{false}; // The OK packet information is default constructed, or actual data?
  27. std::uint64_t affected_rows{}; // OK packet data
  28. std::uint64_t last_insert_id{}; // OK packet data
  29. std::uint16_t warnings{}; // OK packet data
  30. bool is_out_params{false}; // Does this resultset contain OUT param information?
  31. };
  32. std::vector<metadata> meta_;
  33. ok_data eof_data_;
  34. std::vector<char> info_;
  35. void on_new_resultset() noexcept
  36. {
  37. meta_.clear();
  38. eof_data_ = ok_data{};
  39. info_.clear();
  40. }
  41. BOOST_MYSQL_DECL
  42. void on_ok_packet_impl(const ok_view& pack);
  43. BOOST_MYSQL_DECL
  44. void reset_impl() noexcept override final;
  45. BOOST_MYSQL_DECL
  46. error_code on_head_ok_packet_impl(const ok_view& pack, diagnostics&) override final;
  47. BOOST_MYSQL_DECL
  48. void on_num_meta_impl(std::size_t num_columns) override final;
  49. BOOST_MYSQL_DECL
  50. error_code on_meta_impl(const coldef_view&, bool, diagnostics&) override final;
  51. BOOST_MYSQL_DECL
  52. error_code on_row_impl(span<const std::uint8_t> msg, const output_ref&, std::vector<field_view>& fields)
  53. override final;
  54. BOOST_MYSQL_DECL
  55. error_code on_row_ok_packet_impl(const ok_view& pack) override final;
  56. void on_row_batch_start_impl() noexcept override final {}
  57. void on_row_batch_finish_impl() noexcept override final {}
  58. public:
  59. execution_state_impl() = default;
  60. metadata_collection_view meta() const noexcept { return meta_; }
  61. std::uint64_t get_affected_rows() const noexcept
  62. {
  63. BOOST_ASSERT(eof_data_.has_value);
  64. return eof_data_.affected_rows;
  65. }
  66. std::uint64_t get_last_insert_id() const noexcept
  67. {
  68. BOOST_ASSERT(eof_data_.has_value);
  69. return eof_data_.last_insert_id;
  70. }
  71. unsigned get_warning_count() const noexcept
  72. {
  73. BOOST_ASSERT(eof_data_.has_value);
  74. return eof_data_.warnings;
  75. }
  76. string_view get_info() const noexcept
  77. {
  78. BOOST_ASSERT(eof_data_.has_value);
  79. return string_view(info_.data(), info_.size());
  80. }
  81. bool get_is_out_params() const noexcept
  82. {
  83. BOOST_ASSERT(eof_data_.has_value);
  84. return eof_data_.is_out_params;
  85. }
  86. execution_state_impl& get_interface() noexcept { return *this; }
  87. };
  88. } // namespace detail
  89. } // namespace mysql
  90. } // namespace boost
  91. #ifdef BOOST_MYSQL_HEADER_ONLY
  92. #include <boost/mysql/impl/execution_state_impl.ipp>
  93. #endif
  94. #endif