Kea  1.9.9-git
isc::db::PgSqlResult Class Reference

RAII wrapper for PostgreSQL Result sets. More...

#include <pgsql_connection.h>

+ Inheritance diagram for isc::db::PgSqlResult:

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

isc::db::PgSqlResult::PgSqlResult ( PGresult *  result)

Constructor.

Store the pointer to the result set to being fetched. Set row and column counts for convenience.

Parameters
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 ( )

Destructor.

Frees the result set

Definition at line 66 of file pgsql_connection.cc.

Member Function Documentation

void isc::db::PgSqlResult::colCheck ( int  col) const

Determines if a column index is valid.

Parameters
colindex to range check
Exceptions
DbOperationErrorif the column index is out of range

Definition at line 73 of file pgsql_connection.cc.

References isc_throw.

Referenced by getColumnLabel(), and rowColCheck().

int isc::db::PgSqlResult::getCols ( ) const
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>"

Parameters
colindex of the column name to fetch
Returns
string containing the name of the column This method is exception safe.

Definition at line 87 of file pgsql_connection.cc.

References colCheck().

Referenced by isc::db::PgSqlExchange::dumpRow(), and isc::db::PgSqlExchange::getColumnLabel().

+ Here is the call graph for this function:

int isc::db::PgSqlResult::getRows ( ) const
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().

isc::db::PgSqlResult::operator bool ( ) const
inline

Boolean Operator.

Allows testing the PgSqlResult object for emptiness: "if (result)"

Definition at line 159 of file pgsql_connection.h.

isc::db::PgSqlResult::operator PGresult * ( ) const
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.

Parameters
rowindex to range check
Exceptions
DbOperationErrorif 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.

Parameters
rowindex to range check
colindex to range check
Exceptions
DbOperationErrorif 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().

+ Here is the call graph for this function:


The documentation for this class was generated from the following files: