Kea  1.9.9-git
isc::db::PsqlBindArray Struct Reference

#include <pgsql_exchange.h>

Public Member Functions

void add (const char *value)
 Adds a char array to bind array based. More...
 
void add (const std::string &value)
 Adds an string value to the bind array. More...
 
void add (const std::vector< uint8_t > &data)
 Adds a vector of binary data to the bind array. More...
 
void add (const uint8_t *data, const size_t len)
 Adds a buffer of binary data to the bind array. More...
 
void add (const bool &value)
 Adds a boolean value to the bind array. More...
 
void add (const uint8_t &byte)
 Adds a uint8_t value to the bind array. More...
 
void add (const isc::asiolink::IOAddress &addr)
 Adds the given IOAddress value to the bind array. More...
 
template<typename T >
void add (const T &value)
 Adds the given value to the bind array. More...
 
void addNull (const int format=PsqlBindArray::TEXT_FMT)
 Adds a NULL value to the bind array. More...
 
void addTempString (const std::string &str)
 Binds the given string to the bind array. More...
 
bool empty () const
 Indicates it the array is empty. More...
 
std::vector< ConstStringPtrgetBoundStrs ()
 
size_t size () const
 Fetches the number of entries in the array. More...
 
std::string toText () const
 Dumps the contents of the array to a string. More...
 

Public Attributes

std::vector< int > formats_
 Vector of "format" for each value. More...
 
std::vector< int > lengths_
 Vector of data lengths for each value. More...
 
std::vector< const char * > values_
 Vector of pointers to the data values. More...
 

Static Public Attributes

static const int BINARY_FMT = 1
 Format value for binary data. More...
 
static const char * FALSE_STR = "FALSE"
 Constant string passed to DB for boolean false values. More...
 
static const int TEXT_FMT = 0
 Format value for text data. More...
 
static const char * TRUE_STR = "TRUE"
 Constant string passed to DB for boolean true values. More...
 

Detailed Description

Definition at line 44 of file pgsql_exchange.h.

Member Function Documentation

void isc::db::PsqlBindArray::add ( const char *  value)

Adds a char array to bind array based.

Adds a TEXT_FMT value to the end of the bind array, using the given char* as the data source. The value is expected to be NULL terminated. The caller is responsible for ensuring that value remains in scope until the bind array has been discarded.

Parameters
valuechar array containing the null-terminated text to add.
Exceptions
DbOperationErrorif value is NULL.

Definition at line 26 of file pgsql_exchange.cc.

References formats_, isc_throw, lengths_, TEXT_FMT, and values_.

Referenced by add(), addTempString(), isc::dhcp::PgSqlLease4Exchange::createBindForSend(), isc::dhcp::PgSqlLease6Exchange::createBindForSend(), isc::dhcp::PgSqlLeaseMgr::deleteLease(), isc::dhcp::PgSqlLeaseMgr::getLease4(), isc::dhcp::PgSqlLeaseMgr::getLease6(), isc::dhcp::PgSqlLeaseMgr::getLeases4(), isc::dhcp::PgSqlLeaseMgr::getLeases6(), isc::dhcp::PgSqlLeaseStatsQuery::start(), isc::dhcp::PgSqlLeaseMgr::updateLease4(), and isc::dhcp::PgSqlLeaseMgr::updateLease6().

void isc::db::PsqlBindArray::add ( const std::string &  value)

Adds an string value to the bind array.

Adds a TEXT formatted value to the end of the bind array using the given string as the data source. The caller is responsible for ensuring that string parameter remains in scope until the bind array has been discarded.

Parameters
valuestd::string containing the value to add.

Definition at line 36 of file pgsql_exchange.cc.

References formats_, lengths_, TEXT_FMT, and values_.

void isc::db::PsqlBindArray::add ( const std::vector< uint8_t > &  data)

Adds a vector of binary data to the bind array.

Adds a BINARY_FMT value to the end of the bind array using the given vector as the data source. NOTE this does not replicate the vector, so it must remain in scope until the bind array is destroyed.

Parameters
datavector of binary bytes.

Definition at line 42 of file pgsql_exchange.cc.

References BINARY_FMT, formats_, lengths_, and values_.

void isc::db::PsqlBindArray::add ( const uint8_t *  data,
const size_t  len 
)

Adds a buffer of binary data to the bind array.

Adds a BINARY_FMT value to the end of the bind array using the given vector as the data source. NOTE this does not replicate the buffer, so it must remain in scope until the bind array is destroyed.

Parameters
databuffer of binary data.
lennumber of bytes of data in buffer
Exceptions
DbOperationErrorif data is NULL.

Definition at line 48 of file pgsql_exchange.cc.

References BINARY_FMT, formats_, isc_throw, lengths_, and values_.

void isc::db::PsqlBindArray::add ( const bool &  value)

Adds a boolean value to the bind array.

Converts the given boolean value to its corresponding to PostgreSQL string value and adds it as a TEXT_FMT value to the bind array. This creates an internally scoped string.

Parameters
valuethe boolean value to add.

Definition at line 58 of file pgsql_exchange.cc.

References add(), FALSE_STR, and TRUE_STR.

