16#if !defined(PQXX_HEADER_PRE)
17# error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
20#include "pqxx/except.hxx"
21#include "pqxx/field.hxx"
22#include "pqxx/result.hxx"
24#include "pqxx/internal/concat.hxx"
28template<
typename... T>
class result_iter;
46class PQXX_LIBEXPORT
row
60 row()
noexcept =
default;
61 row(
row &&)
noexcept =
default;
62 row(
row const &)
noexcept =
default;
63 row &operator=(
row const &)
noexcept =
default;
64 row &operator=(
row &&)
noexcept =
default;
70 [[nodiscard]] PQXX_PURE
bool operator==(
row const &)
const noexcept;
71 [[nodiscard]]
bool operator!=(
row const &rhs)
const noexcept
73 return not operator==(rhs);
86 [[nodiscard]]
reference front()
const noexcept;
94 [[nodiscard]]
reference operator[](size_type) const noexcept;
106 [[nodiscard]] constexpr size_type size() const noexcept
108 return m_end - m_begin;
112 [[nodiscard]]
constexpr result::size_type
rownumber() const noexcept
122 [[nodiscard]] size_type column_number(
zview col_name)
const;
125 [[nodiscard]]
oid column_type(size_type)
const;
130 return column_type(column_number(col_name));
134 [[nodiscard]]
oid column_table(size_type col_num)
const;
139 return column_table(column_number(col_name));
150 [[nodiscard]] size_type table_column(size_type)
const;
155 return table_column(column_number(col_name));
159 [[nodiscard]]
constexpr result::size_type num() const noexcept
173 template<
typename Tuple>
void to(Tuple &t)
const
175 check_size(std::tuple_size_v<Tuple>);
188 template<
typename... TYPE> std::tuple<TYPE...>
as()
const
190 check_size(
sizeof...(TYPE));
191 using seq = std::make_index_sequence<
sizeof...(TYPE)>;
192 return get_tuple<std::tuple<TYPE...>>(seq{});
195 [[deprecated(
"Swap iterators, not rows.")]]
void swap(
row &)
noexcept;
208 [[deprecated(
"Row slicing is going away. File a bug if you need it.")]]
row
209 slice(size_type sbegin, size_type send)
const;
212 [[nodiscard, deprecated(
"Row slicing is going away.")]] PQXX_PURE
bool
213 empty() const noexcept;
221 void check_size(size_type expected)
const
223 if (size() != expected)
225 "Tried to extract ", expected,
" field(s) from a row of ", size(),
235 using seq = std::make_index_sequence<std::tuple_size_v<TUPLE>>;
236 return get_tuple<TUPLE>(seq{});
241 template<
typename Tuple>
void convert(Tuple &t)
const
243 extract_fields(t, std::make_index_sequence<std::tuple_size_v<Tuple>>{});
256 result::size_type m_index = 0;
260 size_type m_begin = 0;
265 template<
typename Tuple, std::size_t... indexes>
266 void extract_fields(Tuple &t, std::index_sequence<indexes...>)
const
268 (extract_value<Tuple, indexes>(t), ...);
271 template<
typename Tuple, std::
size_t index>
272 void extract_value(Tuple &t)
const;
275 template<
typename TUPLE, std::size_t... indexes>
276 auto get_tuple(std::index_sequence<indexes...>)
const
278 return std::make_tuple(get_field<TUPLE, indexes>()...);
282 template<
typename TUPLE, std::
size_t index>
auto get_field()
const
284 return (*
this)[index].as<std::tuple_element_t<index, TUPLE>>();
293 using iterator_category = std::random_access_iterator_tag;
294 using value_type =
field const;
295 using pointer =
field const *;
300#include "pqxx/internal/ignore-deprecated-pre.hxx"
302#include "pqxx/internal/ignore-deprecated-post.hxx"
314 [[nodiscard]]
constexpr pointer operator->()
const noexcept {
return this; }
315 [[nodiscard]]
reference operator*()
const noexcept {
return {*
this}; }
340 m_col = size_type(difference_type(m_col) + i);
345 m_col = size_type(difference_type(m_col) - i);
354 [[nodiscard]]
constexpr bool
357 return col() == i.col();
359 [[nodiscard]]
constexpr bool
362 return col() != i.col();
364 [[nodiscard]]
constexpr bool
367 return col() < i.col();
369 [[nodiscard]]
constexpr bool
372 return col() <= i.col();
374 [[nodiscard]]
constexpr bool
377 return col() > i.col();
379 [[nodiscard]]
constexpr bool
382 return col() >= i.col();
391 operator+(difference_type)
const noexcept;
397 operator-(difference_type)
const noexcept;
398 [[nodiscard]]
inline difference_type
401 [[nodiscard]]
inline field operator[](difference_type offset)
const noexcept
403 return *(*
this + offset);
415 using iterator_type::difference_type;
416 using iterator_type::iterator_category;
417 using iterator_type::pointer;
418 using value_type = iterator_type::value_type;
438 using iterator_type::operator->;
439 using iterator_type::operator*;
449 iterator_type::operator=(r);
454 iterator_type::operator--();
460 iterator_type::operator++();
466 iterator_type::operator-=(i);
471 iterator_type::operator+=(i);
481 operator+(difference_type i)
const noexcept
486 operator-(difference_type i)
noexcept
490 [[nodiscard]] difference_type
493 return rhs.const_row_iterator::operator-(*this);
495 [[nodiscard]]
inline field operator[](difference_type offset)
const noexcept
497 return *(*
this + offset);
508 return iterator_type::operator==(rhs);
513 return !operator==(rhs);
516 [[nodiscard]]
constexpr bool
519 return iterator_type::operator>(rhs);
521 [[nodiscard]]
constexpr bool
524 return iterator_type::operator>=(rhs);
526 [[nodiscard]]
constexpr bool
529 return iterator_type::operator<(rhs);
531 [[nodiscard]]
constexpr bool
534 return iterator_type::operator<=(rhs);
541const_row_iterator::operator+(difference_type o)
const noexcept
545 row{home(), idx(), home().columns()},
546 size_type(difference_type(col()) + o)};
549inline const_row_iterator operator+(
550 const_row_iterator::difference_type o, const_row_iterator
const &i)
noexcept
555inline const_row_iterator
556const_row_iterator::operator-(difference_type o)
const noexcept
560 row{home(), idx(), home().columns()},
561 size_type(difference_type(col()) - o)};
564inline const_row_iterator::difference_type
565const_row_iterator::operator-(const_row_iterator
const &i)
const noexcept
567 return difference_type(num() - i.num());
571template<
typename Tuple, std::
size_t index>
572inline void row::extract_value(Tuple &t)
const
574 using field_type = strip_t<decltype(std::get<index>(t))>;
576 std::get<index>(t) = from_string<field_type>(f);
Reverse iterator for a row. Use as row::const_reverse_iterator.
Definition row.hxx:411
Iterator for fields in a row. Use as row::const_iterator.
Definition row.hxx:291
Reference to a field in a result set.
Definition field.hxx:35
Iterator for looped unpacking of a result.
Definition result_iter.hxx:27
Result set containing data returned by a query or command.
Definition result.hxx:92
Reference to one row in a result.
Definition row.hxx:47
std::tuple< TYPE... > as() const
Extract entire row's values into a tuple.
Definition row.hxx:188
oid column_type(zview col_name) const
Return a column's type.
Definition row.hxx:128
result m_result
Result set of which this is one row.
Definition row.hxx:249
result::size_type m_index
Row number.
Definition row.hxx:256
constexpr result::size_type rownumber() const noexcept
Row number, assuming this is a real row and not end()/rend().
Definition row.hxx:112
TUPLE as_tuple() const
Convert to a given tuple of values, don't check sizes.
Definition row.hxx:233
void to(Tuple &t) const
Extract entire row's values into a tuple.
Definition row.hxx:173
size_type table_column(zview col_name) const
What column number in its table did this result column come from?
Definition row.hxx:153
void convert(Tuple &t) const
Convert entire row to tuple fields, without checking row size.
Definition row.hxx:241
oid column_table(zview col_name) const
What table did this column come from?
Definition row.hxx:137
Marker-type wrapper: zero-terminated std::string_view.
Definition zview.hxx:38
Error in usage of libpqxx library, similar to std::logic_error.
Definition except.hxx:249
Internal items for libpqxx' own use. Do not use these yourself.
Definition encodings.cxx:33
The home of all libpqxx classes, functions, templates, etc.
Definition array.cxx:27
int row_size_type
Number of fields in a row of database data.
Definition types.hxx:34
int row_difference_type
Difference between row sizes.
Definition types.hxx:37
int result_size_type
Number of rows in a result set.
Definition types.hxx:28
unsigned int oid
PostgreSQL database row identifier.
Definition libpq-forward.hxx:33