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"
46class PQXX_LIBEXPORT
row
58 row() noexcept = default;
61 row &operator=(
row const &) noexcept = default;
62 row &operator=(
row &&) noexcept = default;
68 [[nodiscard]] PQXX_PURE
bool operator==(
row const &) const noexcept;
69 [[nodiscard]]
bool operator!=(
row const &rhs) const noexcept
71 return not operator==(rhs);
75 [[nodiscard]] const_iterator begin() const noexcept;
76 [[nodiscard]] const_iterator cbegin() const noexcept;
77 [[nodiscard]] const_iterator end() const noexcept;
78 [[nodiscard]] const_iterator cend() const noexcept;
84 [[nodiscard]] reference front() const noexcept;
85 [[nodiscard]] reference back() const noexcept;
92 [[nodiscard]] reference operator[](size_type) const noexcept;
96 [[nodiscard]] reference operator[](
zview col_name) const;
98 reference at(size_type) const;
102 reference at(
zview col_name) const;
106 return m_end - m_begin;
109 [[deprecated(
"Swap iterators, not rows.")]]
void swap(
row &)
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));
175 [[deprecated(
"Row slicing is going away. File a bug if you need it.")]]
row
176 slice(size_type sbegin, size_type send)
const;
179 [[nodiscard, deprecated(
"Row slicing is going away.")]] PQXX_PURE
bool
180 empty() const noexcept;
188 template<typename Tuple>
void to(Tuple &t)
const
190 check_size(std::tuple_size_v<Tuple>);
200 template<
typename... TYPE> std::tuple<TYPE...>
as()
const
202 check_size(
sizeof...(TYPE));
203 using seq = std::make_index_sequence<
sizeof...(TYPE)>;
204 return get_tuple<std::tuple<TYPE...>>(seq{});
215 if (size() != expected)
217 "Tried to extract ", expected,
" field(s) from a row of ", size(),
227 using seq = std::make_index_sequence<std::tuple_size_v<TUPLE>>;
228 return get_tuple<TUPLE>(seq{});
233 template<
typename Tuple>
void convert(Tuple &t)
const
235 extract_fields(t, std::make_index_sequence<std::tuple_size_v<Tuple>>{});
257 template<
typename Tuple, std::size_t... indexes>
258 void extract_fields(Tuple &t, std::index_sequence<indexes...>)
const
260 (extract_value<Tuple, indexes>(t), ...);
263 template<
typename Tuple, std::
size_t index>
264 void extract_value(Tuple &t)
const;
267 template<
typename TUPLE, std::size_t... indexes>
268 auto get_tuple(std::index_sequence<indexes...>)
const
270 return std::make_tuple(get_field<TUPLE, indexes>()...);
274 template<
typename TUPLE, std::
size_t index>
auto get_field()
const
276 return (*
this)[index].as<std::tuple_element_t<index, TUPLE>>();
292#include "pqxx/internal/ignore-deprecated-pre.hxx"
294#include "pqxx/internal/ignore-deprecated-post.hxx"
296 field{t.m_result, t.m_index, c}
306 [[nodiscard]] constexpr
pointer operator->() const noexcept {
return this; }
346 [[nodiscard]]
constexpr bool
349 return col() == i.col();
351 [[nodiscard]]
constexpr bool
354 return col() != i.col();
356 [[nodiscard]]
constexpr bool
359 return col() < i.col();
361 [[nodiscard]]
constexpr bool
364 return col() <= i.col();
366 [[nodiscard]]
constexpr bool
369 return col() > i.col();
371 [[nodiscard]]
constexpr bool
374 return col() >= i.col();
383 operator+(difference_type)
const noexcept;
419 [[nodiscard]] PQXX_PURE iterator_type base() const noexcept;
425 using iterator_type::operator->;
426 using iterator_type::operator*;
433 const_reverse_row_iterator &
436 iterator_type::operator=(r);
441 iterator_type::operator--();
447 iterator_type::operator++();
453 iterator_type::operator-=(i);
458 iterator_type::operator+=(i);
477 [[nodiscard]] difference_type
480 return rhs.const_row_iterator::operator-(*this);
491 return iterator_type::operator==(rhs);
496 return !operator==(rhs);
499 [[nodiscard]]
constexpr bool
502 return iterator_type::operator>(rhs);
504 [[nodiscard]]
constexpr bool
507 return iterator_type::operator>=(rhs);
509 [[nodiscard]]
constexpr bool
512 return iterator_type::operator<(rhs);
514 [[nodiscard]]
constexpr bool
517 return iterator_type::operator<=(rhs);
528 row{home(), idx(), home().columns()},
543 row{home(), idx(), home().columns()},
554template<
typename Tuple, std::
size_t index>
555inline void row::extract_value(Tuple &t)
const
559 std::get<index>(t) = from_string<field_type>(f);
The home of all libpqxx classes, functions, templates, etc.
Definition array.hxx:33
int row_size_type
Number of fields in a row of database data.
Definition types.hxx:34
std::remove_cv_t< std::remove_reference_t< TYPE > > strip_t
Remove any constness, volatile, and reference-ness from a type.
Definition types.hxx:91
int row_difference_type
Difference between row sizes.
Definition types.hxx:37
const_row_iterator operator+(const_row_iterator::difference_type o, const_row_iterator const &i) noexcept
Definition row.hxx:532
int result_size_type
Number of rows in a result set.
Definition types.hxx:28
Internal items for libpqxx' own use. Do not use these yourself.
Definition composite.hxx:84
Error in usage of libpqxx library, similar to std::logic_error.
Definition except.hxx:249
Reference to a field in a result set.
Definition field.hxx:35
Result set containing data returned by a query or command.
Definition result.hxx:73
result_size_type size_type
Definition result.hxx:75
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:200
row_size_type size_type
Definition row.hxx:49
oid column_type(zview col_name) const
Return a column's type.
Definition row.hxx:128
row_difference_type difference_type
Definition row.hxx:50
result m_result
Result set of which this is one row.
Definition row.hxx:241
result::size_type m_index
Row number.
Definition row.hxx:248
constexpr result::size_type num() const noexcept
Definition row.hxx:159
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:225
void check_size(size_type expected) const
Throw usage_error if row size is not expected.
Definition row.hxx:213
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:233
oid column_table(zview col_name) const
What table did this column come from?
Definition row.hxx:137
Iterator for fields in a row. Use as row::const_iterator.
Definition row.hxx:283
const_row_iterator operator-(difference_type) const noexcept
Definition row.hxx:539
const_row_iterator & operator=(const_row_iterator &&) noexcept=default
reference operator*() const noexcept
Definition row.hxx:307
const_row_iterator(field const &F) noexcept
Definition row.hxx:298
friend const_row_iterator operator+(difference_type, const_row_iterator const &) noexcept
Definition row.hxx:532
constexpr bool operator>=(const_row_iterator const &i) const noexcept
Definition row.hxx:372
const_row_iterator(const_row_iterator const &) noexcept=default
const_row_iterator & operator=(const_row_iterator const &) noexcept=default
std::random_access_iterator_tag iterator_category
Definition row.hxx:285
constexpr bool operator==(const_row_iterator const &i) const noexcept
Definition row.hxx:347
field const * pointer
Definition row.hxx:287
field const value_type
Definition row.hxx:286
constexpr bool operator!=(const_row_iterator const &i) const noexcept
Definition row.hxx:352
const_row_iterator(const_row_iterator &&) noexcept=default
row_size_type size_type
Definition row.hxx:288
const_row_iterator & operator--() noexcept
Definition row.hxx:324
const_row_iterator() noexcept=default
row_difference_type difference_type
Definition row.hxx:289
const_row_iterator & operator-=(difference_type i) noexcept
Definition row.hxx:335
const_row_iterator & operator+=(difference_type i) noexcept
Definition row.hxx:330
const_row_iterator(row const &t, row_size_type c) noexcept
Definition row.hxx:295
constexpr bool operator>(const_row_iterator const &i) const noexcept
Definition row.hxx:367
Reverse iterator for a row. Use as row::const_reverse_iterator.
Definition row.hxx:398
const_reverse_row_iterator operator++() noexcept
Definition row.hxx:439
bool operator!=(const_reverse_row_iterator const &rhs) const noexcept
Definition row.hxx:494
constexpr bool operator>=(const_reverse_row_iterator const &rhs) const noexcept
Definition row.hxx:515
constexpr bool operator>(const_reverse_row_iterator const &rhs) const noexcept
Definition row.hxx:510
difference_type operator-(const_reverse_row_iterator const &rhs) const noexcept
Definition row.hxx:478
const_reverse_row_iterator & operator+=(difference_type i) noexcept
Definition row.hxx:451
const_reverse_row_iterator operator+(difference_type i) const noexcept
Definition row.hxx:468
const_reverse_row_iterator & operator-=(difference_type i) noexcept
Definition row.hxx:456
const_reverse_row_iterator & operator--() noexcept
Definition row.hxx:445
row_difference_type difference_type
Definition row.hxx:289
bool operator==(const_reverse_row_iterator const &rhs) const noexcept
Definition row.hxx:489
const_reverse_row_iterator() noexcept=default
const_reverse_row_iterator operator-(difference_type i) noexcept
Definition row.hxx:473
iterator_type::value_type value_type
Definition row.hxx:405
Marker-type wrapper: zero-terminated std::string_view.
Definition zview.hxx:38