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
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;
115 [[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}
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();
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);
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);
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:23
const_row_iterator operator+(const_row_iterator::difference_type o, const_row_iterator const &i)
Definition: row.hxx:489
int row_size_type
Number of fields in a row of database data.
Definition: types.hxx:30
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
int row_difference_type
Difference between row sizes.
Definition: types.hxx:33
int result_size_type
Number of rows in a result set.
Definition: types.hxx:24
Internal items for libpqxx' own use. Do not use these yourself.
Definition: composite.hxx:80
Error in usage of libpqxx library, similar to std::logic_error.
Definition: except.hxx:162
Reference to a field in a result set.
Definition: field.hxx:31
row_size_type col() const noexcept
Definition: field.hxx:255
result const & home() const noexcept
Definition: field.hxx:253
field_size_type size_type
Definition: field.hxx:33
result::size_type idx() const noexcept
Definition: field.hxx:254
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 set containing data returned by a query or command.
Definition: result.hxx:68
PQXX_PURE row_size_type columns() const noexcept
Number of columns in result.
Definition: result.cxx:477
result_size_type size_type
Definition: result.hxx:70
Reference to one row in a result.
Definition: row.hxx:43
bool operator!=(row const &rhs) const noexcept
Definition: row.hxx:65
row_size_type size_type
Definition: row.hxx:45
result::size_type rownumber() const noexcept
Row number, assuming this is a real row and not end()/rend().
Definition: row.hxx:105
result::size_type num() const
Definition: row.hxx:152
oid column_type(zview col_name) const
Return a column's type.
Definition: row.hxx:121
row_difference_type difference_type
Definition: row.hxx:46
result m_result
Result set of which this is one row.
Definition: row.hxx:214
result::size_type m_index
Row number.
Definition: row.hxx:221
std::tuple< TYPE... > as() const
Definition: row.hxx:181
row & operator=(row &&)=default
void check_size(size_type expected) const
Throw usage_error if row size is not expected.
Definition: row.hxx:194
size_type table_column(zview col_name) const
What column number in its table did this result column come from?
Definition: row.hxx:146
row & operator=(row const &)=default
void convert(Tuple &t) const
Convert entire row to tuple fields, without checking row size.
Definition: row.hxx:204
oid column_table(zview col_name) const
What table did this column come from?
Definition: row.hxx:130
Iterator for fields in a row. Use as row::const_iterator.
Definition: row.hxx:256
bool operator>(const_row_iterator const &i) const
Definition: row.hxx:335
const_row_iterator & operator=(const_row_iterator &&)=default
const_row_iterator(const_row_iterator const &)=default
bool operator==(const_row_iterator const &i) const
Definition: row.hxx:319
const_row_iterator(field const &F) noexcept
Definition: row.hxx:271
std::random_access_iterator_tag iterator_category
Definition: row.hxx:258
const_row_iterator operator-(difference_type) const
Definition: row.hxx:495
field const * pointer
Definition: row.hxx:260
const_row_iterator & operator--()
Definition: row.hxx:297
field const value_type
Definition: row.hxx:259
const_row_iterator()=default
const_row_iterator operator+(difference_type) const
Definition: row.hxx:480
const_row_iterator & operator=(const_row_iterator const &)=default
const_row_iterator & operator++()
Definition: row.hxx:291
reference operator*() const
Definition: row.hxx:280
row_size_type size_type
Definition: row.hxx:261
const_row_iterator & operator+=(difference_type i)
Definition: row.hxx:303
const_row_iterator & operator-=(difference_type i)
Definition: row.hxx:308
bool operator!=(const_row_iterator const &i) const
Definition: row.hxx:323
bool operator>=(const_row_iterator const &i) const
Definition: row.hxx:339
row_difference_type difference_type
Definition: row.hxx:262
pointer operator->() const
Definition: row.hxx:279
bool operator<=(const_row_iterator const &i) const
Definition: row.hxx:331
const_row_iterator(row const &t, row_size_type c) noexcept
Definition: row.hxx:268
bool operator<(const_row_iterator const &i) const
Definition: row.hxx:327
const_row_iterator(const_row_iterator &&)=default
Reverse iterator for a row. Use as row::const_reverse_iterator.
Definition: row.hxx:363
const_reverse_row_iterator & operator--()
Definition: row.hxx:408
bool operator!=(const_reverse_row_iterator const &rhs) const noexcept
Definition: row.hxx:455
const_reverse_row_iterator(const_reverse_row_iterator &&)=default
const_reverse_row_iterator operator+(difference_type i) const
Definition: row.hxx:430
const_reverse_row_iterator(super const &rhs) noexcept
Definition: row.hxx:377
bool operator>(const_reverse_row_iterator const &rhs) const
Definition: row.hxx:468
const_reverse_row_iterator()=default
const_reverse_row_iterator & operator-=(difference_type i)
Definition: row.hxx:419
bool operator>=(const_reverse_row_iterator const &rhs) const
Definition: row.hxx:472
difference_type operator-(const_reverse_row_iterator const &rhs) const
Definition: row.hxx:439
const_reverse_row_iterator operator-(difference_type i)
Definition: row.hxx:434
const_reverse_row_iterator & operator+=(difference_type i)
Definition: row.hxx:414
bool operator<=(const_reverse_row_iterator const &rhs) const
Definition: row.hxx:464
bool operator==(const_reverse_row_iterator const &rhs) const noexcept
Definition: row.hxx:450
const_reverse_row_iterator(const_reverse_row_iterator const &)=default
const_reverse_row_iterator operator++()
Definition: row.hxx:402
bool operator<(const_reverse_row_iterator const &rhs) const
Definition: row.hxx:460
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:38