|
||||
File indexing completed on 2024-11-15 09:19:40
0001 // 0002 // Copyright (c) 2019-2023 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_RESULTSET_VIEW_HPP 0009 #define BOOST_MYSQL_RESULTSET_VIEW_HPP 0010 0011 #include <boost/mysql/metadata_collection_view.hpp> 0012 #include <boost/mysql/rows_view.hpp> 0013 0014 #include <boost/mysql/detail/access.hpp> 0015 #include <boost/mysql/detail/execution_processor/results_impl.hpp> 0016 0017 #include <boost/assert.hpp> 0018 0019 namespace boost { 0020 namespace mysql { 0021 0022 /** 0023 * \brief A non-owning reference to a resultset. 0024 * \details 0025 * A `resultset_view` points to memory owned by an external object, usually a \ref results. 0026 * The view and any other reference type obtained from it are valid as long as the 0027 * object they point to is alive. 0028 */ 0029 class resultset_view 0030 { 0031 public: 0032 /** 0033 * \brief Constructs a view with `this->has_value() == false`. 0034 * \par Exception safety 0035 * No-throw guarantee. 0036 */ 0037 resultset_view() = default; 0038 0039 /** 0040 * \brief Returns whether this is a null view or not. 0041 * \details 0042 * Only returns true for default-constructed views. 0043 * 0044 * \par Exception safety 0045 * No-throw guarantee. 0046 * 0047 * \par Complexity 0048 * Constant. 0049 */ 0050 bool has_value() const noexcept { return impl_ != nullptr; } 0051 0052 /** 0053 * \brief Returns the rows for this resultset. 0054 * \par Preconditions 0055 * `this->has_value() == true` 0056 * 0057 * \par Exception safety 0058 * No-throw guarantee. 0059 * 0060 * \par Object lifetimes 0061 * The returned reference and any other references obtained from it are valid as long as 0062 * the object that `*this` points to is alive. 0063 * 0064 * \par Complexity 0065 * Constant. 0066 */ 0067 rows_view rows() const noexcept 0068 { 0069 BOOST_ASSERT(has_value()); 0070 return impl_->get_rows(index_); 0071 } 0072 0073 /** 0074 * \brief Returns metadata for this resultset. 0075 * \par Preconditions 0076 * `this->has_value() == true` 0077 * 0078 * \par Exception safety 0079 * No-throw guarantee. 0080 * 0081 * \par Object lifetimes 0082 * The returned reference and any other references obtained from it are valid as long as 0083 * the object that `*this` points to is alive. 0084 * 0085 * \par Complexity 0086 * Constant. 0087 */ 0088 metadata_collection_view meta() const noexcept 0089 { 0090 BOOST_ASSERT(has_value()); 0091 return impl_->get_meta(index_); 0092 } 0093 0094 /** 0095 * \brief Returns the number of affected rows for this resultset. 0096 * \par Preconditions 0097 * `this->has_value() == true` 0098 * 0099 * \par Exception safety 0100 * No-throw guarantee. 0101 * 0102 * \par Complexity 0103 * Constant. 0104 */ 0105 std::uint64_t affected_rows() const noexcept 0106 { 0107 BOOST_ASSERT(has_value()); 0108 return impl_->get_affected_rows(index_); 0109 } 0110 0111 /** 0112 * \brief Returns the last insert ID for this resultset. 0113 * \par Preconditions 0114 * `this->has_value() == true` 0115 * 0116 * \par Exception safety 0117 * No-throw guarantee. 0118 * 0119 * \par Complexity 0120 * Constant. 0121 */ 0122 std::uint64_t last_insert_id() const noexcept 0123 { 0124 BOOST_ASSERT(has_value()); 0125 return impl_->get_last_insert_id(index_); 0126 } 0127 0128 /** 0129 * \brief Returns the number of warnings for this resultset. 0130 * \par Preconditions 0131 * `this->has_value() == true` 0132 * 0133 * \par Exception safety 0134 * No-throw guarantee. 0135 * 0136 * \par Complexity 0137 * Constant. 0138 */ 0139 unsigned warning_count() const noexcept 0140 { 0141 BOOST_ASSERT(has_value()); 0142 return impl_->get_warning_count(index_); 0143 } 0144 0145 /** 0146 * \brief Returns additional information for this resultset. 0147 * \details 0148 * The format of this information is documented by MySQL <a 0149 * href="https://dev.mysql.com/doc/c-api/8.0/en/mysql-info.html">here</a>. 0150 * \n 0151 * The returned string always uses ASCII encoding, regardless of the connection's character set. 0152 * 0153 * \par Preconditions 0154 * `this->has_value() == true` 0155 * 0156 * \par Exception safety 0157 * No-throw guarantee. 0158 * 0159 * \par Object lifetimes 0160 * The returned reference and any other references obtained from it are valid as long as 0161 * the object that `*this` points to is alive. 0162 * 0163 * \par Complexity 0164 * Constant. 0165 */ 0166 string_view info() const noexcept 0167 { 0168 BOOST_ASSERT(has_value()); 0169 return impl_->get_info(index_); 0170 } 0171 0172 /** 0173 * \brief Returns whether this resultset represents a procedure OUT params. 0174 * \par Preconditions 0175 * `this->has_value() == true` 0176 * 0177 * \par Exception safety 0178 * No-throw guarantee. 0179 * 0180 * \par Complexity 0181 * Constant. 0182 */ 0183 bool is_out_params() const noexcept 0184 { 0185 BOOST_ASSERT(has_value()); 0186 return impl_->get_is_out_params(index_); 0187 } 0188 0189 #ifndef BOOST_MYSQL_DOXYGEN 0190 const resultset_view* operator->() const noexcept { return this; } 0191 #endif 0192 0193 private: 0194 const detail::results_impl* impl_{}; 0195 std::size_t index_{}; 0196 0197 resultset_view(const detail::results_impl& impl, std::size_t index) noexcept : impl_(&impl), index_(index) 0198 { 0199 } 0200 0201 #ifndef BOOST_MYSQL_DOXYGEN 0202 friend struct detail::access; 0203 #endif 0204 }; 0205 0206 } // namespace mysql 0207 } // namespace boost 0208 0209 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |