File indexing completed on 2025-01-18 09:42:42
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_MYSQL_IMPL_RESULTS_IMPL_IPP
0009 #define BOOST_MYSQL_IMPL_RESULTS_IMPL_IPP
0010
0011 #pragma once
0012
0013 #include <boost/mysql/detail/execution_processor/results_impl.hpp>
0014
0015 #include <boost/mysql/impl/internal/protocol/protocol.hpp>
0016
0017 boost::mysql::detail::per_resultset_data& boost::mysql::detail::resultset_container::emplace_back()
0018 {
0019 if (!first_has_data_)
0020 {
0021 first_ = per_resultset_data();
0022 first_has_data_ = true;
0023 return first_;
0024 }
0025 else
0026 {
0027 rest_.emplace_back();
0028 return rest_.back();
0029 }
0030 }
0031
0032 boost::mysql::row_view boost::mysql::detail::results_impl::get_out_params() const noexcept
0033 {
0034 BOOST_ASSERT(is_complete());
0035 for (std::size_t i = 0; i < per_result_.size(); ++i)
0036 {
0037 if (per_result_[i].is_out_params)
0038 {
0039 auto res = get_rows(i);
0040 return res.empty() ? row_view() : res[0];
0041 }
0042 }
0043 return row_view();
0044 }
0045
0046 void boost::mysql::detail::results_impl::reset_impl() noexcept
0047 {
0048 meta_.clear();
0049 per_result_.clear();
0050 info_.clear();
0051 rows_.clear();
0052 num_fields_at_batch_start_ = no_batch;
0053 }
0054
0055 void boost::mysql::detail::results_impl::on_num_meta_impl(std::size_t num_columns)
0056 {
0057 auto& resultset_data = add_resultset();
0058 meta_.reserve(meta_.size() + num_columns);
0059 resultset_data.num_columns = num_columns;
0060 }
0061
0062 boost::mysql::error_code boost::mysql::detail::results_impl::
0063 on_head_ok_packet_impl(const ok_view& pack, diagnostics&)
0064 {
0065 add_resultset();
0066 on_ok_packet_impl(pack);
0067 return error_code();
0068 }
0069
0070 boost::mysql::error_code boost::mysql::detail::results_impl::
0071 on_meta_impl(const coldef_view& coldef, bool, diagnostics&)
0072 {
0073 meta_.push_back(create_meta(coldef));
0074 return error_code();
0075 }
0076
0077 boost::mysql::error_code boost::mysql::detail::results_impl::
0078 on_row_impl(span<const std::uint8_t> msg, const output_ref&, std::vector<field_view>&)
0079 {
0080 BOOST_ASSERT(has_active_batch());
0081
0082
0083 std::size_t num_fields = current_resultset().num_columns;
0084 span<field_view> storage = rows_.add_fields(num_fields);
0085 ++current_resultset().num_rows;
0086
0087
0088 auto err = deserialize_row(encoding(), msg, current_resultset_meta(), storage);
0089 if (err)
0090 return err;
0091
0092 return error_code();
0093 }
0094
0095 boost::mysql::error_code boost::mysql::detail::results_impl::on_row_ok_packet_impl(const ok_view& pack)
0096 {
0097 on_ok_packet_impl(pack);
0098 return error_code();
0099 }
0100
0101 void boost::mysql::detail::results_impl::on_row_batch_start_impl()
0102 {
0103 BOOST_ASSERT(!has_active_batch());
0104 num_fields_at_batch_start_ = rows_.fields().size();
0105 }
0106
0107 void boost::mysql::detail::results_impl::on_row_batch_finish_impl() { finish_batch(); }
0108
0109 void boost::mysql::detail::results_impl::finish_batch()
0110 {
0111 if (has_active_batch())
0112 {
0113 rows_.copy_strings_as_offsets(
0114 num_fields_at_batch_start_,
0115 rows_.fields().size() - num_fields_at_batch_start_
0116 );
0117 num_fields_at_batch_start_ = no_batch;
0118 }
0119 }
0120
0121 boost::mysql::detail::per_resultset_data& boost::mysql::detail::results_impl::add_resultset()
0122 {
0123
0124 auto& resultset_data = per_result_.emplace_back();
0125 resultset_data.meta_offset = meta_.size();
0126 resultset_data.field_offset = rows_.fields().size();
0127 resultset_data.info_offset = info_.size();
0128 return resultset_data;
0129 }
0130
0131 void boost::mysql::detail::results_impl::on_ok_packet_impl(const ok_view& pack)
0132 {
0133 auto& resultset_data = current_resultset();
0134 resultset_data.affected_rows = pack.affected_rows;
0135 resultset_data.last_insert_id = pack.last_insert_id;
0136 resultset_data.warnings = pack.warnings;
0137 resultset_data.info_size = pack.info.size();
0138 resultset_data.has_ok_packet_data = true;
0139 resultset_data.is_out_params = pack.is_out_params();
0140 info_.insert(info_.end(), pack.info.begin(), pack.info.end());
0141 if (!pack.more_results())
0142 {
0143 finish_batch();
0144 rows_.offsets_to_string_views();
0145 }
0146 }
0147
0148 #endif