41class FieldView
final {
43 using size_type = std::size_t;
45 FieldView(
const detail::ResultWrapper& res, size_type row_index, size_type field_index)
46 : res_{res}, row_index_{row_index}, field_index_{field_index} {}
49 size_type To(T&& val)
const {
50 using ValueType =
typename std::decay<T>::type;
51 auto fb = GetBuffer();
52 return ReadNullable(fb, std::forward<T>(val), io::
traits::
IsNullable<ValueType>{});
57 std::string_view Name()
const;
58 Oid GetTypeOid()
const;
59 const io::TypeBufferCategory& GetTypeBufferCategories()
const;
62 size_type ReadNullable(
const io::
FieldBuffer& fb, T&& val, std::true_type)
const {
63 using ValueType =
typename std::decay<T>::type;
66 NullSetter::SetNull(val);
68 Read(fb, std::forward<T>(val));
74 size_type ReadNullable(
const io::
FieldBuffer& buffer, T&& val, std::false_type)
const {
78 Read(buffer, std::forward<T>(val));
84 void Read(
const io::
FieldBuffer& buffer, T&& val)
const {
85 using ValueType =
typename std::decay<T>::type;
86 io::
traits::CheckParser<ValueType>();
88 io::ReadBuffer(buffer, std::forward<T>(val), GetTypeBufferCategories());
91 ex.AddMsgPrefix(fmt::format(
92 "Error while reading field #{0} '{1}' which database type {2} as a C++ type '{3}'. Refer to "
93 "the 'Supported data types' in the documentation to make sure that the database type is actually "
94 "representable as a C++ type '{3}'. Error details: ",
97 impl::OidPrettyPrint(GetTypeOid()),
103 ex.AddMsgSuffix(fmt::format(
" (ResultSet error while reading field #{} name `{}`)", field_index_, Name()));
108 const detail::ResultWrapper& res_;
109 const size_type row_index_;
110 const size_type field_index_;
116 using size_type = std::size_t;
118 size_type RowIndex()
const {
return row_index_; }
119 size_type FieldIndex()
const {
return field_index_; }
127 Oid GetTypeOid()
const;
134 size_type Length()
const;
139 template <
typename T>
140 size_type
To(T&& val)
const {
141 return FieldView{*res_, row_index_, field_index_}.To(std::forward<T>(val));
140 size_type
To(T&& val)
const {
…}
146 template <
typename T>
147 void Coalesce(T& val,
const T& default_val)
const {
157 template <
typename T>
158 typename std::decay<T>::
type As()
const {
166 template <
typename T>
168 if (IsNull())
return default_val;
172 const io::TypeBufferCategory& GetTypeBufferCategories()
const;
179 Field(detail::ResultWrapperPtr res, size_type row, size_type col)
180 : res_{std::move(res)}, row_index_{row}, field_index_{col} {}
184 bool IsValid()
const;
185 int Compare(
const Field& rhs)
const;
186 std::ptrdiff_t Distance(
const Field& rhs)
const;
187 Field& Advance(std::ptrdiff_t);
191 detail::ResultWrapperPtr res_;
192 size_type row_index_{0};
193 size_type field_index_{0};
200 ConstFieldIterator() =
default;
205 ConstFieldIterator(detail::ResultWrapperPtr res, size_type row, size_type col)
206 : ConstDataIterator(std::move(res), row, col) {}
213 ReverseConstFieldIterator() =
default;
218 ReverseConstFieldIterator(detail::ResultWrapperPtr res, size_type row, size_type col)
219 : ConstDataIterator(std::move(res), row, col) {}