Kea 2.7.6
|
RAII wrapper for PostgreSQL Result sets. More...
#include <pgsql_exchange.h>
Public Member Functions | |
PgSqlResult (PGresult *result) | |
Constructor. | |
~PgSqlResult () | |
Destructor. | |
void | colCheck (int col) const |
Determines if a column index is valid. | |
int | getCols () const |
Returns the number of columns in the result set. | |
std::string | getColumnLabel (const int col) const |
Fetches the name of the column in a result set. | |
int | getRows () const |
Returns the number of rows in the result set. | |
operator bool () const | |
Boolean Operator. | |
operator PGresult * () const | |
Conversion Operator. | |
void | rowCheck (int row) const |
Determines if a row index is valid. | |
void | rowColCheck (int row, int col) const |
Determines if both a row and column index are valid. | |
RAII wrapper for PostgreSQL Result sets.
When a Postgresql statement is executed, the results are returned in a pointer allocated structure, PGresult*. Data and status information are accessed via calls to functions such as PQgetvalue() which require the results pointer. In order to ensure this structure is freed, any invocation of Psql function which returns a PGresult* (e.g. PQexec, PQExecPrepared, ...) must save the result to an instance of this class. Example: {{{ PgSqlResult r(PQexec(conn_, "ROLLBACK")); }}}
This eliminates the need for an explicit release via, PQclear() and guarantees that the resources are released even if the an exception is thrown.
Definition at line 46 of file pgsql_exchange.h.
isc::db::PgSqlResult::PgSqlResult | ( | PGresult * | result | ) |
Constructor.
Store the pointer to the fetched result set. Set row and column counts for convenience.
result | pointer to the Postgresql client layer result If the value of is NULL, row and col values will be set to -1. This allows PgSqlResult to be passed into statement error checking. |
Definition at line 56 of file pgsql_connection.cc.
isc::db::PgSqlResult::~PgSqlResult | ( | ) |
void isc::db::PgSqlResult::colCheck | ( | int | col | ) | const |
Determines if a column index is valid.
col | index to range check |
DbOperationError | if the column index is out of range |
Definition at line 86 of file pgsql_connection.cc.
References isc_throw.
Referenced by getColumnLabel(), and rowColCheck().
|
inline |
Returns the number of columns in the result set.
Definition at line 70 of file pgsql_exchange.h.
Referenced by isc::db::PgSqlExchange::dumpRow().
std::string isc::db::PgSqlResult::getColumnLabel | ( | const int | col | ) | const |
Fetches the name of the column in a result set.
Returns the column name of the column from the result set. If the column index is out of range it will return the string "Unknown column:<index>"
col | index of the column name to fetch |
Definition at line 100 of file pgsql_connection.cc.
References colCheck().
Referenced by isc::db::PgSqlExchange::dumpRow(), and isc::db::PgSqlExchange::getColumnLabel().
|
inline |
Returns the number of rows in the result set.
Definition at line 65 of file pgsql_exchange.h.
|
inline |
Boolean Operator.
Allows testing the PgSqlResult object for emptiness: "if (result)"
Definition at line 119 of file pgsql_exchange.h.
|
inline |
Conversion Operator.
Allows the PgSqlResult object to be passed as the result set argument to PQxxxx functions.
Definition at line 112 of file pgsql_exchange.h.
void isc::db::PgSqlResult::rowCheck | ( | int | row | ) | const |
Determines if a row index is valid.
row | index to range check |
DbOperationError | if the row index is out of range |
Definition at line 72 of file pgsql_connection.cc.
References isc_throw.
Referenced by isc::db::PgSqlResultRowWorker::PgSqlResultRowWorker(), isc::db::PgSqlExchange::dumpRow(), and rowColCheck().
void isc::db::PgSqlResult::rowColCheck | ( | int | row, |
int | col ) const |
Determines if both a row and column index are valid.
row | index to range check |
col | index to range check |
DbOperationError | if either the row or column index is out of range |
Definition at line 94 of file pgsql_connection.cc.
References colCheck(), and rowCheck().
Referenced by isc::db::PgSqlExchange::getRawColumnValue(), and isc::db::PgSqlExchange::isColumnNull().