Kea
1.9.9-git
|
RAII wrapper for PostgreSQL Result sets. More...
#include <pgsql_connection.h>
Public Member Functions | |
PgSqlResult (PGresult *result) | |
Constructor. More... | |
~PgSqlResult () | |
Destructor. More... | |
void | colCheck (int col) const |
Determines if a column index is valid. More... | |
int | getCols () const |
Returns the number of columns in the result set. More... | |
std::string | getColumnLabel (const int col) const |
Fetches the name of the column in a result set. More... | |
int | getRows () const |
Returns the number of rows in the result set. More... | |
operator bool () const | |
Boolean Operator. More... | |
operator PGresult * () const | |
Conversion Operator. More... | |
void | rowCheck (int row) const |
Determines if a row index is valid. More... | |
void | rowColCheck (int row, int col) const |
Determines if both a row and column index are valid. More... | |
RAII wrapper for PostgreSQL Result sets.
When a Postgresql statement is executed, the results are returned in 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 and class. Examples: {{{ 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 86 of file pgsql_connection.h.
isc::db::PgSqlResult::PgSqlResult | ( | PGresult * | result | ) |
Constructor.
Store the pointer to the result set to being fetched. 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 43 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 73 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 110 of file pgsql_connection.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 87 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 105 of file pgsql_connection.h.
Referenced by isc::dhcp::PgSqlHostDataSourceImpl::getHostCollection().
|
inline |
Boolean Operator.
Allows testing the PgSqlResult object for emptiness: "if (result)"
Definition at line 159 of file pgsql_connection.h.
|
inline |
Conversion Operator.
Allows the PgSqlResult object to be passed as the result set argument to PQxxxx functions.
Definition at line 152 of file pgsql_connection.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 59 of file pgsql_connection.cc.
References isc_throw.
Referenced by 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 81 of file pgsql_connection.cc.
References colCheck(), and rowCheck().
Referenced by isc::db::PgSqlExchange::getRawColumnValue(), and isc::db::PgSqlExchange::isColumnNull().