7 #ifndef MYSQL_BINDING_H 8 #define MYSQL_BINDING_H 13 #include <boost/date_time/posix_time/conversion.hpp> 14 #include <boost/date_time/posix_time/posix_time.hpp> 15 #include <boost/shared_ptr.hpp> 18 #include <mysqld_error.h> 49 static const enum_field_types
column_type = MYSQL_TYPE_STRING;
57 static const enum_field_types
column_type = MYSQL_TYPE_TIMESTAMP;
58 static const size_t length =
sizeof(MYSQL_TIME);
59 static const bool am_unsignged =
false;
160 return (bind_.buffer_type);
217 std::vector<uint8_t>
getBlob()
const;
249 const T* value = reinterpret_cast<const T*>(&buffer_[0]);
268 return (default_value);
270 return (getInteger<T>());
293 boost::posix_time::ptime
344 template<
typename Iterator>
347 std::distance(begin, end)));
348 binding->setBufferValue(begin, end);
362 binding->setValue<T>(0);
378 binding->setValue(value);
422 MYSQL_TIME& output_time);
444 const uint32_t valid_lifetime,
465 uint32_t valid_lifetime,
474 static boost::posix_time::ptime
486 MySqlBinding(enum_field_types buffer_type,
const size_t length);
496 template<
typename Iterator>
497 void setBufferValue(Iterator begin, Iterator end) {
498 length_ = std::distance(begin, end);
499 buffer_.assign(begin, end);
506 if (buffer_.empty()) {
509 bind_.buffer = &buffer_[0];
510 bind_.buffer_length = length_;
516 void setBufferLength(
const unsigned long length);
525 void setValue(T value) {
526 memcpy(static_cast<void*>(&buffer_[0]), reinterpret_cast<char*>(&value),
528 bind_.buffer = &buffer_[0];
536 void setTimestampValue(
const boost::posix_time::ptime& timestamp);
547 void validateAccess()
const {
550 isc_throw(InvalidOperation,
"retrieved value is null");
554 isc_throw(InvalidOperation,
"mismatched column type");
559 std::vector<uint8_t> buffer_;
562 unsigned long length_;
static MySqlBindingPtr createNull()
Creates binding encapsulating a NULL value.
static MySqlBindingPtr createInteger(T value)
Creates binding of numeric type for sending data.
static MySqlBindingPtr createTimestamp()
Creates binding of timestamp type for receiving data.
static const enum_field_types column_type
Column type represented in MySQL C API.
enum_field_types getType() const
Returns MySQL column type for the binding.
static MySqlBindingPtr createBlob(Iterator begin, Iterator end)
Creates binding of blob type for sending data.
static MySqlBindingPtr condCreateString(const std::string &value)
Conditionally creates binding of text type for sending data if provided value is not empty.
static void convertToDatabaseTime(const time_t input_time, MYSQL_TIME &output_time)
Converts time_t value to database time.
boost::shared_ptr< Element > ElementPtr
MYSQL_BIND & getMySqlBinding()
Returns reference to the native binding.
static MySqlBindingPtr createString(const unsigned long length)
Creates binding of text type for receiving data.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
const my_bool MLM_FALSE
MySQL false value.
static const size_t length
Length of data in this column.
Trait class for column types supported in MySQL.
T getInteger() const
Returns numeric value held in the binding.
std::string getStringOrDefault(const std::string &default_value) const
Returns value held in the binding as string.
boost::posix_time::ptime getTimestampOrDefault(const boost::posix_time::ptime &default_value) const
Returns timestamp value held in the binding.
static void convertFromDatabaseTime(const MYSQL_TIME &expire, uint32_t valid_lifetime, time_t &cltt)
Converts Database Time to Lease Times.
std::vector< uint8_t > getBlobOrDefault(const std::vector< uint8_t > &default_value) const
Returns value held in the binding as blob.
std::string getString() const
Returns value held in the binding as string.
Defines the logger used by the top-level component of kea-dhcp-ddns.
static const bool am_unsigned
Boolean value indicating if the numeric value is unsigned.
std::vector< uint8_t > getBlob() const
Returns value held in the binding as blob.
static MySqlBindingPtr condCreateInteger(T value)
Conditionally creates binding of numeric type for sending data if provided value is not 0.
boost::posix_time::ptime getTimestamp() const
Returns timestamp value held in the binding.
std::vector< MySqlBindingPtr > MySqlBindingCollection
Collection of bindings.
boost::shared_ptr< MySqlBinding > MySqlBindingPtr
Shared pointer to the Binding class.
T getIntegerOrDefault(T default_value) const
Returns numeric value held in the binding.
data::ElementPtr getJSON() const
Returns value held in the binding as JSON.
static MySqlBindingPtr createBlob(const unsigned long length)
Creates binding of blob type for receiving data.
bool amNull() const
Checks if the bound value is NULL.
static MySqlBindingPtr createInteger()
Creates binding of numeric type for receiving data.
MySQL binding used in prepared statements.
const my_bool MLM_TRUE
MySQL true value.