File indexing completed on 2025-04-09 08:28:05
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_MYSQL_IMPL_PIPELINE_IPP
0009 #define BOOST_MYSQL_IMPL_PIPELINE_IPP
0010
0011 #pragma once
0012
0013 #include <boost/mysql/error_code.hpp>
0014 #include <boost/mysql/field_view.hpp>
0015 #include <boost/mysql/pipeline.hpp>
0016
0017 #include <boost/mysql/detail/access.hpp>
0018 #include <boost/mysql/detail/pipeline.hpp>
0019 #include <boost/mysql/detail/resultset_encoding.hpp>
0020
0021 #include <boost/mysql/impl/internal/protocol/serialization.hpp>
0022 #include <boost/mysql/impl/internal/sansio/set_character_set.hpp>
0023
0024 #include <boost/core/span.hpp>
0025 #include <boost/throw_exception.hpp>
0026
0027 #include <stdexcept>
0028
0029 boost::mysql::pipeline_request& boost::mysql::pipeline_request::add_execute(string_view query)
0030 {
0031 impl_.stages_.reserve(impl_.stages_.size() + 1);
0032 impl_.stages_.push_back({
0033 detail::pipeline_stage_kind::execute,
0034 detail::serialize_top_level(detail::query_command{query}, impl_.buffer_),
0035 detail::resultset_encoding::text,
0036 });
0037 return *this;
0038 }
0039
0040 boost::mysql::pipeline_request& boost::mysql::pipeline_request::add_execute_range(
0041 statement stmt,
0042 span<const field_view> params
0043 )
0044 {
0045 if (params.size() != stmt.num_params())
0046 {
0047 BOOST_THROW_EXCEPTION(
0048 std::invalid_argument("Wrong number of actual parameters supplied to a prepared statement")
0049 );
0050 }
0051 impl_.stages_.reserve(impl_.stages_.size() + 1);
0052 impl_.stages_.push_back({
0053 detail::pipeline_stage_kind::execute,
0054 detail::serialize_top_level(detail::execute_stmt_command{stmt.id(), params}, impl_.buffer_),
0055 detail::resultset_encoding::binary,
0056 });
0057 return *this;
0058 }
0059
0060 boost::mysql::pipeline_request& boost::mysql::pipeline_request::add_prepare_statement(string_view stmt_sql)
0061 {
0062 impl_.stages_.reserve(impl_.stages_.size() + 1);
0063 impl_.stages_.push_back({
0064 detail::pipeline_stage_kind::prepare_statement,
0065 detail::serialize_top_level(detail::prepare_stmt_command{stmt_sql}, impl_.buffer_),
0066 {},
0067 });
0068 return *this;
0069 }
0070
0071 boost::mysql::pipeline_request& boost::mysql::pipeline_request::add_close_statement(statement stmt)
0072 {
0073 impl_.stages_.reserve(impl_.stages_.size() + 1);
0074 impl_.stages_.push_back({
0075 detail::pipeline_stage_kind::close_statement,
0076 detail::serialize_top_level(detail::close_stmt_command{stmt.id()}, impl_.buffer_),
0077 {},
0078 });
0079 return *this;
0080 }
0081
0082 boost::mysql::pipeline_request& boost::mysql::pipeline_request::add_reset_connection()
0083 {
0084 impl_.stages_.reserve(impl_.stages_.size() + 1);
0085 impl_.stages_.push_back({
0086 detail::pipeline_stage_kind::reset_connection,
0087 detail::serialize_top_level(detail::reset_connection_command{}, impl_.buffer_),
0088 {},
0089 });
0090 return *this;
0091 }
0092
0093 boost::mysql::pipeline_request& boost::mysql::pipeline_request::add_set_character_set(character_set charset)
0094 {
0095 auto q = detail::compose_set_names(charset);
0096 if (q.has_error())
0097 {
0098 BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid character set name"));
0099 }
0100 impl_.stages_.reserve(impl_.stages_.size() + 1);
0101 impl_.stages_.push_back({
0102 detail::pipeline_stage_kind::set_character_set,
0103 detail::serialize_top_level(detail::query_command{*q}, impl_.buffer_),
0104 charset,
0105 });
0106 return *this;
0107 }
0108
0109 void boost::mysql::stage_response::check_has_results() const
0110 {
0111 if (!has_results())
0112 {
0113 BOOST_THROW_EXCEPTION(
0114 std::invalid_argument("stage_response::as_results: object doesn't contain results")
0115 );
0116 }
0117 }
0118
0119 boost::mysql::statement boost::mysql::stage_response::as_statement() const
0120 {
0121 if (!has_statement())
0122 {
0123 BOOST_THROW_EXCEPTION(
0124 std::invalid_argument("stage_response::as_statement: object doesn't contain a statement")
0125 );
0126 }
0127 return variant2::unsafe_get<1>(impl_.value);
0128 }
0129
0130 #endif