12 #include <boost/lexical_cast.hpp>
37 values_.push_back(value.c_str());
43 values_.push_back(reinterpret_cast<const char*>(&(data[0])));
53 values_.push_back(reinterpret_cast<const char*>(&(data[0])));
66 (static_cast<unsigned int>(byte)));
95 std::ostringstream stream;
96 for (
int i = 0; i <
values_.size(); ++i) {
99 stream <<
"\"" <<
values_[i] <<
"\"" << std::endl;
103 stream <<
"empty" << std::endl;
106 for (
int x = 0; x <
lengths_[i]; ++x) {
107 stream << std::setfill(
'0') << std::setw(2)
109 <<
static_cast<unsigned int>(data[x]);
112 stream << std::setbase(10);
117 return (stream.str());
124 localtime_r(&input_time, &tinfo);
125 strftime(buffer,
sizeof(buffer),
"%Y-%m-%d %H:%M:%S", &tinfo);
126 return (std::string(buffer));
131 const uint32_t valid_lifetime) {
134 int64_t expire_time_64 =
static_cast<int64_t
>(cltt)
135 + static_cast<int64_t>(valid_lifetime);
154 new_time = (boost::lexical_cast<time_t>(db_time_val));
155 }
catch (
const std::exception& ex) {
166 const char* value = PQgetvalue(r, row, col);
178 return (PQgetisnull(r, row, col));
183 const size_t col, std::string& value) {
189 const size_t col,
bool &value) {
191 if (!strlen(data) || *data ==
'f') {
193 }
else if (*data ==
't') {
198 <<
" : must be 't' or 'f'");
204 const size_t col, uint8_t &value) {
209 value = boost::lexical_cast<uint16_t>(data);
210 }
catch (
const std::exception& ex) {
213 <<
" : " << ex.what());
223 }
catch (
const std::exception& ex) {
226 <<
" : " << ex.what());
232 const size_t col, uint8_t* buffer,
233 const size_t buffer_size,
234 size_t &bytes_converted) {
237 unsigned char* bytes = PQunescapeBytea((
const unsigned char*)
248 if (bytes_converted > buffer_size) {
252 << bytes_converted <<
" is too large for: "
258 memcpy(buffer, bytes, bytes_converted);
270 std::ostringstream stream;
272 for (
int col = 0; col < columns; ++col) {
275 int format = PQfformat(r, col);
277 stream << col <<
" " << name <<
" : " ;
278 if (format == PsqlBindArray::TEXT_FMT) {
279 stream <<
"\"" << val <<
"\"" << std::endl;
281 const char *data = val;
282 int length = PQfsize(r, col);
284 stream <<
"empty" << std::endl;
287 for (
int i = 0; i < length; ++i) {
288 stream << std::setfill(
'0') << std::setw(2)
290 <<
static_cast<unsigned int>(data[i]);
297 return (stream.str());
static time_t convertFromDatabaseTime(const std::string &db_time_val)
Converts time stamp from the database to a time_t.
RAII wrapper for PostgreSQL Result sets.
uint32_t toUint32() const
Converts IPv4 address to uint32_t.
static std::string convertToDatabaseTime(const time_t input_time)
Converts time_t value to a text representation in local time.
std::vector< int > formats_
Vector of "format" for each value.
static const int BINARY_FMT
Format value for binary data.
static std::string dumpRow(const PgSqlResult &r, int row)
Diagnostic tool which dumps the Result row contents as a string.
std::string toText() const
Dumps the contents of the array to a string.
static const char * FALSE_STR
Constant string passed to DB for boolean false values.
std::vector< int > lengths_
Vector of data lengths for each value.
void rowColCheck(int row, int col) const
Determines if both a row and column index are valid.
void rowCheck(int row) const
Determines if a row index is valid.
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 time_t MAX_DB_TIME
Defines maximum value for time that can be reliably stored.
bool isV4() const
Convenience function to check for an IPv4 address.
std::vector< const char * > values_
Vector of pointers to the data values.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
void addTempString(const std::string &str)
Binds the given string to the bind array.
void add(const char *value)
Adds a char array to bind array based.
static const int TEXT_FMT
Format value for text data.
static void getColumnValue(const PgSqlResult &r, const int row, const size_t col, std::string &value)
Fetches text column value as a string.
static bool isColumnNull(const PgSqlResult &r, const int row, const size_t col)
Returns true if a column within a row is null.
static std::string getColumnLabel(const PgSqlResult &r, const size_t col)
Fetches the name of the column in a result set.
void addNull(const int format=PsqlBindArray::TEXT_FMT)
Adds a NULL value to the bind array.
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.
boost::shared_ptr< const std::string > ConstStringPtr
Structure used to bind C++ input values to dynamic SQL parameters The structure contains three vector...
Defines the logger used by the top-level component of kea-dhcp-ddns.
int getCols() const
Returns the number of columns in the result set.
std::string toText() const
Convert the address to a string.
std::string getColumnLabel(const int col) const
Fetches the name of the column in a result set.
The IOAddress class represents an IP addresses (version agnostic)
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.
Exception thrown on failure to execute a database function.
static const char * TRUE_STR
Constant string passed to DB for boolean true values.
std::string format(const std::string &format, const std::vector< std::string > &args)
Apply Formatting.