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"
28 template<
typename... T>
class result_iter;
46 class 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;
87 [[nodiscard]]
reference back()
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
121 [[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{});
204 check_size(std::tuple_size_v<TUPLE>);
205 using seq = std::make_index_sequence<std::tuple_size_v<TUPLE>>;
206 return get_tuple<TUPLE>(seq{});
209 [[deprecated(
"Swap iterators, not rows.")]]
void swap(
row &) noexcept;
222 [[deprecated("Row slicing is going away. File a bug if you need it.")]]
row
223 slice(size_type sbegin, size_type send) const;
226 [[nodiscard, deprecated("Row slicing is going away.")]] PQXX_PURE
bool
227 empty() const noexcept;
235 void check_size(size_type expected)
const
237 if (size() != expected)
239 "Tried to extract ", expected,
" field(s) from a row of ", size(),
245 template<
typename Tuple>
void convert(Tuple &t)
const
247 extract_fields(t, std::make_index_sequence<std::tuple_size_v<Tuple>>{});
260 result::size_type m_index = 0;
264 size_type m_begin = 0;
269 template<
typename Tuple, std::size_t... indexes>
270 void extract_fields(Tuple &t, std::index_sequence<indexes...>)
const
272 (extract_value<Tuple, indexes>(t), ...);
275 template<
typename Tuple, std::
size_t index>
276 void extract_value(Tuple &t)
const;
279 template<
typename TUPLE, std::size_t... indexes>
280 auto get_tuple(std::index_sequence<indexes...>)
const
282 return std::make_tuple(get_field<TUPLE, indexes>()...);
286 template<
typename TUPLE, std::
size_t index>
auto get_field()
const
288 return (*
this)[index].as<std::tuple_element_t<index, TUPLE>>();
297 using iterator_category = std::random_access_iterator_tag;
298 using value_type =
field const;
299 using pointer =
field const *;
304 #include "pqxx/internal/ignore-deprecated-pre.hxx"
306 #include "pqxx/internal/ignore-deprecated-post.hxx"
308 field{t.m_result, t.m_index, c}
310 const_row_iterator(field
const &F) noexcept : field{F} {}
311 const_row_iterator(const_row_iterator
const &) noexcept = default;
312 const_row_iterator(const_row_iterator &&) noexcept = default;
318 [[nodiscard]] constexpr pointer operator->() const noexcept {
return this; }
319 [[nodiscard]] reference operator*() const noexcept {
return {*
this}; }
326 const_row_iterator &operator=(const_row_iterator
const &) noexcept = default;
327 const_row_iterator &operator=(const_row_iterator &&) noexcept = default;
329 const_row_iterator operator++(
int) & noexcept;
330 const_row_iterator &operator++() noexcept
335 const_row_iterator operator--(
int) & noexcept;
336 const_row_iterator &operator--() noexcept
342 const_row_iterator &operator+=(difference_type i) noexcept
344 m_col = size_type(difference_type(m_col) + i);
347 const_row_iterator &operator-=(difference_type i) noexcept
349 m_col = size_type(difference_type(m_col) - i);
358 [[nodiscard]] constexpr
bool
359 operator==(const_row_iterator
const &i)
const noexcept
361 return col() == i.col();
363 [[nodiscard]] constexpr
bool
364 operator!=(const_row_iterator
const &i)
const noexcept
366 return col() != i.col();
368 [[nodiscard]] constexpr
bool
369 operator<(const_row_iterator
const &i)
const noexcept
371 return col() < i.col();
373 [[nodiscard]] constexpr
bool
374 operator<=(const_row_iterator
const &i)
const noexcept
376 return col() <= i.col();
378 [[nodiscard]] constexpr
bool
379 operator>(const_row_iterator
const &i)
const noexcept
381 return col() > i.col();
383 [[nodiscard]] constexpr
bool
384 operator>=(const_row_iterator
const &i)
const noexcept
386 return col() >= i.col();
394 [[nodiscard]]
inline const_row_iterator
395 operator+(difference_type) const noexcept;
397 friend const_row_iterator
398 operator+(difference_type, const_row_iterator const &) noexcept;
400 [[nodiscard]] inline const_row_iterator
401 operator-(difference_type) const noexcept;
402 [[nodiscard]] inline difference_type
403 operator-(const_row_iterator const &) const noexcept;
405 [[nodiscard]] inline field operator[](difference_type offset) const noexcept
407 return *(*
this + offset);
419 using iterator_type::difference_type;
420 using iterator_type::iterator_category;
421 using iterator_type::pointer;
422 using value_type = iterator_type::value_type;
442 using iterator_type::operator->;
443 using iterator_type::operator*;
453 iterator_type::operator=(r);
458 iterator_type::operator--();
464 iterator_type::operator++();
470 iterator_type::operator-=(i);
475 iterator_type::operator+=(i);
485 operator+(difference_type i)
const noexcept
490 operator-(difference_type i) noexcept
494 [[nodiscard]] difference_type
497 return rhs.const_row_iterator::operator-(*this);
499 [[nodiscard]]
inline field operator[](difference_type offset)
const noexcept
501 return *(*
this + offset);
512 return iterator_type::operator==(rhs);
517 return !operator==(rhs);
520 [[nodiscard]] constexpr
bool
523 return iterator_type::operator>(rhs);
525 [[nodiscard]] constexpr
bool
528 return iterator_type::operator>=(rhs);
530 [[nodiscard]] constexpr
bool
533 return iterator_type::operator<(rhs);
535 [[nodiscard]] constexpr
bool
538 return iterator_type::operator<=(rhs);
545 const_row_iterator::operator+(difference_type o)
const noexcept
549 row{home(), idx(), home().columns()},
550 size_type(difference_type(col()) + o)};
553 inline const_row_iterator operator+(
554 const_row_iterator::difference_type o, const_row_iterator
const &i) noexcept
559 inline const_row_iterator
560 const_row_iterator::operator-(difference_type o)
const noexcept
564 row{home(), idx(), home().columns()},
565 size_type(difference_type(col()) - o)};
568 inline const_row_iterator::difference_type
569 const_row_iterator::operator-(const_row_iterator
const &i)
const noexcept
571 return difference_type(num() - i.num());
575 template<
typename Tuple, std::
size_t index>
576 inline void row::extract_value(Tuple &t)
const
578 using field_type = strip_t<decltype(std::get<index>(t))>;
580 std::get<index>(t) = from_string<field_type>(f);
std::string concat(TYPE...item)
Efficiently combine a bunch of items into one big string.
Definition: concat.hxx:31
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:37
Error in usage of libpqxx library, similar to std::logic_error.
Definition: except.hxx:248
Internal items for libpqxx' own use. Do not use these yourself.
Definition: encodings.cxx:32
Reference to one row in a result.
Definition: row.hxx:46
const_row_iterator(row const &t, row_size_type c) noexcept
End a code block started by "ignore-deprecated-pre.hxx".
Definition: row.hxx:307
TUPLE as_tuple() const
Convert to a given tuple of values,.
Definition: row.hxx:202
constexpr result::size_type rownumber() const noexcept
Row number, assuming this is a real row and not end()/rend().
Definition: row.hxx:112
void to(Tuple &t) const
Extract entire row's values into a tuple.
Definition: row.hxx:173
int row_size_type
Number of fields in a row of database data.
Definition: types.hxx:34
Result set containing data returned by a query or command.
Definition: result.hxx:91
int result_size_type
Number of rows in a result set.
Definition: types.hxx:28
oid column_type(zview col_name) const
Return a column's type.
Definition: row.hxx:128
oid column_table(zview col_name) const
What table did this column come from?
Definition: row.hxx:137
result m_result
Result set of which this is one row.
Definition: row.hxx:253
The home of all libpqxx classes, functions, templates, etc.
Definition: array.cxx:26
Reference to a field in a result set.
Definition: field.hxx:34
unsigned int oid
PostgreSQL database row identifier.
Definition: libpq-forward.hxx:33
int row_difference_type
Difference between row sizes.
Definition: types.hxx:37
Reverse iterator for a row. Use as row::const_reverse_iterator.
Definition: row.hxx:414
Iterator for fields in a row. Use as row::const_iterator.
Definition: row.hxx:294
void convert(Tuple &t) const
Convert entire row to tuple fields, without checking row size.
Definition: row.hxx:245
std::tuple< TYPE... > as() const
Extract entire row's values into a tuple.
Definition: row.hxx:188
result::size_type m_index
Row number.
Definition: row.hxx:260
Iterator for looped unpacking of a result.
Definition: result_iter.hxx:26
size_type table_column(zview col_name) const
What column number in its table did this result column come from?
Definition: row.hxx:153