13 #ifndef PQXX_RESULT_HXX
14 #define PQXX_RESULT_HXX
16 #if !defined(PQXX_HEADER_PRE)
17 # error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
43 class result_connection;
44 class result_creation;
45 class result_field_ref;
46 class result_pipeline;
48 class result_sql_cursor;
156 [[nodiscard]]
bool operator==(
result const &rhs) const noexcept
158 return rhs.m_data == m_data;
181 template<
typename... TYPE>
auto iter()
const;
183 [[nodiscard]]
PQXX_PURE const_reverse_iterator rbegin() const noexcept;
184 [[nodiscard]]
PQXX_PURE const_reverse_iterator crbegin() const noexcept;
185 [[nodiscard]]
PQXX_PURE const_reverse_iterator rend() const noexcept;
186 [[nodiscard]]
PQXX_PURE const_reverse_iterator crend() const noexcept;
188 [[nodiscard]]
PQXX_PURE const_iterator begin() const noexcept;
189 [[nodiscard]]
PQXX_PURE const_iterator cbegin() const noexcept;
190 [[nodiscard]]
PQXX_PURE inline const_iterator end() const noexcept;
191 [[nodiscard]]
PQXX_PURE inline const_iterator cend() const noexcept;
196 [[nodiscard]]
PQXX_PURE size_type size() const noexcept;
197 [[nodiscard]]
PQXX_PURE bool empty() const noexcept;
209 void swap(
result &) noexcept;
221 #if defined(PQXX_HAVE_MULTIDIM)
224 operator[](size_type row_num,
row_size_type col_num)
const noexcept;
228 [[nodiscard]]
row_ref at(size_type,
sl = sl::current())
const;
265 column_number(
zview name,
sl =
sl::current()) const;
289 [[nodiscard]]
int column_type_modifier(
row_size_type number) const noexcept;
304 [[nodiscard]]
oid column_type(
zview col_name,
sl loc =
sl::current())
const
306 return column_type(column_number(col_name, loc));
324 return column_table(column_number(col_name, loc), loc);
343 return table_column(column_number(col_name), loc);
348 [[nodiscard]]
PQXX_PURE std::string
const &query() const & noexcept;
364 [[nodiscard]]
PQXX_PURE size_type affected_rows() const;
404 template<typename CALLABLE>
405 inline
void for_each(CALLABLE &&func,
sl =
sl::current()) const;
415 auto const sz{size()};
419 if (not m_query or m_query->empty())
421 std::format(
"Expected {} row(s) from query, got {}.", n, sz), loc};
425 "Expected {} row(s) from query '{}', got {}.", n, *m_query, sz),
438 row one_row(
sl = sl::current())
const;
446 row_ref one_row_ref(
sl = sl::current())
const;
454 std::optional<row> opt_row(
sl = sl::current())
const;
462 std::optional<row_ref> opt_row_ref(
sl = sl::current())
const;
478 auto const actual{columns()};
482 if (not m_query or m_query->empty())
485 "Expected {} column(s) from query, got {}.", cols, actual),
490 "Expected {} column(s) from query '{}', got {}.", cols, *m_query,
504 field one_field(
sl = sl::current())
const;
523 using data_pointer = std::shared_ptr<internal::pq::PGresult const>;
526 void check_one_row(
sl loc)
const
528 auto const sz{size()};
531 if (not m_query or m_query->empty())
532 throw unexpected_rows{
533 std::format(
"Expected 1 row from query, got {}.", sz), loc};
535 throw unexpected_rows{
536 std::format(
"Expected 1 row from query '{}', got {}.", *m_query, sz),
545 PQXX_PURE [[nodiscard]] std::shared_ptr<std::string const>
546 query_ptr() const noexcept
553 std::shared_ptr<std::string const> m_query;
560 std::shared_ptr<pqxx::internal::notice_waiters> m_notice_waiters;
564 static std::string
const s_empty_string;
576 std::shared_ptr<internal::pq::PGresult>
const &rhs,
577 std::shared_ptr<std::string>
const &query,
578 std::shared_ptr<pqxx::internal::notice_waiters>
const &waiters,
581 PQXX_PRIVATE void check_status(std::string_view desc,
sl loc)
const;
584 friend class pqxx::internal::gate::result_row;
585 bool operator!() const noexcept {
return m_data.get() ==
nullptr; }
587 operator bool() const noexcept {
return m_data.get() !=
nullptr; }
590 throw_sql_error(std::string
const &Err, std::string
const &Query,
sl)
const;
595 PQXX_PURE [[nodiscard]]
char const *cmd_status() const noexcept;
Iterator for rows in a result. Use as result::const_iterator.
Definition: result_iterator.hxx:35
Reverse iterator for result. Use as result::const_reverse_iterator.
Definition: result_iterator.hxx:173
Lightweight reference to a field in a result set.
Definition: field.hxx:52
Reference to a field in a result set.
Definition: field.hxx:309
Definition: result-connection.hxx:9
Definition: result-creation.hxx:9
Definition: result-field_ref.hxx:9
Definition: result-pipeline.hxx:9
Definition: result-sql_cursor.hxx:6
Result set containing data returned by a query or command.
Definition: result.hxx:101
encoding_group get_encoding_group() const noexcept
Retrieve encoding group for this result's client encoding.
Definition: result.hxx:517
result_size_type size_type
Definition: result.hxx:103
bool operator!=(result const &rhs) const noexcept
Compare two results for inequality.
Definition: result.hxx:161
result const & no_rows(sl loc=sl::current()) const
Expect that result contains no rows. Return result for convenience.
Definition: result.hxx:465
void clear() noexcept
Let go of the result's data.
Definition: result.hxx:242
row_size_type table_column(zview col_name, sl loc=sl::current()) const
What column in its table did this column come from?
Definition: result.hxx:341
result_difference_type difference_type
Definition: result.hxx:104
result const & expect_columns(row_size_type cols, sl loc=sl::current()) const
Expect that result consists of exactly cols columns.
Definition: result.hxx:476
result() noexcept=default
oid column_table(zview col_name, sl loc=sl::current()) const
What table did this column come from?
Definition: result.hxx:322
Lightweight reference to one row in a result.
Definition: row.hxx:57
Reference to one row in a result.
Definition: row.hxx:415
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:55
Query returned an unexpected number of rows.
Definition: except.hxx:664
Error in usage of libpqxx library, similar to std::logic_error.
Definition: except.hxx:580
Definition: connection.hxx:94
void PGresult
Placeholder for libpq's result type.
Definition: types.hxx:431
Private namespace for libpqxx's internal use; do not access.
Definition: connection.cxx:333
PQXX_LIBEXPORT void clear_result(pq::PGresult const *) noexcept
C++ wrapper for libpq's PQclear.
Definition: result.cxx:79
The home of all libpqxx classes, functions, templates, etc.
Definition: array.cxx:26
int row_size_type
Number of fields in a row of database data.
Definition: types.hxx:83
std::source_location sl
Convenience alias for std::source_location. It's just too long.
Definition: types.hxx:38
std::size_t field_size_type
Number of bytes in a field of database data.
Definition: types.hxx:89
int result_difference_type
Difference between result sizes.
Definition: types.hxx:80
encoding_group
Definition: encoding_group.hxx:40
@ unknown
Default: indeterminate encoding. All we know is it supports ASCII.
int result_size_type
Number of rows in a result set.
Definition: types.hxx:77
unsigned int oid
PostgreSQL database row identifier.
Definition: types.hxx:73
constexpr bool operator==(char const lhs[], pqxx::zview rhs) noexcept
Disambiguating comparison operator: leave it to std::string_view.
Definition: zview.hxx:203
format
Format code: is data text or binary?
Definition: types.hxx:121
Various callbacks waiting for a notice to come in.
Definition: result.hxx:57
std::function< void(zview)> notice_handler
Definition: result.hxx:59
notice_waiters(notice_waiters &&)=delete
notice_waiters(notice_waiters const &)=delete
notice_waiters & operator=(notice_waiters const &)=delete
~notice_waiters()=default
std::list< errorhandler * > errorhandlers
Definition: result.hxx:60
notice_waiters & operator=(notice_waiters &&)=delete