+ Here is the call graph for this function:

void isc::db::PsqlBindArray::add ( const uint8_t &  byte)

Adds a uint8_t value to the bind array.

Converts the given uint8_t value to its corresponding numeric string literal and adds it as a TEXT_FMT value to the bind array. This creates an internally scoped string.

Parameters
bytethe one byte value to add.

Definition at line 62 of file pgsql_exchange.cc.

References addTempString().

+ Here is the call graph for this function:

void isc::db::PsqlBindArray::add ( const isc::asiolink::IOAddress addr)

Adds the given IOAddress value to the bind array.

Converts the IOAddress, based on its protocol family, to the corresponding string literal and adds it as a TEXT_FMT value to the bind array. This creates an internally scoped string.

Parameters
addrIP address value to add.

Definition at line 69 of file pgsql_exchange.cc.

References addTempString(), isc::asiolink::IOAddress::isV4(), isc::asiolink::IOAddress::toText(), and isc::asiolink::IOAddress::toUint32().

+ Here is the call graph for this function:

template<typename T >
void isc::db::PsqlBindArray::add ( const T &  value)
inline

Adds the given value to the bind array.

Converts the given value to its corresponding string literal boost::lexical_cast and adds it as a TEXT_FMT value to the bind array. This is intended primarily for numeric types. This creates an internally scoped string.

Parameters
valuedata value to add.

Definition at line 157 of file pgsql_exchange.h.

References addTempString().

+ Here is the call graph for this function:

void isc::db::PsqlBindArray::addNull ( const int  format = PsqlBindArray::TEXT_FMT)

Adds a NULL value to the bind array.

This should be used whenever the value for a parameter specified in the SQL statement should be NULL.

Definition at line 78 of file pgsql_exchange.cc.

References formats_, lengths_, and values_.

void isc::db::PsqlBindArray::addTempString ( const std::string &  str)

Binds the given string to the bind array.

Prior to add the given string the vector of exchange values, it duplicated as a ConstStringPtr and saved internally. This guarantees the string remains in scope until the PsqlBindArray is destroyed, without the caller maintaining the string values.

Parameters
strstring value to add.
Todo:
Eventually this could replace add(std::string&)? This would mean all bound strings would be internally copies rather than perhaps belonging to the originating object such as Host::hostname_. One the one hand it would make all strings handled one-way only, on the other hand it would mean duplicating strings where it isn't strictly necessary.

Definition at line 89 of file pgsql_exchange.cc.

References add().

Referenced by add().

+ Here is the call graph for this function:

bool isc::db::PsqlBindArray::empty ( ) const
inline

Indicates it the array is empty.

Returns
Returns true if there are no entries in the array, false otherwise.

Definition at line 72 of file pgsql_exchange.h.

std::vector<ConstStringPtr> isc::db::PsqlBindArray::getBoundStrs ( )
inline

Definition at line 178 of file pgsql_exchange.h.

size_t isc::db::PsqlBindArray::size ( ) const
inline

Fetches the number of entries in the array.

Returns
Returns size_t containing the number of entries.

Definition at line 65 of file pgsql_exchange.h.

Referenced by isc::dhcp::PgSqlLeaseStatsQuery::start().

std::string isc::db::PsqlBindArray::toText ( ) const

Dumps the contents of the array to a string.

Returns
std::string containing the dump

Definition at line 94 of file pgsql_exchange.cc.

References formats_, lengths_, TEXT_FMT, and values_.

Referenced by isc::dhcp::PgSqlLeaseMgr::updateLease6().

Member Data Documentation

const int isc::db::PsqlBindArray::BINARY_FMT = 1
static

Format value for binary data.

Definition at line 56 of file pgsql_exchange.h.

Referenced by add().

const char * isc::db::PsqlBindArray::FALSE_STR = "FALSE"
static

Constant string passed to DB for boolean false values.

Definition at line 61 of file pgsql_exchange.h.

Referenced by add().

std::vector<int> isc::db::PsqlBindArray::formats_

Vector of "format" for each value.

A value of 0 means the value is text, 1 means the value is binary.

Definition at line 51 of file pgsql_exchange.h.

Referenced by add(), addNull(), isc::dhcp::PgSqlLeaseStatsQuery::start(), and toText().

std::vector<int> isc::db::PsqlBindArray::lengths_

Vector of data lengths for each value.

Definition at line 48 of file pgsql_exchange.h.

Referenced by add(), addNull(), isc::dhcp::PgSqlLeaseStatsQuery::start(), and toText().

const int isc::db::PsqlBindArray::TEXT_FMT = 0
static

Format value for text data.

Definition at line 54 of file pgsql_exchange.h.

Referenced by add(), and toText().

const char * isc::db::PsqlBindArray::TRUE_STR = "TRUE"
static

Constant string passed to DB for boolean true values.

Definition at line 59 of file pgsql_exchange.h.

Referenced by add().

std::vector<const char *> isc::db::PsqlBindArray::values_

Vector of pointers to the data values.

Definition at line 46 of file pgsql_exchange.h.

Referenced by add(), addNull(), isc::dhcp::PgSqlLeaseStatsQuery::start(), and toText().


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