41class FieldView
final {
43 using size_type = std::size_t;
45 FieldView(
const detail::ResultWrapper& res, size_type row_index, size_type field_index)
47 row_index_{row_index},
48 field_index_{field_index}
52 size_type To(T&& val)
const {
53 using ValueType =
typename std::decay<T>::type;
54 auto fb = GetBuffer();
55 return ReadNullable(fb, std::forward<T>(val), io::
traits::
IsNullable<ValueType>{});
60 std::string_view Name()
const;
61 Oid GetTypeOid()
const;
62 const io::TypeBufferCategory& GetTypeBufferCategories()
const;
65 size_type ReadNullable(
const io::
FieldBuffer& fb, T&& val, std::true_type)
const {
66 using ValueType =
typename std::decay<T>::type;
69 NullSetter::SetNull(val);
71 Read(fb, std::forward<T>(val));
77 size_type ReadNullable(
const io::
FieldBuffer& buffer, T&& val, std::false_type)
const {
81 Read(buffer, std::forward<T>(val));
87 void Read(
const io::
FieldBuffer& buffer, T&& val)
const {
88 using ValueType =
typename std::decay<T>::type;
89 io::
traits::CheckParser<ValueType>();
91 io::ReadBuffer(buffer, std::forward<T>(val), GetTypeBufferCategories());
94 ex.AddMsgPrefix(fmt::format(
95 "Error while reading field #{0} '{1}' which database type {2} as a C++ type '{3}'. Refer to "
96 "the 'Supported data types' in the documentation to make sure that the database type is actually "
97 "representable as a C++ type '{3}'. Error details: ",
100 impl::OidPrettyPrint(GetTypeOid()),
106 ex.AddMsgSuffix(fmt::format(
" (ResultSet error while reading field #{} name `{}`)", field_index_, Name()));
111 const detail::ResultWrapper& res_;
112 const size_type row_index_;
113 const size_type field_index_;
119 using size_type = std::size_t;
121 size_type RowIndex()
const {
return row_index_; }
122 size_type FieldIndex()
const {
return field_index_; }
130 Oid GetTypeOid()
const;
137 size_type Length()
const;
142 template <
typename T>
143 size_type
To(T&& val)
const {
144 return FieldView{*res_, row_index_, field_index_}.To(std::forward<T>(val));
149 template <
typename T>
150 void Coalesce(T& val,
const T& default_val)
const {
161 template <
typename T>
162 typename std::decay<T>::
type As()
const {
170 template <
typename T>
178 const io::TypeBufferCategory& GetTypeBufferCategories()
const;
185 Field(detail::ResultWrapperPtr res, size_type row, size_type col)
186 : res_{std::move(res)},
193 bool IsValid()
const;
194 int Compare(
const Field& rhs)
const;
195 std::ptrdiff_t Distance(
const Field& rhs)
const;
196 Field& Advance(std::ptrdiff_t);
200 detail::ResultWrapperPtr res_;
201 size_type row_index_{0};
202 size_type field_index_{0};
209 ConstFieldIterator() =
default;
214 ConstFieldIterator(detail::ResultWrapperPtr res, size_type row, size_type col)
215 : ConstDataIterator(std::move(res), row, col)
223 ReverseConstFieldIterator() =
default;
228 ReverseConstFieldIterator(detail::ResultWrapperPtr res, size_type row, size_type col)
229 : ConstDataIterator(std::move(res), row, col)