16 #if !defined(PQXX_HEADER_PRE)
17 # error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
27 template<
typename... T>
class result_iter;
33 class row_ref_const_result_iterator;
72 m_result{&res}, m_index{index}
104 return rhs.m_result == m_result and rhs.m_index == m_index;
112 [[nodiscard]] const_iterator cbegin() const noexcept;
113 [[nodiscard]] const_iterator begin() const noexcept;
114 [[nodiscard]] const_iterator end() const noexcept;
115 [[nodiscard]] const_iterator cend() const noexcept;
121 [[nodiscard]] reference front() const noexcept;
122 [[nodiscard]] reference back() const noexcept;
131 return {home(), row_number(), i};
134 #if defined(PQXX_HAVE_MULTIDIM)
158 [[nodiscard]]
PQXX_PURE reference operator[](
zview col_name)
const;
163 if (m_result ==
nullptr)
164 throw usage_error{
"Indexing uninitialised row.", loc};
165 if (std::cmp_less(i, 0))
167 auto const sz{size()};
168 if (std::cmp_greater_equal(i, sz))
171 "Column index out of range: {} in a result of {} column(s).", i, sz),
173 return operator[](i);
185 if (m_result ==
nullptr)
186 throw usage_error{
"Indexing uninitialised row.", loc};
187 return operator[](column_number(col_name, loc));
192 return home().columns();
211 [[nodiscard]] size_type
212 column_number(
zview col_name,
sl = sl::current())
const;
222 return home().column_type(col_num, loc);
232 return column_type(column_number(col_name, loc), loc);
240 [[nodiscard]]
oid column_table(size_type col_num,
sl = sl::current())
const;
249 return column_table(column_number(col_name, loc), loc);
260 [[nodiscard]] size_type
263 return home().table_column(col_num, loc);
267 [[nodiscard]] size_type
270 return table_column(column_number(col_name, loc), loc);
283 template<
typename Tuple>
void to(Tuple &t,
sl loc = sl::current())
const
285 check_size(std::tuple_size_v<Tuple>, loc);
298 template<
typename... TYPE>
299 [[nodiscard]] std::tuple<TYPE...>
as(
sl loc = sl::current())
const
301 return as_tuple<std::tuple<TYPE...>>(loc);
314 template<
typename TUPLE>
318 check_size(std::tuple_size_v<TUPLE>, loc);
319 using seq = std::make_index_sequence<std::tuple_size_v<TUPLE>>;
320 return get_tuple<TUPLE>(
seq{}, loc);
336 void check_size(size_type expected,
sl loc)
const
338 if (size() != expected)
341 "Tried to extract {} field(s) from a row of {}.", expected, size()),
347 template<
typename Tuple>
void convert(Tuple &t,
sl loc)
const
350 t, std::make_index_sequence<std::tuple_size_v<Tuple>>{},
355 template<
typename Tuple, std::size_t... indexes>
356 void extract_fields(Tuple &t, std::index_sequence<indexes...>,
ctx c)
const
358 (extract_value<Tuple, indexes>(t, c), ...);
361 template<
typename Tuple, std::
size_t index>
362 void extract_value(Tuple &t,
ctx)
const;
365 template<
typename TUPLE, std::size_t... indexes>
366 [[nodiscard]]
auto get_tuple(std::index_sequence<indexes...>,
sl)
const
368 return std::make_tuple(get_field<TUPLE, indexes>()...);
372 template<
typename TUPLE, std::
size_t index>
373 [[nodiscard]]
auto get_field()
const
375 return (*
this)[index].as<std::tuple_element_t<index, TUPLE>>();
379 result
const *m_result =
nullptr;
431 m_result{ref.home()},
432 m_index{ref.row_number()},
433 m_end{std::size(ref)}
464 return rhs.m_result == m_result and rhs.m_index == m_index;
478 [[nodiscard]]
PQXX_PURE const_iterator begin() const noexcept;
479 [[nodiscard]]
PQXX_PURE const_iterator cbegin() const noexcept;
480 [[nodiscard]]
PQXX_PURE const_iterator end() const noexcept;
481 [[nodiscard]]
PQXX_PURE const_iterator cend() const noexcept;
492 [[nodiscard]]
field_ref front() const noexcept;
493 [[nodiscard]]
field_ref back() const noexcept;
505 #if defined(PQXX_HAVE_MULTIDIM)
523 # if defined(_MSC_VER)
524 # pragma warning(push)
525 # pragma warning(disable : 4548)
527 return as_row_ref()[col_name, loc];
528 # if defined(_MSC_VER)
529 # pragma warning(pop)
545 return as_row_ref()[col_name];
549 [[nodiscard]]
field_ref at(size_type,
sl = sl::current())
const;
580 [[nodiscard]] size_type
583 return as_row_ref().column_number(col_name, loc);
590 return as_row_ref().column_type(col_num, loc);
596 return column_type(column_number(col_name, loc), loc);
603 return as_row_ref().column_table(col_num, loc);
609 return column_table(column_number(col_name, loc), loc);
620 [[nodiscard]] size_type
623 return as_row_ref().table_column(col, loc);
627 [[nodiscard]] size_type
630 return as_row_ref().table_column(col_name, loc);
648 template<
typename Tuple>
void to(Tuple &t,
sl loc = sl::current())
const
650 check_size(std::tuple_size_v<Tuple>, loc);
663 template<
typename... TYPE>
664 [[nodiscard]] std::tuple<TYPE...>
as(
sl loc = sl::current())
const
666 return as_row_ref().as<TYPE...>(loc);
679 template<
typename TUPLE>
683 return as_row_ref().as_tuple<TUPLE>(loc);
686 [[deprecated(
"Swap iterators, not rows.")]]
void swap(row &) noexcept;
694 [[nodiscard]] row_ref as_row_ref() const noexcept
696 return {m_result, row_number()};
702 void check_size(size_type expected,
sl loc)
const
704 if (size() != expected)
707 "Tried to extract {} field(s) from a row of {}.", expected, size()),
712 [[nodiscard]] result
const &home()
const {
return m_result; }
715 template<
typename Tuple>
void convert(Tuple &t,
sl loc)
const
717 auto ref{as_row_ref()};
719 t, std::make_index_sequence<std::tuple_size_v<Tuple>>{},
720 conversion_context{home().get_encoding_group(), loc});
759 m_field{t.home(), t.row_number(), c}
769 return m_field.column_number();
825 return col() == i.
col();
829 return col() != i.
col();
833 return col() < i.
col();
837 return col() <= i.
col();
841 return col() > i.
col();
845 return col() >= i.
col();
854 operator+(difference_type)
const noexcept;
867 return *(*
this + offset);
921 iterator_type::operator--();
927 iterator_type::operator++();
933 iterator_type::operator-=(i);
938 iterator_type::operator+=(i);
957 [[nodiscard]] difference_type
960 return rhs.const_row_iterator::operator-(*this);
965 return *(*
this + offset);
987 return iterator_type::operator>(rhs);
992 return iterator_type::operator>=(rhs);
997 return iterator_type::operator<(rhs);
1002 return iterator_type::operator<=(rhs);
1012 {m_field.home(), m_field.row_number()},
1027 {m_field.home(), m_field.row_number()},
1035 return difference_type(m_field.column_number() - i.m_field.column_number());
1039 template<
typename Tuple, std::
size_t index>
1040 inline void row_ref::extract_value(Tuple &t,
ctx c)
const
1042 using field_type = std::remove_cvref_t<decltype(std::get<index>(t))>;
1043 field_ref const f{*m_result, m_index, index};
1044 std::get<index>(t) = from_string<field_type>(f, c);
1110 return as_row_ref().
cbegin();
Reverse iterator for a row. Use as row::const_reverse_iterator.
Definition: row.hxx:879
~const_reverse_row_iterator()=default
bool operator!=(const_reverse_row_iterator const &rhs) const noexcept
Definition: row.hxx:979
const_reverse_row_iterator & operator--() noexcept
Definition: row.hxx:925
const_reverse_row_iterator & operator+=(difference_type i) noexcept
Definition: row.hxx:931
bool operator>(const_reverse_row_iterator const &rhs) const noexcept
Definition: row.hxx:995
difference_type operator-(const_reverse_row_iterator const &rhs) const noexcept
Definition: row.hxx:958
const_reverse_row_iterator operator+(difference_type i) const noexcept
Definition: row.hxx:948
field_ref operator[](difference_type offset) const noexcept
Definition: row.hxx:963
bool operator==(const_reverse_row_iterator const &rhs) const noexcept
Definition: row.hxx:974
const_reverse_row_iterator() noexcept=default
const_reverse_row_iterator operator-(difference_type i) noexcept
Definition: row.hxx:953
bool operator>=(const_reverse_row_iterator const &rhs) const noexcept
Definition: row.hxx:1000
const_reverse_row_iterator & operator-=(difference_type i) noexcept
Definition: row.hxx:936
Iterator for fields in a row. Use as row::const_iterator.
Definition: row.hxx:748
field_ref const * pointer
Definition: row.hxx:752
bool operator<=(const_row_iterator const &i) const noexcept
Definition: row.hxx:835
const_row_iterator operator-(difference_type) const noexcept
Definition: row.hxx:1024
PQXX_PURE reference operator*() const noexcept
Definition: row.hxx:781
bool operator>(const_row_iterator const &i) const noexcept
Definition: row.hxx:839
const_row_iterator & operator--() noexcept
Definition: row.hxx:801
bool operator==(const_row_iterator const &i) const noexcept
Definition: row.hxx:823
const_row_iterator & operator-=(difference_type n) noexcept
Definition: row.hxx:812
const_row_iterator & operator+=(difference_type n) noexcept
Definition: row.hxx:807
bool operator!=(const_row_iterator const &i) const noexcept
Definition: row.hxx:827
const_row_iterator(const_row_iterator const &) noexcept=default
std::random_access_iterator_tag iterator_category
Definition: row.hxx:750
const_row_iterator & operator=(const_row_iterator &&) noexcept=default
PQXX_PURE size_type col() const noexcept
Current column number, if the iterator is pointing at a valid field.
Definition: row.hxx:767
field_ref operator[](difference_type offset) const noexcept
Definition: row.hxx:865
const_row_iterator(const_row_iterator &&) noexcept=default
row_size_type size_type
Definition: row.hxx:753
const_row_iterator() noexcept=default
bool operator>=(const_row_iterator const &i) const noexcept
Definition: row.hxx:843
const_row_iterator & operator=(const_row_iterator const &) noexcept=default
row_difference_type difference_type
Definition: row.hxx:754
PQXX_PURE constexpr PQXX_RETURNS_NONNULL pointer operator->() const noexcept
Definition: row.hxx:777
const_row_iterator(field_ref const &f) noexcept
Definition: row.hxx:761
field_ref const value_type
Definition: row.hxx:751
bool operator<(const_row_iterator const &i) const noexcept
Definition: row.hxx:831
const_row_iterator operator+(difference_type) const noexcept
Definition: row.hxx:1009
Lightweight reference to a field in a result set.
Definition: field.hxx:52
Reference to a field in a result set.
Definition: field.hxx:309
Definition: field_ref-const_row_iterator.hxx:15
Definition: row_ref-const_result_iterator.hxx:15
Definition: row_ref-result.hxx:15
Definition: row_ref-row.hxx:9
Iterator for looped unpacking of a result.
Definition: result_iter.hxx:31
Result set containing data returned by a query or command.
Definition: result.hxx:101
PQXX_PURE row_size_type columns() const noexcept
Number of columns in result.
Definition: result.cxx:551
result_size_type size_type
Definition: result.hxx:103
oid column_table(row_size_type col_num, sl=sl::current()) const
What table did this column come from?
Definition: result.cxx:473
row_size_type column_number(zview name, sl=sl::current()) const
Number of given column (throws exception if it doesn't exist).
Definition: result.cxx:462
Lightweight reference to one row in a result.
Definition: row.hxx:57
const_iterator cend() const noexcept
Definition: row.hxx:1058
const_reverse_row_iterator rend() const noexcept
Definition: row.hxx:1083
reference front() const noexcept
Definition: row.hxx:1088
TUPLE as_tuple(sl loc=sl::current()) const requires(requires(TUPLE t)
Convert to a given tuple of values,.
Definition: row.hxx:315
row_ref(result const &res, result_size_type index)
Definition: row.hxx:71
reference at(zview col_name, sl loc=sl::current()) const
Address field by name.
Definition: row.hxx:183
size_type column_number(zview col_name, sl=sl::current()) const
Number of given column (throws exception if it doesn't exist).
Definition: row.hxx:1098
size_type table_column(zview col_name, sl loc=sl::current()) const
What column number in its table did this result column come from?
Definition: row.hxx:268
void to(Tuple &t, sl loc=sl::current()) const
Extract entire row's values into a tuple.
Definition: row.hxx:283
row_difference_type difference_type
Definition: row.hxx:60
row_ref & operator=(row_ref const &) noexcept=default
reference back() const noexcept
Definition: row.hxx:1093
constexpr PQXX_PURE result::size_type row_number() const noexcept
Row number, assuming this is a real row and not end()/rend().
Definition: row.hxx:197
field_ref const * pointer
Definition: row.hxx:64
const_reverse_row_iterator crbegin() const noexcept
Definition: row.hxx:1068
oid column_table(size_type col_num, sl=sl::current()) const
What table did this column come from?
Definition: row.hxx:1103
oid column_type(size_type col_num, sl loc=sl::current()) const
Return a column's type.
Definition: row.hxx:220
reference at(size_type i, sl loc=sl::current()) const
Address a field by number, but check that the number is in range.
Definition: row.hxx:161
const_iterator cbegin() const noexcept
Definition: row.hxx:1048
oid column_table(zview col_name, sl loc=sl::current()) const
What table did this column come from?
Definition: row.hxx:247
PQXX_PURE bool operator!=(row_ref const &rhs) const noexcept
Definition: row.hxx:106
row_ref(row_ref const &)=default
const_reverse_row_iterator rbegin() const noexcept
Definition: row.hxx:1073
const_iterator begin() const noexcept
Definition: row.hxx:1053
std::tuple< TYPE... > as(sl loc=sl::current()) const
Extract entire row's values into a tuple.
Definition: row.hxx:299
size_type table_column(size_type col_num, sl loc=sl::current()) const
What column number in its table did this result column come from?
Definition: row.hxx:261
row_size_type size_type
Definition: row.hxx:59
row_ref & operator=(row_ref &&) noexcept=default
oid column_type(zview col_name, sl loc=sl::current()) const
Return a column's type.
Definition: row.hxx:230
const_reverse_row_iterator crend() const noexcept
Definition: row.hxx:1078
row_ref(row_ref &&)=default
const_iterator end() const noexcept
Definition: row.hxx:1063
std::make_index_sequence< std::tuple_size_v< TUPLE > > seq
Definition: row.hxx:319
PQXX_PURE size_type size() const noexcept
Definition: row.hxx:190
PQXX_PURE result const & home() const noexcept
The result object to which this row_ref refers.
Definition: row.hxx:324
Reference to one row in a result.
Definition: row.hxx:415
oid column_table(size_type col_num, sl loc=sl::current()) const
What table did this column come from?
Definition: row.hxx:601
row_size_type size_type
Definition: row.hxx:418
PQXX_PURE const_reverse_row_iterator rend() const noexcept
Definition: row.hxx:1143
constexpr PQXX_PURE result::size_type num() const noexcept
Definition: row.hxx:634
oid column_type(zview col_name, sl loc=sl::current()) const
Return a column's type.
Definition: row.hxx:594
size_type table_column(zview col_name, sl loc=sl::current()) const
What column number in its table did this result column come from?
Definition: row.hxx:628
constexpr PQXX_PURE size_type size() const noexcept
Definition: row.hxx:556
row_difference_type difference_type
Definition: row.hxx:419
TUPLE as_tuple(sl loc=sl::current()) const requires(requires(TUPLE t)
Convert to a given tuple of values,.
Definition: row.hxx:680
size_type column_number(zview col_name, sl loc=sl::current()) const
Number of given column (throws exception if it doesn't exist).
Definition: row.hxx:581
size_type table_column(size_type col, sl loc=sl::current()) const
What column number in its table did this result column come from?
Definition: row.hxx:621
constexpr PQXX_PURE result::size_type row_number() const noexcept
Row number, assuming this is a real row and not end()/rend().
Definition: row.hxx:570
PQXX_PURE const_reverse_row_iterator crend() const noexcept
Definition: row.hxx:1138
PQXX_PURE const_reverse_row_iterator crbegin() const noexcept
Definition: row.hxx:1128
oid column_table(zview col_name, sl loc=sl::current()) const
What table did this column come from?
Definition: row.hxx:607
std::tuple< TYPE... > as(sl loc=sl::current()) const
Extract entire row's values into a tuple.
Definition: row.hxx:664
constexpr result::size_type rownumber() const noexcept
Row number, assuming this is a real row and not end()/rend().
Definition: row.hxx:563
PQXX_PURE const_iterator cend() const noexcept
Definition: row.hxx:1118
row & operator=(row const &) noexcept=default
row & operator=(row &&) noexcept=default
PQXX_PURE const_iterator end() const noexcept
Definition: row.hxx:1123
void to(Tuple &t, sl loc=sl::current()) const
Extract entire row's values into a tuple.
Definition: row.hxx:648
PQXX_PURE bool operator!=(row const &rhs) const noexcept
Definition: row.hxx:466
PQXX_PURE const_iterator begin() const noexcept
Definition: row.hxx:1113
PQXX_PURE field_ref operator[](zview col_name) const
Definition: row.hxx:543
oid column_type(size_type col_num, sl loc=sl::current()) const
Return a column's type.
Definition: row.hxx:588
PQXX_PURE const_reverse_row_iterator rbegin() const noexcept
Definition: row.hxx:1133
PQXX_PURE const_iterator cbegin() const noexcept
Definition: row.hxx:1108
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:55
Something is out of range, similar to std::out_of_range.
Definition: except.hxx:651
Error in usage of libpqxx library, similar to std::logic_error.
Definition: except.hxx:580
Definition: connection.hxx:94
Private namespace for libpqxx's internal use; do not access.
Definition: connection.cxx:333
The home of all libpqxx classes, functions, templates, etc.
Definition: array.cxx:26
int row_size_type
Number of fields in a row of database data.
Definition: types.hxx:83
int row_difference_type
Difference between row sizes.
Definition: types.hxx:86
std::source_location sl
Convenience alias for std::source_location. It's just too long.
Definition: types.hxx:38
const_result_iterator operator+(result::difference_type o, const_result_iterator const &i)
Definition: result_iterator.hxx:321
int result_size_type
Number of rows in a result set.
Definition: types.hxx:77
std::remove_cvref_t< std::ranges::range_value_t< CONTAINER > > value_type
The type of a container's elements.
Definition: types.hxx:138
requires(pqxx::internal::to_buf_7< TYPE > or pqxx::internal::to_buf_8< TYPE >) const eval bool supports_to_buf_8()
Is the libpqxx 8 version of to_buf() supported for TYPE?
Definition: strconv.hxx:417
unsigned int oid
PostgreSQL database row identifier.
Definition: types.hxx:73
conversion_context const & ctx
Convenience alias: const reference to a pqxx::conversion_context.
Definition: strconv.hxx:201
constexpr bool operator==(char const lhs[], pqxx::zview rhs) noexcept
Disambiguating comparison operator: leave it to std::string_view.
Definition: zview.hxx:203
format
Format code: is data text or binary?
Definition: types.hxx:121
Contextual parameters for string conversions implementations.
Definition: strconv.hxx:163