File indexing completed on 2025-12-16 09:58:25
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_MYSQL_IMPL_STATEMENT_HPP
0009 #define BOOST_MYSQL_IMPL_STATEMENT_HPP
0010
0011 #pragma once
0012
0013 #include <boost/mysql/field_view.hpp>
0014 #include <boost/mysql/statement.hpp>
0015
0016 #include <boost/mysql/detail/access.hpp>
0017 #include <boost/mysql/detail/any_execution_request.hpp>
0018 #include <boost/mysql/detail/writable_field_traits.hpp>
0019
0020 #include <boost/assert.hpp>
0021 #include <boost/core/ignore_unused.hpp>
0022
0023 #include <tuple>
0024 #include <vector>
0025
0026 template <BOOST_MYSQL_WRITABLE_FIELD_TUPLE WritableFieldTuple>
0027 class boost::mysql::bound_statement_tuple
0028 {
0029 friend class statement;
0030 friend struct detail::access;
0031
0032 struct impl
0033 {
0034 statement stmt;
0035 WritableFieldTuple params;
0036 } impl_;
0037
0038 template <typename TupleType>
0039 bound_statement_tuple(const statement& stmt, TupleType&& t) : impl_{stmt, std::forward<TupleType>(t)}
0040 {
0041 }
0042 };
0043
0044 template <BOOST_MYSQL_FIELD_VIEW_FORWARD_ITERATOR FieldViewFwdIterator>
0045 class boost::mysql::bound_statement_iterator_range
0046 {
0047 friend class statement;
0048 friend struct detail::access;
0049
0050 struct impl
0051 {
0052 statement stmt;
0053 FieldViewFwdIterator first;
0054 FieldViewFwdIterator last;
0055 } impl_;
0056
0057 bound_statement_iterator_range(
0058 const statement& stmt,
0059 FieldViewFwdIterator first,
0060 FieldViewFwdIterator last
0061 )
0062 : impl_{stmt, first, last}
0063 {
0064 }
0065 };
0066
0067 template <BOOST_MYSQL_WRITABLE_FIELD_TUPLE WritableFieldTuple, typename EnableIf>
0068 boost::mysql::bound_statement_tuple<typename std::decay<WritableFieldTuple>::type> boost::mysql::statement::
0069 bind(WritableFieldTuple&& args) const
0070
0071 {
0072 BOOST_ASSERT(valid());
0073 return bound_statement_tuple<typename std::decay<WritableFieldTuple>::type>(
0074 *this,
0075 std::forward<WritableFieldTuple>(args)
0076 );
0077 }
0078
0079 template <BOOST_MYSQL_FIELD_VIEW_FORWARD_ITERATOR FieldViewFwdIterator, typename EnableIf>
0080 boost::mysql::bound_statement_iterator_range<FieldViewFwdIterator> boost::mysql::statement::bind(
0081 FieldViewFwdIterator first,
0082 FieldViewFwdIterator last
0083 ) const
0084 {
0085 BOOST_ASSERT(valid());
0086 return bound_statement_iterator_range<FieldViewFwdIterator>(*this, first, last);
0087 }
0088
0089
0090 namespace boost {
0091 namespace mysql {
0092 namespace detail {
0093
0094
0095 template <std::size_t N>
0096 struct stmt_tuple_request_proxy
0097 {
0098 statement stmt;
0099 std::array<field_view, N> params;
0100
0101 operator any_execution_request() const
0102 {
0103 return any_execution_request({stmt.id(), static_cast<std::uint16_t>(stmt.num_params()), params});
0104 }
0105 };
0106
0107 template <class... T>
0108 struct execution_request_traits<bound_statement_tuple<std::tuple<T...>>>
0109 {
0110 template <std::size_t... I>
0111 static std::array<field_view, sizeof...(T)> tuple_to_array(const std::tuple<T...>& t, mp11::index_sequence<I...>)
0112 {
0113 boost::ignore_unused(t);
0114 return {{to_field(std::get<I>(t))...}};
0115 }
0116
0117 static stmt_tuple_request_proxy<sizeof...(T)> make_request(const bound_statement_tuple<std::tuple<T...>>& input, std::vector<field_view>&)
0118 {
0119 auto& impl = access::get_impl(input);
0120 return {impl.stmt, tuple_to_array(impl.params, mp11::make_index_sequence<sizeof...(T)>())};
0121 }
0122 };
0123
0124
0125 template <class FieldViewFwdIterator>
0126 struct execution_request_traits<bound_statement_iterator_range<FieldViewFwdIterator>>
0127 {
0128 static any_execution_request make_request(
0129 const bound_statement_iterator_range<FieldViewFwdIterator>& input,
0130 std::vector<field_view>& shared_fields
0131 )
0132 {
0133 auto& impl = access::get_impl(input);
0134 shared_fields.assign(impl.first, impl.last);
0135 return any_execution_request(
0136 {impl.stmt.id(), static_cast<std::uint16_t>(impl.stmt.num_params()), shared_fields}
0137 );
0138 }
0139 };
0140
0141 }
0142 }
0143 }
0144
0145 #endif