result.hxx
#ifndef PQXX_H_RESULT
#define PQXX_H_RESULT
#include "pqxx/compiler-public.hxx"
#include "pqxx/compiler-internal-pre.hxx"
#include <ios>
#include <memory>
#include <stdexcept>
#include "pqxx/except.hxx"
#include "pqxx/types.hxx"
#include "pqxx/util.hxx"
#include "pqxx/internal/encodings.hxx"
// Methods tested in eg. test module test01 are marked with "//[t01]".
namespace pqxx
{
namespace internal
{
PQXX_LIBEXPORT void clear_result(const pq::PGresult *);
namespace gate
{
class result_connection;
class result_creation;
class result_row;
class result_sql_cursor;
} // namespace internal::gate
} // namespace internal
class PQXX_LIBEXPORT result
{
public:
using size_type = result_size_type;
using difference_type = result_difference_type;
using reference = row;
using const_iterator = const_result_iterator;
using pointer = const_iterator;
using iterator = const_iterator;
using const_reverse_iterator = const_reverse_result_iterator;
using reverse_iterator = const_reverse_iterator;
result() noexcept : //[t03]
m_data(make_data_pointer()),
m_query(),
m_encoding(internal::encoding_group::MONOBYTE)
{}
result(const result &rhs) noexcept =default; //[t01]
result &operator=(const result &rhs) noexcept =default; //[t10]
bool operator==(const result &) const noexcept; //[t70]
bool operator!=(const result &rhs) const noexcept //[t70]
{ return not operator==(rhs); }
const_reverse_iterator rbegin() const; //[t75]
const_reverse_iterator crbegin() const;
const_reverse_iterator rend() const; //[t75]
const_reverse_iterator crend() const;
const_iterator begin() const noexcept; //[t01]
const_iterator cbegin() const noexcept;
inline const_iterator end() const noexcept; //[t01]
inline const_iterator cend() const noexcept;
reference front() const noexcept; //[t74]
reference back() const noexcept; //[t75]
PQXX_PURE size_type size() const noexcept; //[t02]
PQXX_PURE bool empty() const noexcept; //[t11]
size_type capacity() const noexcept { return size(); } //[t20]
void swap(result &) noexcept; //[t77]
const row operator[](size_type i) const noexcept; //[t02]
const row at(size_type) const; //[t10]
void clear() noexcept { m_data.reset(); m_query = nullptr; } //[t20]
PQXX_PURE row_size_type columns() const noexcept; //[t11]
row_size_type column_number(const char ColName[]) const; //[t11]
row_size_type column_number(const std::string &Name) const //[t11]
{return column_number(Name.c_str());}
const char *column_name(row_size_type Number) const; //[t11]
oid column_type(row_size_type ColNum) const; //[t07]
oid column_type(int ColNum) const //[t07]
{ return column_type(row_size_type(ColNum)); }
oid column_type(const std::string &ColName) const //[t07]
{ return column_type(column_number(ColName)); }
oid column_type(const char ColName[]) const //[t07]
{ return column_type(column_number(ColName)); }
oid column_table(row_size_type ColNum) const; //[t02]
oid column_table(int ColNum) const //[t02]
{ return column_table(row_size_type(ColNum)); }
oid column_table(const std::string &ColName) const //[t02]
{ return column_table(column_number(ColName)); }
row_size_type table_column(row_size_type ColNum) const; //[t93]
row_size_type table_column(int ColNum) const //[t93]
{ return table_column(row_size_type(ColNum)); }
row_size_type table_column(const std::string &ColName) const //[t93]
{ return table_column(column_number(ColName)); }
PQXX_PURE const std::string &query() const noexcept; //[t70]
PQXX_PURE oid inserted_oid() const; //[t13]
PQXX_PURE size_type affected_rows() const; //[t07]
private:
using data_pointer = std::shared_ptr<const internal::pq::PGresult>;
data_pointer m_data;
static data_pointer make_data_pointer(
const internal::pq::PGresult *res=nullptr)
{ return data_pointer{res, internal::clear_result}; }
std::shared_ptr<std::string> m_query;
internal::encoding_group m_encoding;
static const std::string s_empty_string;
friend class pqxx::field;
PQXX_PURE const char *GetValue(size_type Row, row_size_type Col) const;
PQXX_PURE bool get_is_null(size_type Row, row_size_type Col) const;
PQXX_PURE field_size_type get_length(
size_type,
row_size_type) const noexcept;
friend class pqxx::internal::gate::result_creation;
result(
internal::pq::PGresult *rhs,
const std::string &Query,
internal::encoding_group enc);
PQXX_PRIVATE void check_status() const;
friend class pqxx::internal::gate::result_connection;
friend class pqxx::internal::gate::result_row;
bool operator!() const noexcept { return not m_data.get(); }
operator bool() const noexcept { return m_data.get() != nullptr; }
[[noreturn]] PQXX_PRIVATE void ThrowSQLError(
const std::string &Err,
const std::string &Query) const;
PQXX_PRIVATE PQXX_PURE int errorposition() const;
PQXX_PRIVATE std::string StatusError() const;
friend class pqxx::internal::gate::result_sql_cursor;
PQXX_PURE const char *cmd_status() const noexcept;
};
} // namespace pqxx
#include "pqxx/compiler-internal-post.hxx"
#endif
pqxx::result::operator!=
bool operator!=(const result &rhs) const noexcept
Definition: result.hxx:95
pqxx::result::size
PQXX_PURE size_type size() const noexcept
Definition: result.cxx:94
pqxx::result::operator[]
const row operator[](size_type i) const noexcept
Definition: result.cxx:125
pqxx::field::size_type
field_size_type size_type
Definition: field.hxx:52
pqxx::result::column_type
oid column_type(int ColNum) const
Type of given column.
Definition: result.hxx:143
pqxx::result::table_column
row_size_type table_column(row_size_type ColNum) const
What column in its table did this column come from?
Definition: result.cxx:350
pqxx::result::table_column
row_size_type table_column(const std::string &ColName) const
What column in its table did this column come from?
Definition: result.hxx:173
pqxx::const_reverse_result_iterator
Reverse iterator for result. Use as result::const_reverse_iterator.
Definition: result_iterator.hxx:120
pqxx::const_reverse_result_iterator::base
PQXX_PURE const_result_iterator base() const noexcept
Definition: result.cxx:425
pqxx::const_result_iterator
Iterator for rows in a result. Use as result::const_iterator.
Definition: result_iterator.hxx:35
pqxx::const_reverse_result_iterator::operator--
const_reverse_result_iterator & operator--()
Definition: result_iterator.hxx:159
pqxx::result::difference_type
result_difference_type difference_type
Definition: result.hxx:73
pqxx::result::rbegin
const_reverse_iterator rbegin() const
Definition: result.cxx:58
pqxx::internal::clear_result
void clear_result(const pq::PGresult *)
C++ wrapper for libpq's PQclear.
Definition: result.cxx:30
pqxx::const_result_iterator::operator--
const_result_iterator & operator--()
Definition: result_iterator.hxx:74
pqxx::result
Result set containing data returned by a query or command.
Definition: result.hxx:69
pqxx::result_difference_type
signed long result_difference_type
Difference between result sizes.
Definition: types.hxx:21
pqxx::result::column_type
oid column_type(const char ColName[]) const
Type of given column.
Definition: result.hxx:151
pqxx::row_size_type
unsigned int row_size_type
Number of fields in a row of database data.
Definition: types.hxx:24
pqxx::from_string
void from_string(const field &F, T &Obj)
Convert a field's string contents to another type.
Definition: field.hxx:365
pqxx::result::back
reference back() const noexcept
Definition: result.cxx:112
pqxx::result::result
result() noexcept
Definition: result.hxx:81
pqxx::const_reverse_result_iterator::operator++
const_reverse_result_iterator & operator++()
Definition: result_iterator.hxx:156
pqxx::result::size_type
result_size_type size_type
Definition: result.hxx:72
pqxx::result::table_column
row_size_type table_column(int ColNum) const
What column in its table did this column come from?
Definition: result.hxx:169
pqxx::field
Reference to a field in a result set.
Definition: field.hxx:49
pqxx::result::empty
PQXX_PURE bool empty() const noexcept
Definition: result.cxx:100
pqxx::result::crbegin
const_reverse_iterator crbegin() const
Definition: result.cxx:64
pqxx::result::column_table
oid column_table(const std::string &ColName) const
What table did this column come from?
Definition: result.hxx:162
pqxx::result::query
const PQXX_PURE std::string & query() const noexcept
Query that produced this result, if available (empty string otherwise)
Definition: result.cxx:277
pqxx::result::operator==
bool operator==(const result &) const noexcept
Definition: result.cxx:47
pqxx::result::crend
const_reverse_iterator crend() const
Definition: result.cxx:76
pqxx::result::rend
const_reverse_iterator rend() const
Definition: result.cxx:70
pqxx::result::column_name
const char * column_name(row_size_type Number) const
Name of column with this number (throws exception if it doesn't exist)
Definition: result.cxx:384
pqxx::oid_none
constexpr oid oid_none
The "null" oid.
Definition: util.hxx:77
pqxx::result::at
const row at(size_type) const
Definition: result.cxx:131
pqxx::result::affected_rows
PQXX_PURE size_type affected_rows() const
If command was INSERT, UPDATE, or DELETE: number of affected rows.
Definition: result.cxx:292
pqxx::result_size_type
unsigned long result_size_type
Number of rows in a result set.
Definition: types.hxx:18
pqxx::field::size
size_type size() const noexcept
Return number of bytes taken up by the field's value.
Definition: field.cxx:74
pqxx::result::front
reference front() const noexcept
Definition: result.cxx:106
pqxx::result::inserted_oid
PQXX_PURE oid inserted_oid() const
If command was INSERT of 1 row, return oid of inserted row.
Definition: result.cxx:283
pqxx::result::column_table
oid column_table(row_size_type ColNum) const
What table did this column come from?
Definition: result.cxx:334
pqxx::result::column_type
oid column_type(row_size_type ColNum) const
Type of given column.
Definition: result.cxx:323
pqxx::result::clear
void clear() noexcept
Definition: result.hxx:121
pqxx::argument_error
Invalid argument passed to libpqxx, similar to std::invalid_argument.
Definition: except.hxx:229
pqxx::result::begin
const_iterator begin() const noexcept
Definition: result.cxx:82
pqxx::to_string
std::string to_string(const field &Obj)
Convert a field to a string.
Definition: result.cxx:451
pqxx::result::columns
PQXX_PURE row_size_type columns() const noexcept
Number of columns in result.
Definition: result.cxx:399
pqxx::result::cbegin
const_iterator cbegin() const noexcept
Definition: result.cxx:88
pqxx::field_size_type
std::size_t field_size_type
Number of bytes in a field of database data.
Definition: types.hxx:30
pqxx::result::swap
void swap(result &) noexcept
Definition: result.cxx:118
pqxx::range_error
Something is out of range, similar to std::out_of_range.
Definition: except.hxx:251
pqxx
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
pqxx::row
Reference to one row in a result.
Definition: row.hxx:40
pqxx::usage_error
Error in usage of libpqxx library, similar to std::logic_error.
Definition: except.hxx:218
pqxx::const_result_iterator::operator++
const_result_iterator & operator++()
Definition: result_iterator.hxx:72
pqxx::result::column_type
oid column_type(const std::string &ColName) const
Type of given column.
Definition: result.hxx:147
pqxx::row::size_type
row_size_type size_type
Definition: row.hxx:43
pqxx::field::c_str
const char * c_str() const
Read as plain C string.
Definition: field.cxx:62
pqxx::result::column_table
oid column_table(int ColNum) const
What table did this column come from?
Definition: result.hxx:158