Kea 2.7.6
|
#include <pgsql_exchange.h>
Public Member Functions | |
PsqlBindArray () | |
Constructor. | |
void | add (const bool &value) |
Adds a boolean value to the bind array. | |
void | add (const char *value) |
Adds a char array to bind array based. | |
void | add (const data::ConstElementPtr &value) |
Adds a ConstElementPtr to the bind array. | |
void | add (const data::ElementPtr &value) |
Adds an ElementPtr to the bind array. | |
void | add (const isc::asiolink::IOAddress &addr) |
Adds the given IOAddress value to the bind array. | |
void | add (const isc::util::Triplet< uint32_t > &triplet) |
Adds an integer Triplet's value to the bind array. | |
void | add (const std::string &value) |
Adds a string value to the bind array. | |
void | add (const std::vector< uint8_t > &data) |
Adds a vector of binary data to the bind array. | |
template<typename T > | |
void | add (const T &value) |
Adds the given value to the bind array. | |
void | add (const uint8_t &byte) |
Adds a uint8_t value to the bind array. | |
void | add (const uint8_t *data, const size_t len) |
Adds a buffer of binary data to the bind array. | |
void | addInet4 (const isc::asiolink::IOAddress &value) |
Adds an IPv4 address to the bind array. | |
void | addInet6 (const isc::asiolink::IOAddress &value) |
Adds an IPv6 address to the bind array. | |
void | addMax (const isc::util::Triplet< uint32_t > &triplet) |
Adds an integer Triplet's maximum value to the bind array. | |
void | addMin (const isc::util::Triplet< uint32_t > &triplet) |
Adds an integer Triplet's minimum value to the bind array. | |
void | addNull (const int format=PsqlBindArray::TEXT_FMT) |
Adds a NULL value to the bind array. | |
void | addOptional (const util::Optional< std::string > &value) |
Adds an Optional string to the bind array. | |
template<typename T > | |
void | addOptional (const util::Optional< T > &value) |
Adds an Optional<type> value to the bind array. | |
void | addOptionalInet4 (const util::Optional< isc::asiolink::IOAddress > &value) |
Adds an Optional IPv4 address to the bind array. | |
void | addOptionalInet6 (const util::Optional< isc::asiolink::IOAddress > &value) |
Adds an Optional IPv6 address to the bind array. | |
void | addTempBinary (const std::vector< uint8_t > &data) |
Adds a vector of binary data to the bind array. | |
void | addTempBuffer (const uint8_t *data, const size_t len) |
Adds a temporary buffer of binary data to the bind array. | |
void | addTempString (const std::string &str) |
Binds the given string to the bind array. | |
void | addTimestamp () |
Adds a timestamp of the current time to the bind array. | |
void | addTimestamp (const boost::posix_time::ptime ×tamp) |
Adds a timestamp from a ptime to the bind array. | |
bool | amNull (size_t index=0) const |
Determines if specified value is null. | |
bool | empty () const |
Indicates it the array is empty. | |
template<typename T > | |
T | getInteger (size_t index=0) |
Returns the value as an integer. | |
int | getType (size_t index=0) |
Returns the column type. | |
void | insert (const char *value, size_t index) |
Inserts a string value to the bind array before the given index. | |
void | insert (const std::string &value, size_t index) |
Inserts a string value to the bind array before the given index. | |
void | popBack () |
Removes the last entry in the bind array. | |
size_t | size () const |
Fetches the number of entries in the array. | |
std::string | toText () const |
Dumps the contents of the array to a string. | |
Public Attributes | |
std::vector< int > | formats_ |
Vector of "format" for each value. | |
std::vector< int > | lengths_ |
Vector of data lengths for each value. | |
std::vector< const char * > | values_ |
Vector of pointers to the data values. | |
Static Public Attributes | |
static const int | BINARY_FMT = 1 |
Format value for binary data. | |
static const char * | FALSE_STR = "FALSE" |
Constant string passed to DB for boolean false values. | |
static const int | TEXT_FMT = 0 |
Format value for text data. | |
static const char * | TRUE_STR = "TRUE" |
Constant string passed to DB for boolean true values. | |
Definition at line 151 of file pgsql_exchange.h.
|
inline |
Constructor.
Definition at line 153 of file pgsql_exchange.h.
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.
value | the boolean value to add. |
Definition at line 119 of file pgsql_exchange.cc.
References add(), FALSE_STR, and TRUE_STR.
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.
value | char array containing the null-terminated text to add. |
DbOperationError | if value is NULL. |
Definition at line 31 of file pgsql_exchange.cc.
References formats_, isc_throw, lengths_, TEXT_FMT, and values_.
Referenced by add(), add(), addMax(), addMin(), addOptional(), and addTempString().
void isc::db::PsqlBindArray::add | ( | const data::ConstElementPtr & | value | ) |
Adds a ConstElementPtr to the bind array.
Adds a TEXT_FMT value to the end of the bind array containing the JSON text output by given ElementPtr::toJSON().
value | ElementPtr containing Element tree to add. |
DbOperationError | if value is NULL. |
Definition at line 279 of file pgsql_exchange.cc.
References addNull(), and addTempString().
void isc::db::PsqlBindArray::add | ( | const data::ElementPtr & | value | ) |
Adds an ElementPtr to the bind array.
Adds a TEXT_FMT value to the end of the bind array containing the JSON text output by given ElementPtr::toJSON().
value | ElementPtr containing Element tree to add. |
DbOperationError | if value is NULL. |
Definition at line 267 of file pgsql_exchange.cc.
References addNull(), and addTempString().
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.
addr | IP address value to add. |
Definition at line 130 of file pgsql_exchange.cc.
References addTempString(), isc::asiolink::IOAddress::isV4(), isc::asiolink::IOAddress::toText(), and isc::asiolink::IOAddress::toUint32().
void isc::db::PsqlBindArray::add | ( | const isc::util::Triplet< uint32_t > & | triplet | ) |
Adds an integer Triplet's value to the bind array.
Stores the current value of a triplet to the bind array. If it is unspecified it stores a NULL.
triplet | Triplet instance from which to get the value. |
Definition at line 146 of file pgsql_exchange.cc.
References add(), addNull(), isc::util::Triplet< T >::get(), and isc::util::Optional< T >::unspecified().
void isc::db::PsqlBindArray::add | ( | const std::string & | value | ) |
Adds a 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.
value | std::string containing the value to add. |
Definition at line 41 of file pgsql_exchange.cc.
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.
data | vector of binary bytes. |
Definition at line 81 of file pgsql_exchange.cc.
References BINARY_FMT, formats_, lengths_, and values_.
|
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.
value | data value to add. |
Definition at line 327 of file pgsql_exchange.h.
References addTempString().
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.
byte | the one byte value to add. |
Definition at line 123 of file pgsql_exchange.cc.
References addTempString().
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.
data | buffer of binary data. |
len | number of bytes of data in buffer |
DbOperationError | if data is NULL. |
Definition at line 96 of file pgsql_exchange.cc.
References BINARY_FMT, formats_, isc_throw, lengths_, and values_.
void isc::db::PsqlBindArray::addInet4 | ( | const isc::asiolink::IOAddress & | value | ) |
Adds an IPv4 address to the bind array.
This is used for inet type columns.
value | Optional boolean value to add |
BadValue | if the address is not a IPv4 address. |
Definition at line 193 of file pgsql_exchange.cc.
References addTempString(), isc_throw, isc::asiolink::IOAddress::isV4(), and isc::asiolink::IOAddress::toText().
Referenced by addOptionalInet4().
void isc::db::PsqlBindArray::addInet6 | ( | const isc::asiolink::IOAddress & | value | ) |
Adds an IPv6 address to the bind array.
This is used for inet type columns.
value | Optional boolean value to add |
BadValue | if the address is not a IPv6 address. |
Definition at line 214 of file pgsql_exchange.cc.
References addTempString(), isc_throw, isc::asiolink::IOAddress::isV6(), and isc::asiolink::IOAddress::toText().
Referenced by addOptionalInet6().
void isc::db::PsqlBindArray::addMax | ( | const isc::util::Triplet< uint32_t > & | triplet | ) |
Adds an integer Triplet's maximum value to the bind array.
Stores the maximum value of a triplet to the bind array. If it is unspecified it stores a NULL.
triplet | Triplet instance from which to get the value. |
Definition at line 164 of file pgsql_exchange.cc.
References add(), addNull(), isc::util::Triplet< T >::get(), isc::util::Triplet< T >::getMax(), and isc::util::Optional< T >::unspecified().
void isc::db::PsqlBindArray::addMin | ( | const isc::util::Triplet< uint32_t > & | triplet | ) |
Adds an integer Triplet's minimum value to the bind array.
Stores the minimum value of a triplet to the bind array. If it is unspecified it stores a NULL.
triplet | Triplet instance from which to get the value. |
Definition at line 155 of file pgsql_exchange.cc.
References add(), addNull(), isc::util::Triplet< T >::get(), isc::util::Triplet< T >::getMin(), and isc::util::Optional< T >::unspecified().
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 139 of file pgsql_exchange.cc.
References formats_, lengths_, and values_.
Referenced by add(), add(), add(), addMax(), addMin(), addOptional(), addOptional(), addOptionalInet4(), and addOptionalInet6().
void isc::db::PsqlBindArray::addOptional | ( | const util::Optional< std::string > & | value | ) |
Adds an Optional
string to the bind array.
Optional strings require adding a temp string to the bind array, unlike other types which implicitly do so.
value | Optional string value to add |
Definition at line 184 of file pgsql_exchange.cc.
References addNull(), addTempString(), and isc::util::Optional< T >::unspecified().
|
inline |
Adds an Optional<type>
value to the bind array.
T | variable type corresponding to the binding type, e.g. string , bool, uint8_t, uint16_t etc. |
value | Optional of type T. |
Definition at line 385 of file pgsql_exchange.h.
References add(), addNull(), isc::util::Optional< T >::get(), and isc::util::Optional< T >::unspecified().
void isc::db::PsqlBindArray::addOptionalInet4 | ( | const util::Optional< isc::asiolink::IOAddress > & | value | ) |
Adds an Optional
IPv4 address to the bind array.
This is used for inet type columns.
value | Optional boolean value to add |
BadValue | if the address is not a IPv4 address. |
Definition at line 204 of file pgsql_exchange.cc.
References addInet4(), addNull(), and isc::util::Optional< T >::unspecified().
void isc::db::PsqlBindArray::addOptionalInet6 | ( | const util::Optional< isc::asiolink::IOAddress > & | value | ) |
Adds an Optional
IPv6 address to the bind array.
This is used for inet type columns which expect v4 addresses to be inserted in string form: '3001::1'
value | Optional boolean value to add |
BadValue | if the address is not a IPv6 address. |
Definition at line 225 of file pgsql_exchange.cc.
References addInet6(), addNull(), and isc::util::Optional< T >::unspecified().
void isc::db::PsqlBindArray::addTempBinary | ( | 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. This creates an internally scoped copy of the vector.
data | vector of binary bytes. |
Definition at line 87 of file pgsql_exchange.cc.
References BINARY_FMT, formats_, lengths_, and values_.
void isc::db::PsqlBindArray::addTempBuffer | ( | const uint8_t * | data, |
const size_t | len ) |
Adds a temporary 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. Prior to adding the buffer, it is duplicated as a ConstStringPtr and saved internally. This guarantees the buffer remains in scope until the PsqlBindArray is destroyed, without the caller maintaining the buffer values.
data | buffer of binary data. |
len | number of bytes of data in buffer |
DbOperationError | if data is NULL. |
Definition at line 106 of file pgsql_exchange.cc.
References BINARY_FMT, formats_, isc_throw, 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.
str | string value to add. |
Definition at line 177 of file pgsql_exchange.cc.
References add().
Referenced by add(), add(), add(), add(), add(), addInet4(), addInet6(), addOptional(), addTimestamp(), and addTimestamp().
void isc::db::PsqlBindArray::addTimestamp | ( | ) |
Adds a timestamp of the current time to the bind array.
Precision is seconds.
Definition at line 260 of file pgsql_exchange.cc.
References addTempString(), and isc::db::PgSqlExchange::convertLocalToDatabaseTime().
void isc::db::PsqlBindArray::addTimestamp | ( | const boost::posix_time::ptime & | timestamp | ) |
Adds a timestamp from a ptime to the bind array.
Precision is seconds.
timestamp | Timestamp value to be sent to the database. |
BadValue | if the timestamp exceeds DatabaseConnection::MAX_DB_TIME. |
Definition at line 235 of file pgsql_exchange.cc.
References addTempString(), isc::db::PgSqlExchange::convertLocalToDatabaseTime(), isc_throw, and isc::db::DatabaseConnection::MAX_DB_TIME.
bool isc::db::PsqlBindArray::amNull | ( | size_t | index = 0 | ) | const |
Determines if specified value is null.
index | if array holds more than one value, this index determines which column to use |
Definition at line 325 of file pgsql_exchange.cc.
|
inline |
Indicates it the array is empty.
Definition at line 186 of file pgsql_exchange.h.
References values_.
|
inline |
Returns the value as an integer.
index | if array holds more than one value, this index determines which column to use |
OutOfRange | if the offset is too large |
BadValue | if the data is null |
boost::bad_lexical_cast | if value is not an integer |
Definition at line 479 of file pgsql_exchange.h.
|
inline |
Returns the column type.
index | if array holds more than one value, this index determines which column to use |
BadValue | if the offset is too large |
Definition at line 496 of file pgsql_exchange.h.
void isc::db::PsqlBindArray::insert | ( | const char * | value, |
size_t | index ) |
Inserts a string value to the bind array before the given index.
Inserts a TEXT_FMT value into the bind array before the element position given by index, 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.
value | char array containing the null-terminated text to add. |
index | element position before which the string should be inserted. |
DbOperationError | if value is NULL. |
OutOfRange | if the index is beyond the end of the array. |
Definition at line 47 of file pgsql_exchange.cc.
References formats_, isc_throw, lengths_, TEXT_FMT, and values_.
void isc::db::PsqlBindArray::insert | ( | const std::string & | value, |
size_t | index ) |
Inserts a string value to the bind array before the given index.
Inserts a TEXT_FMT value into the bind array before the element position given by index, using the given given string as the data source. This creates an internally scoped copy of the string.
value | char array containing the null-terminated text to add. |
index | element position before which the string should be inserted. |
DbOperationError | if value is NULL. |
OutOfRange | if the index is beyond the end of the array. |
Definition at line 58 of file pgsql_exchange.cc.
References formats_, isc_throw, lengths_, TEXT_FMT, and values_.
void isc::db::PsqlBindArray::popBack | ( | ) |
Removes the last entry in the bind array.
OutOfRange | if array is empty. |
Definition at line 71 of file pgsql_exchange.cc.
|
inline |
Fetches the number of entries in the array.
Definition at line 179 of file pgsql_exchange.h.
References values_.
Referenced by isc::db::PgSqlConnection::executePreparedStatement().
std::string isc::db::PsqlBindArray::toText | ( | ) | const |
|
static |
Format value for binary data.
Definition at line 169 of file pgsql_exchange.h.
Referenced by add(), add(), addTempBinary(), and addTempBuffer().
|
static |
Constant string passed to DB for boolean false values.
Definition at line 175 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 163 of file pgsql_exchange.h.
Referenced by add(), add(), add(), add(), addNull(), addTempBinary(), addTempBuffer(), isc::db::PgSqlConnection::executePreparedStatement(), getType(), insert(), insert(), popBack(), and toText().
std::vector<int> isc::db::PsqlBindArray::lengths_ |
Vector of data lengths for each value.
Definition at line 159 of file pgsql_exchange.h.
Referenced by add(), add(), add(), add(), addNull(), addTempBinary(), addTempBuffer(), amNull(), isc::db::PgSqlConnection::executePreparedStatement(), insert(), insert(), popBack(), and toText().
|
static |
Format value for text data.
Definition at line 166 of file pgsql_exchange.h.
Referenced by add(), add(), isc::db::PgSqlExchange::dumpRow(), insert(), insert(), and toText().
|
static |
Constant string passed to DB for boolean true values.
Definition at line 172 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 156 of file pgsql_exchange.h.
Referenced by add(), add(), add(), add(), addNull(), addTempBinary(), addTempBuffer(), amNull(), empty(), isc::db::PgSqlConnection::executePreparedStatement(), getInteger(), insert(), insert(), popBack(), size(), and toText().