Kea 2.7.5
|
Base class for marshalling data to and from PostgreSQL. More...
#include <pgsql_exchange.h>
Public Member Functions | |
PgSqlExchange (const size_t num_columns=0) | |
Constructor. | |
virtual | ~PgSqlExchange () |
Destructor. | |
Static Public Member Functions | |
static void | convertFromBytea (const PgSqlResult &r, const int row, const size_t col, std::vector< uint8_t > &value) |
Converts a column in a row in a result set to a binary bytes. | |
static void | convertFromBytea (const PgSqlResult &r, const int row, const size_t col, uint8_t *buffer, const size_t buffer_size, size_t &bytes_converted) |
Converts a column in a row in a result set to a binary bytes. | |
static time_t | convertFromDatabaseTime (const std::string &db_time_val) |
Converts time stamp from the database to a time_t. | |
static void | convertFromDatabaseTime (const std::string &db_time_val, boost::posix_time::ptime &conv_time) |
Converts time stamp from the database to a boost::posix::ptime. | |
static std::string | convertLocalToDatabaseTime (const time_t input_time) |
Converts local time_t value to a text representation in local time. | |
static std::string | convertToDatabaseTime (const time_t cltt, const uint32_t valid_lifetime) |
Converts lease expiration time to a text representation in local time. | |
static std::string | convertToDatabaseTime (const time_t input_time) |
Converts UTC time_t value to a text representation in local time. | |
static std::string | dumpRow (const PgSqlResult &r, int row) |
Diagnostic tool which dumps the Result row contents as a string. | |
static std::string | getColumnLabel (const PgSqlResult &r, const size_t col) |
Fetches the name of the column in a result set. | |
static void | getColumnValue (const PgSqlResult &r, const int row, const size_t col, bool &value) |
Fetches boolean text ('t' or 'f') as a bool. | |
static void | getColumnValue (const PgSqlResult &r, const int row, const size_t col, boost::posix_time::ptime &value) |
Fetches a timestamp column as a ptime. | |
static void | getColumnValue (const PgSqlResult &r, const int row, const size_t col, data::ElementPtr &value) |
Fetches a JSON column as an ElementPtr. | |
static void | getColumnValue (const PgSqlResult &r, const int row, const size_t col, std::string &value) |
Fetches text column value as a string. | |
template<typename T > | |
static void | getColumnValue (const PgSqlResult &r, const int row, const size_t col, T &value) |
Fetches a text column as the given value type. | |
static void | getColumnValue (const PgSqlResult &r, const int row, const size_t col, uint8_t &value) |
Fetches an integer text column as a uint8_t. | |
static isc::asiolink::IOAddress | getInetValue4 (const PgSqlResult &r, const int row, const size_t col) |
Converts a column in a row in a result set into IPv4 address. | |
static isc::asiolink::IOAddress | getInetValue6 (const PgSqlResult &r, const int row, const size_t col) |
Converts a column in a row in a result set into IPv6 address. | |
static isc::asiolink::IOAddress | getIPv6Value (const PgSqlResult &r, const int row, const size_t col) |
Converts a column in a row in a result set into IPv6 address. | |
static const char * | getRawColumnValue (const PgSqlResult &r, const int row, const size_t col) |
Gets a pointer to the raw column value in a result set row. | |
static isc::util::Triplet< uint32_t > | getTripletValue (const PgSqlResult &r, const int row, const size_t col) |
Fetches a uint32_t value into a Triplet using a single column value. | |
static isc::util::Triplet< uint32_t > | getTripletValue (const PgSqlResult &r, const int row, const size_t def_col, const size_t min_col, const size_t max_col) |
Fetches a uint32_t value into a Triplet using a three column values: default, minimum, and maximum. | |
static bool | isColumnNull (const PgSqlResult &r, const int row, const size_t col) |
Returns true if a column within a row is null. | |
Protected Attributes | |
std::vector< std::string > | columns_ |
Stores text labels for columns, currently only used for logging and errors. | |
Base class for marshalling data to and from PostgreSQL.
Provides the common functionality to set up binding information between application objects in the program and their representation in the database, and for retrieving column values from rows of a result set.
Definition at line 517 of file pgsql_exchange.h.
|
inline |
Constructor.
Definition at line 520 of file pgsql_exchange.h.
|
inlinevirtual |
Destructor.
Definition at line 523 of file pgsql_exchange.h.
|
static |
Converts a column in a row in a result set to a binary bytes.
Method is used to convert columns stored as BYTEA into a vector of binary bytes, (uint8_t). It uses PQunescapeBytea to do the conversion.
r | the result set containing the query results | |
row | the row number within the result set | |
col | the column number within the row | |
[out] | value | vector to receive the converted bytes value |
DbOperationError | if the value cannot be fetched or is invalid. |
Definition at line 562 of file pgsql_exchange.cc.
References getColumnLabel(), getRawColumnValue(), and isc_throw.
|
static |
Converts a column in a row in a result set to a binary bytes.
Method is used to convert columns stored as BYTEA into a buffer of binary bytes, (uint8_t). It uses PQunescapeBytea to do the conversion.
r | the result set containing the query results | |
row | the row number within the result set | |
col | the column number within the row | |
[out] | buffer | pre-allocated buffer to which the converted bytes will be stored. |
buffer_size | size of the output buffer | |
[out] | bytes_converted | number of bytes converted |
DbOperationError | if the value cannot be fetched or is invalid. |
Definition at line 530 of file pgsql_exchange.cc.
References getColumnLabel(), getRawColumnValue(), and isc_throw.
Referenced by isc::db::PgSqlResultRowWorker::getBytes().
|
static |
Converts time stamp from the database to a time_t.
We're fetching timestamps as an integer string of seconds since the epoch. This method converts such a string to a time_t.
db_time_val | timestamp to be converted. This value is expected to be the number of seconds since the epoch expressed as base-10 integer string. |
Definition at line 385 of file pgsql_exchange.cc.
References isc_throw.
Referenced by convertFromDatabaseTime(), and getColumnValue().
|
static |
Converts time stamp from the database to a boost::posix::ptime.
We're fetching timestamps as an integer string of seconds since the epoch. This method converts such a string to a boost::posix_time::ptime.
db_time_val | timestamp to be converted. This value is expected to be the number of seconds since the epoch expressed as base-10 integer string. | |
[out] | conv_time | resulting time as a ptime (UTC) |
Definition at line 398 of file pgsql_exchange.cc.
References convertFromDatabaseTime().
|
static |
Converts local time_t value to a text representation in local time.
input_time | A time_t value representing time. |
Definition at line 350 of file pgsql_exchange.cc.
Referenced by isc::db::PsqlBindArray::addTimestamp(), and isc::db::PsqlBindArray::addTimestamp().
|
static |
Converts lease expiration time to a text representation in local time.
The expiration time is calculated as a sum of the cltt (client last transmit time) and the valid lifetime.
The format of the output string is "%Y-%m-%d %H:%M:%S". Database table columns using this value should be typed as TIMESTAMP WITH TIME ZONE. For such columns PostgreSQL assumes input strings without timezones should be treated as in local time and are converted to UTC when stored. Likewise, these columns are automatically adjusted upon retrieval unless fetched via "extract(epoch from <column>))".
Unless we start using binary input, timestamp columns must be input as date/time strings.
cltt | Client last transmit time |
valid_lifetime | Valid lifetime |
isc::BadValue | if the sum of the calculated expiration time is greater than the value of DataSource::MAX_DB_TIME . |
Definition at line 365 of file pgsql_exchange.cc.
References convertToDatabaseTime(), isc_throw, and isc::db::DatabaseConnection::MAX_DB_TIME.
|
static |
Converts UTC time_t value to a text representation in local time.
input_time | A time_t value representing time. |
Definition at line 337 of file pgsql_exchange.cc.
Referenced by convertToDatabaseTime().
|
static |
Diagnostic tool which dumps the Result row contents as a string.
r | the result set containing the query results |
row | the row number within the result set |
Definition at line 631 of file pgsql_exchange.cc.
References getRawColumnValue(), and isc::db::PsqlBindArray::TEXT_FMT.
Referenced by isc::db::PgSqlResultRowWorker::dumpRow().
|
static |
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>". Note this is NOT from the list of columns defined in the exchange.
r | the result set containing the query results |
col | index of the column name to fetch |
Definition at line 626 of file pgsql_exchange.cc.
Referenced by convertFromBytea(), convertFromBytea(), getColumnValue(), getColumnValue(), getColumnValue(), getColumnValue(), getInetValue4(), getInetValue6(), getIPv6Value(), and getRawColumnValue().
|
static |
Fetches boolean text ('t' or 'f') as a bool.
r | the result set containing the query results | |
row | the row number within the result set | |
col | the column number within the row | |
[out] | value | parameter to receive the converted value |
DbOperationError | if the value cannot be fetched or is invalid. |
Definition at line 430 of file pgsql_exchange.cc.
References getColumnLabel(), getRawColumnValue(), and isc_throw.
|
static |
Fetches a timestamp column as a ptime.
r | the result set containing the query results | |
row | the row number within the result set | |
col | the column number within the row | |
[out] | value | ptime parameter to receive the converted timestamp |
DbOperationError | if the value cannot be fetched or is invalid. |
Definition at line 460 of file pgsql_exchange.cc.
References convertFromDatabaseTime(), and getColumnValue().
|
static |
Fetches a JSON column as an ElementPtr.
r | the result set containing the query results | |
row | the row number within the result set | |
col | the column number within the row | |
[out] | value | ElementPtr to receive the column data |
DbOperationError | if the value cannot be fetched or is invalid. |
Definition at line 468 of file pgsql_exchange.cc.
References isc::data::Element::fromJSON(), getColumnLabel(), getRawColumnValue(), and isc_throw.
|
static |
Fetches text column value as a string.
r | the result set containing the query results | |
row | the row number within the result set | |
col | the column number within the row | |
[out] | value | parameter to receive the string value |
DbOperationError | if the value cannot be fetched or is invalid. |
Definition at line 424 of file pgsql_exchange.cc.
References getRawColumnValue().
Referenced by isc::db::PgSqlResultRowWorker::getBigInt(), isc::db::PgSqlResultRowWorker::getBool(), getColumnValue(), isc::db::PgSqlResultRowWorker::getColumnValue(), isc::db::PgSqlResultRowWorker::getDouble(), isc::db::PgSqlResultRowWorker::getInt(), isc::db::PgSqlResultRowWorker::getSmallInt(), isc::db::PgSqlResultRowWorker::getString(), getTripletValue(), getTripletValue(), and isc::db::PgSqlConnection::getVersion().
|
inlinestatic |
Fetches a text column as the given value type.
Uses boost::lexicalcast to convert the text column value into a value of type T.
r | the result set containing the query results | |
row | the row number within the result set | |
col | the column number within the row | |
[out] | value | parameter to receive the converted value |
DbOperationError | if the value cannot be fetched or is invalid. |
Definition at line 719 of file pgsql_exchange.h.
References getColumnLabel(), getRawColumnValue(), and isc_throw.
|
static |
Fetches an integer text column as a uint8_t.
r | the result set containing the query results | |
row | the row number within the result set | |
col | the column number within the row | |
[out] | value | parameter to receive the converted value |
DbOperationError | if the value cannot be fetched or is invalid. |
Definition at line 445 of file pgsql_exchange.cc.
References getColumnLabel(), getRawColumnValue(), and isc_throw.
|
static |
Converts a column in a row in a result set into IPv4 address.
This is used to fetch values from inet type columns.
r | the result set containing the query results |
row | the row number within the result set |
col | the column number within the row |
DbOperationError | if the value cannot be fetched or is invalid. |
Definition at line 481 of file pgsql_exchange.cc.
References getColumnLabel(), getRawColumnValue(), isc_throw, and isc::asiolink::IOAddress::isV4().
Referenced by isc::db::PgSqlResultRowWorker::getInet4().
|
static |
Converts a column in a row in a result set into IPv6 address.
This is used to fetch values from inet type columns.
r | the result set containing the query results |
row | the row number within the result set |
col | the column number within the row |
DbOperationError | if the value cannot be fetched or is invalid. |
Definition at line 499 of file pgsql_exchange.cc.
References getColumnLabel(), getRawColumnValue(), isc_throw, and isc::asiolink::IOAddress::isV6().
Referenced by isc::db::PgSqlResultRowWorker::getInet6().
|
static |
Converts a column in a row in a result set into IPv6 address.
This used for IPv6 columns stored as varchar.
r | the result set containing the query results |
row | the row number within the result set |
col | the column number within the row |
DbOperationError | if the value cannot be fetched or is invalid. |
Definition at line 517 of file pgsql_exchange.cc.
References getColumnLabel(), getRawColumnValue(), and isc_throw.
|
static |
Gets a pointer to the raw column value in a result set row.
Given a result set, row, and column return a const char* pointer to the data value in the result set. The pointer is valid as long as the result set has not been freed. It may point to text or binary data depending on how query was structured. You should not attempt to free this pointer.
r | the result set containing the query results |
row | the row number within the result set |
col | the column number within the row |
DbOperationError | if the value cannot be fetched. |
Definition at line 405 of file pgsql_exchange.cc.
References getColumnLabel(), and isc_throw.
Referenced by convertFromBytea(), convertFromBytea(), dumpRow(), getColumnValue(), getColumnValue(), getColumnValue(), getColumnValue(), getColumnValue(), getInetValue4(), getInetValue6(), getIPv6Value(), and isc::db::PgSqlResultRowWorker::getRawColumnValue().
|
static |
Fetches a uint32_t value into a Triplet using a single column value.
r | the result set containing the query results |
row | the row number within the result set |
col | the column number within the row. If the column is null, the Triplet is returned as unspecified. |
DbOperationError | if the value cannot be fetched or is invalid. |
Definition at line 590 of file pgsql_exchange.cc.
References getColumnValue(), and isColumnNull().
Referenced by isc::db::PgSqlResultRowWorker::getTriplet(), and isc::db::PgSqlResultRowWorker::getTriplet().
|
static |
Fetches a uint32_t value into a Triplet using a three column values: default, minimum, and maximum.
r | the result set containing the query results |
row | the row number within the result set |
def_col | the column number within the row that contains the default value. If this column is null, the Triplet is returned as unspecified. |
min_col | the column number within the row that contains the minimum value. |
max_col | the column number within the row that contains the maximum value. |
DbOperationError | if the value cannot be fetched or is invalid. |
Definition at line 602 of file pgsql_exchange.cc.
References getColumnValue(), and isColumnNull().
|
static |
Returns true if a column within a row is null.
r | the result set containing the query results |
row | the row number within the result set |
col | the column number within the row |
Definition at line 417 of file pgsql_exchange.cc.
Referenced by getTripletValue(), getTripletValue(), and isc::db::PgSqlResultRowWorker::isColumnNull().
|
protected |
Stores text labels for columns, currently only used for logging and errors.
Definition at line 839 of file pgsql_exchange.h.