16 #include "pqxx/except.hxx" 17 #include "pqxx/field.hxx" 18 #include "pqxx/result.hxx" 20 #include "pqxx/internal/concat.hxx" 42 class PQXX_LIBEXPORT
row 56 row(
row const &) =
default;
57 row &operator=(
row const &) =
default;
58 row &operator=(
row &&) =
default;
64 [[nodiscard]] PQXX_PURE
bool operator==(
row const &)
const noexcept;
67 return not operator==(rhs);
71 [[nodiscard]] const_iterator begin() const noexcept;
72 [[nodiscard]] const_iterator cbegin() const noexcept;
73 [[nodiscard]] const_iterator end() const noexcept;
74 [[nodiscard]] const_iterator cend() const noexcept;
80 [[nodiscard]] reference front() const noexcept;
81 [[nodiscard]] reference back() const noexcept;
88 [[nodiscard]] reference operator[](size_type) const noexcept;
92 [[nodiscard]] reference operator[](
zview col_name) const;
94 reference at(size_type) const;
98 reference at(
zview col_name) const;
100 [[nodiscard]]
size_type size() const noexcept {
return m_end - m_begin; }
102 [[deprecated(
"Swap iterators, not rows.")]]
void swap(
row &) noexcept;
114 [[nodiscard]] size_type column_number(
zview col_name)
const;
118 [[nodiscard]] oid column_type(size_type)
const;
123 return column_type(column_number(col_name));
127 [[nodiscard]] oid column_table(size_type col_num)
const;
132 return column_table(column_number(col_name));
143 [[nodiscard]] size_type table_column(size_type)
const;
148 return table_column(column_number(col_name));
165 [[deprecated(
"Row slicing is going away. File a bug if you need it.")]]
row 166 slice(size_type sbegin, size_type send)
const;
169 [[nodiscard, deprecated(
"Row slicing is going away.")]] PQXX_PURE
bool 170 empty() const noexcept;
175 template<typename Tuple>
void to(Tuple &t)
const 177 check_size(std::tuple_size_v<Tuple>);
181 template<
typename... TYPE> std::tuple<TYPE...>
as()
const 183 check_size(
sizeof...(TYPE));
184 using seq = std::make_index_sequence<
sizeof...(TYPE)>;
185 return get_tuple<std::tuple<TYPE...>>(seq{});
196 if (size() != expected)
198 "Tried to extract ", expected,
" field(s) from a row of ", size(),
204 template<
typename Tuple>
void convert(Tuple &t)
const 207 constexpr
auto tup_size{std::tuple_size_v<Tuple>};
208 extract_fields(t, std::make_index_sequence<tup_size>{});
230 template<
typename Tuple, std::size_t... indexes>
231 void extract_fields(Tuple &t, std::index_sequence<indexes...>)
const 233 (extract_value<Tuple, indexes>(t), ...);
236 template<
typename Tuple, std::
size_t index>
237 void extract_value(Tuple &t)
const;
240 template<
typename TUPLE, std::size_t... indexes>
241 auto get_tuple(std::index_sequence<indexes...>)
const 243 return std::make_tuple(get_field<TUPLE, indexes>()...);
247 template<
typename TUPLE, std::
size_t index>
auto get_field()
const 249 return (*
this)[index].as<std::tuple_element_t<index, TUPLE>>();
265 #include "pqxx/internal/ignore-deprecated-pre.hxx" 267 #include "pqxx/internal/ignore-deprecated-post.hxx" 269 field{t.m_result, t.m_index, c}
272 const_row_iterator(const_row_iterator
const &) =
default;
273 const_row_iterator(const_row_iterator &&) =
default;
321 return col() == i.
col();
325 return col() != i.
col();
329 return col() < i.
col();
333 return col() <= i.
col();
337 return col() > i.
col();
341 return col() >= i.
col();
355 [[nodiscard]]
inline difference_type
383 [[nodiscard]] PQXX_PURE iterator_type base() const noexcept;
389 using iterator_type::operator->;
390 using iterator_type::operator*;
399 iterator_type::operator=(r);
404 iterator_type::operator--();
410 iterator_type::operator++();
416 iterator_type::operator-=(i);
421 iterator_type::operator+=(i);
438 [[nodiscard]] difference_type
441 return rhs.const_row_iterator::operator-(*this);
452 return iterator_type::operator==(rhs);
457 return !operator==(rhs);
462 return iterator_type::operator>(rhs);
466 return iterator_type::operator>=(rhs);
470 return iterator_type::operator<(rhs);
474 return iterator_type::operator<=(rhs);
494 inline const_row_iterator
510 template<
typename Tuple, std::
size_t index>
511 inline void row::extract_value(Tuple &t)
const 515 std::get<index>(t) = from_string<field_type>(f);
const_row_iterator(field const &F) noexcept
Definition: row.hxx:271
void check_size(size_type expected) const
Throw usage_error if row size is not expected.
Definition: row.hxx:194
bool operator==(const_row_iterator const &i) const
Definition: row.hxx:319
const_row_iterator & operator--()
Definition: row.hxx:297
const_row_iterator & operator+=(difference_type i)
Definition: row.hxx:303
row_size_type col() const noexcept
Definition: field.hxx:255
row_size_type size_type
Definition: row.hxx:45
Error in usage of libpqxx library, similar to std::logic_error.
Definition: except.hxx:161
result::size_type m_index
Row number.
Definition: row.hxx:221
bool operator>(const_row_iterator const &i) const
Definition: row.hxx:335
std::random_access_iterator_tag iterator_category
Definition: row.hxx:258
Reference to one row in a result.
Definition: row.hxx:42
result::size_type num() const
Definition: row.hxx:152
const_reverse_row_iterator & operator-=(difference_type i)
Definition: row.hxx:419
field const value_type
Definition: row.hxx:259
bool operator>=(const_reverse_row_iterator const &rhs) const
Definition: row.hxx:472
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:37
Reverse iterator for a row. Use as row::const_reverse_iterator.
Definition: row.hxx:362
Reference to a field in a result set.
Definition: field.hxx:30
bool operator>=(const_row_iterator const &i) const
Definition: row.hxx:339
Result set containing data returned by a query or command.
Definition: result.hxx:67
row_size_type size_type
Definition: row.hxx:261
result m_result
Result set of which this is one row.
Definition: row.hxx:214
PQXX_PURE row_size_type num() const
Return row number. The first row is row 0, the second is row 1, etc.
Definition: field.hxx:94
result_size_type size_type
Definition: result.hxx:70
bool operator>(const_reverse_row_iterator const &rhs) const
Definition: row.hxx:468
Iterator for fields in a row. Use as row::const_iterator.
Definition: row.hxx:255
oid column_type(zview col_name) const
Return a column's type.
Definition: row.hxx:121
result::size_type rownumber() const noexcept
Row number, assuming this is a real row and not end()/rend().
Definition: row.hxx:105
row_difference_type difference_type
Definition: row.hxx:46
field_size_type size_type
Definition: field.hxx:33
int result_size_type
Number of rows in a result set.
Definition: types.hxx:24
bool operator==(const_reverse_row_iterator const &rhs) const noexcept
Definition: row.hxx:450
const_reverse_row_iterator operator-(difference_type i)
Definition: row.hxx:434
int row_difference_type
Difference between row sizes.
Definition: types.hxx:33
const_reverse_row_iterator operator++()
Definition: row.hxx:402
result const & home() const noexcept
Definition: field.hxx:253
const_row_iterator operator-(difference_type) const
Definition: row.hxx:495
const_reverse_row_iterator & operator--()
Definition: row.hxx:408
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:22
PQXX_PURE row_size_type columns() const noexcept
Number of columns in result.
Definition: result.cxx:477
bool operator<(const_reverse_row_iterator const &rhs) const
Definition: row.hxx:460
difference_type operator-(const_reverse_row_iterator const &rhs) const
Definition: row.hxx:439
field const * pointer
Definition: row.hxx:260
bool operator<=(const_reverse_row_iterator const &rhs) const
Definition: row.hxx:464
std::remove_cv_t< std::remove_reference_t< TYPE > > strip_t
Remove any constness, volatile, and reference-ness from a type.
Definition: types.hxx:87
const_row_iterator(row const &t, row_size_type c) noexcept
End a code block started by "ignore-deprecated-pre.hxx".
Definition: row.hxx:268
const_row_iterator & operator++()
Definition: row.hxx:291
row_difference_type difference_type
Definition: row.hxx:262
int row_size_type
Number of fields in a row of database data.
Definition: types.hxx:30
const_row_iterator operator+(const_row_iterator::difference_type o, const_row_iterator const &i)
Definition: row.hxx:489
bool operator!=(row const &rhs) const noexcept
Definition: row.hxx:65
void convert(Tuple &t) const
Convert entire row to tuple fields, without checking row size.
Definition: row.hxx:204
Internal items for libpqxx' own use. Do not use these yourself.
Definition: composite.hxx:79
const_reverse_row_iterator(super const &rhs) noexcept
Definition: row.hxx:377
bool operator!=(const_reverse_row_iterator const &rhs) const noexcept
Definition: row.hxx:455
const_reverse_row_iterator & operator+=(difference_type i)
Definition: row.hxx:414
result::size_type idx() const noexcept
Definition: field.hxx:254
oid column_table(zview col_name) const
What table did this column come from?
Definition: row.hxx:130
std::tuple< TYPE... > as() const
Definition: row.hxx:181
reference operator*() const
Definition: row.hxx:280
size_type table_column(zview col_name) const
What column number in its table did this result column come from?
Definition: row.hxx:146
const_row_iterator operator+(difference_type) const
Definition: row.hxx:480
bool operator!=(const_row_iterator const &i) const
Definition: row.hxx:323
bool operator<=(const_row_iterator const &i) const
Definition: row.hxx:331
bool operator<(const_row_iterator const &i) const
Definition: row.hxx:327
const_reverse_row_iterator operator+(difference_type i) const
Definition: row.hxx:430
const_row_iterator & operator-=(difference_type i)
Definition: row.hxx:308
pointer operator->() const
Definition: row.hxx:279