static_results_impl.ipp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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_RESULTS_IMPL_IPP
  8. #define BOOST_MYSQL_IMPL_STATIC_RESULTS_IMPL_IPP
  9. #pragma once
  10. #include <boost/mysql/detail/config.hpp>
  11. #include <boost/mysql/detail/execution_processor/static_results_impl.hpp>
  12. #include <boost/mysql/detail/row_impl.hpp>
  13. #include <boost/mysql/impl/internal/protocol/protocol.hpp>
  14. #ifdef BOOST_MYSQL_CXX14
  15. void boost::mysql::detail::static_results_erased_impl::reset_impl() noexcept
  16. {
  17. ext_.reset_fn()(ext_.rows());
  18. info_.clear();
  19. meta_.clear();
  20. resultset_index_ = 0;
  21. }
  22. boost::mysql::error_code boost::mysql::detail::static_results_erased_impl::on_head_ok_packet_impl(
  23. const ok_view& pack,
  24. diagnostics& diag
  25. )
  26. {
  27. add_resultset();
  28. auto err = on_ok_packet_impl(pack);
  29. if (err)
  30. return err;
  31. return meta_check(diag);
  32. }
  33. void boost::mysql::detail::static_results_erased_impl::on_num_meta_impl(std::size_t num_columns)
  34. {
  35. auto& resultset_data = add_resultset();
  36. meta_.reserve(meta_.size() + num_columns);
  37. resultset_data.meta_size = num_columns;
  38. }
  39. boost::mysql::error_code boost::mysql::detail::static_results_erased_impl::on_meta_impl(
  40. const coldef_view& coldef,
  41. bool is_last,
  42. diagnostics& diag
  43. )
  44. {
  45. std::size_t meta_index = meta_.size() - current_resultset().meta_offset;
  46. // Store the new object
  47. meta_.push_back(create_meta(coldef));
  48. // Fill the pos map entry for this field, if any
  49. pos_map_add_field(current_pos_map(), current_name_table(), meta_index, coldef.name);
  50. return is_last ? meta_check(diag) : error_code();
  51. }
  52. boost::mysql::error_code boost::mysql::detail::static_results_erased_impl::on_row_impl(
  53. span<const std::uint8_t> msg,
  54. const output_ref&,
  55. std::vector<field_view>& fields
  56. )
  57. {
  58. auto meta = current_resultset_meta();
  59. // Allocate temporary storage
  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 against the appropriate tuple element
  67. return ext_.parse_fn(resultset_index_ - 1)(current_pos_map(), storage, ext_.rows());
  68. }
  69. boost::mysql::error_code boost::mysql::detail::static_results_erased_impl::on_row_ok_packet_impl(
  70. const ok_view& pack
  71. )
  72. {
  73. return on_ok_packet_impl(pack);
  74. }
  75. boost::mysql::detail::static_per_resultset_data& boost::mysql::detail::static_results_erased_impl::
  76. add_resultset()
  77. {
  78. ++resultset_index_;
  79. auto& resultset_data = current_resultset();
  80. resultset_data = static_per_resultset_data();
  81. resultset_data.meta_offset = meta_.size();
  82. resultset_data.info_offset = info_.size();
  83. pos_map_reset(current_pos_map());
  84. return resultset_data;
  85. }
  86. boost::mysql::error_code boost::mysql::detail::static_results_erased_impl::on_ok_packet_impl(
  87. const ok_view& pack
  88. )
  89. {
  90. auto& resultset_data = current_resultset();
  91. resultset_data.affected_rows = pack.affected_rows;
  92. resultset_data.last_insert_id = pack.last_insert_id;
  93. resultset_data.warnings = pack.warnings;
  94. resultset_data.info_size = pack.info.size();
  95. resultset_data.has_ok_packet_data = true;
  96. resultset_data.is_out_params = pack.is_out_params();
  97. info_.insert(info_.end(), pack.info.begin(), pack.info.end());
  98. bool should_be_last = resultset_index_ == ext_.num_resultsets();
  99. bool is_last = !pack.more_results();
  100. return should_be_last == is_last ? error_code() : client_errc::num_resultsets_mismatch;
  101. }
  102. #endif
  103. #endif