static_execution_state_impl.ipp 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_IMPL_STATIC_EXECUTION_STATE_IMPL_IPP
  8. #define BOOST_MYSQL_IMPL_STATIC_EXECUTION_STATE_IMPL_IPP
  9. #pragma once
  10. #include <boost/mysql/detail/execution_processor/static_execution_state_impl.hpp>
  11. #include <boost/mysql/detail/row_impl.hpp>
  12. #include <boost/mysql/impl/internal/protocol/deserialization.hpp>
  13. #ifdef BOOST_MYSQL_CXX14
  14. void boost::mysql::detail::static_execution_state_erased_impl::reset_impl() noexcept
  15. {
  16. resultset_index_ = 0;
  17. ok_data_ = ok_packet_data();
  18. info_.clear();
  19. meta_.clear();
  20. }
  21. boost::mysql::error_code boost::mysql::detail::static_execution_state_erased_impl::on_head_ok_packet_impl(
  22. const ok_view& pack,
  23. diagnostics& diag
  24. )
  25. {
  26. on_new_resultset();
  27. auto err = on_ok_packet_impl(pack);
  28. if (err)
  29. return err;
  30. return meta_check(diag);
  31. }
  32. void boost::mysql::detail::static_execution_state_erased_impl::on_num_meta_impl(std::size_t num_columns)
  33. {
  34. on_new_resultset();
  35. meta_.reserve(num_columns);
  36. }
  37. boost::mysql::error_code boost::mysql::detail::static_execution_state_erased_impl::on_meta_impl(
  38. const coldef_view& coldef,
  39. bool is_last,
  40. diagnostics& diag
  41. )
  42. {
  43. std::size_t meta_index = meta_.size();
  44. // Store the object
  45. meta_.push_back(create_meta(coldef));
  46. // Record its position
  47. pos_map_add_field(current_pos_map(), current_name_table(), meta_index, coldef.name);
  48. return is_last ? meta_check(diag) : error_code();
  49. }
  50. boost::mysql::error_code boost::mysql::detail::static_execution_state_erased_impl::on_row_impl(
  51. span<const std::uint8_t> msg,
  52. const output_ref& ref,
  53. std::vector<field_view>& fields
  54. )
  55. {
  56. // check output
  57. if (ref.type_index() != ext_.type_index(resultset_index_ - 1))
  58. return client_errc::row_type_mismatch;
  59. // Allocate temporary space
  60. fields.clear();
  61. span<field_view> storage = add_fields(fields, meta_.size());
  62. // deserialize the row
  63. auto err = deserialize_row(encoding(), msg, meta_, storage);
  64. if (err)
  65. return err;
  66. // parse it into the output ref
  67. err = ext_.parse_fn(resultset_index_ - 1)(current_pos_map(), storage, ref);
  68. if (err)
  69. return err;
  70. return error_code();
  71. }
  72. boost::mysql::error_code boost::mysql::detail::static_execution_state_erased_impl::on_row_ok_packet_impl(
  73. const ok_view& pack
  74. )
  75. {
  76. return on_ok_packet_impl(pack);
  77. }
  78. void boost::mysql::detail::static_execution_state_erased_impl::on_new_resultset() noexcept
  79. {
  80. ++resultset_index_;
  81. ok_data_ = ok_packet_data{};
  82. info_.clear();
  83. meta_.clear();
  84. pos_map_reset(current_pos_map());
  85. }
  86. boost::mysql::error_code boost::mysql::detail::static_execution_state_erased_impl::on_ok_packet_impl(
  87. const ok_view& pack
  88. )
  89. {
  90. ok_data_.has_value = true;
  91. ok_data_.affected_rows = pack.affected_rows;
  92. ok_data_.last_insert_id = pack.last_insert_id;
  93. ok_data_.warnings = pack.warnings;
  94. ok_data_.is_out_params = pack.is_out_params();
  95. info_.assign(pack.info.begin(), pack.info.end());
  96. bool should_be_last = resultset_index_ == ext_.num_resultsets();
  97. bool is_last = !pack.more_results();
  98. return should_be_last == is_last ? error_code() : client_errc::num_resultsets_mismatch;
  99. }
  100. #endif
  101. #endif