Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 08:33:52

0001 //
0002 // Copyright (c) 2019-2024 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 
0008 #ifndef BOOST_MYSQL_IMPL_INTERNAL_SANSIO_READ_RESULTSET_HEAD_HPP
0009 #define BOOST_MYSQL_IMPL_INTERNAL_SANSIO_READ_RESULTSET_HEAD_HPP
0010 
0011 #include <boost/mysql/diagnostics.hpp>
0012 #include <boost/mysql/error_code.hpp>
0013 
0014 #include <boost/mysql/detail/algo_params.hpp>
0015 #include <boost/mysql/detail/execution_processor/execution_processor.hpp>
0016 
0017 #include <boost/mysql/impl/internal/coroutine.hpp>
0018 #include <boost/mysql/impl/internal/sansio/connection_state_data.hpp>
0019 
0020 namespace boost {
0021 namespace mysql {
0022 namespace detail {
0023 
0024 inline error_code process_execution_response(
0025     connection_state_data& st,
0026     execution_processor& proc,
0027     span<const std::uint8_t> msg,
0028     diagnostics& diag
0029 )
0030 {
0031     auto response = deserialize_execute_response(msg, st.flavor, diag);
0032     error_code err;
0033     switch (response.type)
0034     {
0035     case execute_response::type_t::error: err = response.data.err; break;
0036     case execute_response::type_t::ok_packet:
0037         st.backslash_escapes = response.data.ok_pack.backslash_escapes();
0038         err = proc.on_head_ok_packet(response.data.ok_pack, diag);
0039         break;
0040     case execute_response::type_t::num_fields: proc.on_num_meta(response.data.num_fields); break;
0041     }
0042     return err;
0043 }
0044 
0045 inline error_code process_field_definition(
0046     execution_processor& proc,
0047     span<const std::uint8_t> msg,
0048     diagnostics& diag
0049 )
0050 {
0051     // Deserialize the message
0052     coldef_view coldef{};
0053     auto err = deserialize_column_definition(msg, coldef);
0054     if (err)
0055         return err;
0056 
0057     // Notify the processor
0058     return proc.on_meta(coldef, diag);
0059 }
0060 
0061 class read_resultset_head_algo
0062 {
0063     diagnostics* diag_;
0064     execution_processor* proc_;
0065 
0066     struct state_t
0067     {
0068         int resume_point{0};
0069     } state_;
0070 
0071 public:
0072     read_resultset_head_algo(read_resultset_head_algo_params params) noexcept
0073         : diag_(params.diag), proc_(params.proc)
0074     {
0075     }
0076 
0077     void reset() { state_ = state_t{}; }
0078 
0079     diagnostics& diag() { return *diag_; }
0080     execution_processor& processor() { return *proc_; }
0081 
0082     next_action resume(connection_state_data& st, error_code ec)
0083     {
0084         if (ec)
0085             return ec;
0086 
0087         switch (state_.resume_point)
0088         {
0089         case 0:
0090 
0091             // Clear diagnostics
0092             diag_->clear();
0093 
0094             // If we're not reading head, return
0095             if (!proc_->is_reading_head())
0096                 return next_action();
0097 
0098             // Read the response
0099             BOOST_MYSQL_YIELD(state_.resume_point, 1, st.read(proc_->sequence_number()))
0100 
0101             // Response may be: ok_packet, err_packet, local infile request
0102             // (not implemented), or response with fields
0103             ec = process_execution_response(st, *proc_, st.reader.message(), *diag_);
0104             if (ec)
0105                 return ec;
0106 
0107             // Read all of the field definitions
0108             while (proc_->is_reading_meta())
0109             {
0110                 // Read a message
0111                 BOOST_MYSQL_YIELD(state_.resume_point, 2, st.read(proc_->sequence_number()))
0112 
0113                 // Process the metadata packet
0114                 ec = process_field_definition(*proc_, st.reader.message(), *diag_);
0115                 if (ec)
0116                     return ec;
0117             }
0118 
0119             // No EOF packet is expected here, as we require deprecate EOF capabilities
0120         }
0121 
0122         return next_action();
0123     }
0124 };
0125 
0126 }  // namespace detail
0127 }  // namespace mysql
0128 }  // namespace boost
0129 
0130 #endif