7 #ifndef MYSQL_BINDING_H
8 #define MYSQL_BINDING_H
15 #include <boost/date_time/posix_time/conversion.hpp>
16 #include <boost/date_time/posix_time/posix_time.hpp>
17 #include <boost/shared_ptr.hpp>
20 #include <mysqld_error.h>
51 static const enum_field_types
column_type = MYSQL_TYPE_STRING;
59 static const enum_field_types
column_type = MYSQL_TYPE_TIMESTAMP;
60 static const size_t length =
sizeof(MYSQL_TIME);
61 static const bool am_unsignged =
false;
169 return (bind_.buffer_type);
226 std::vector<uint8_t>
getBlob()
const;
258 const T* value =
reinterpret_cast<const T*
>(&buffer_[0]);
277 return (default_value);
279 return (getInteger<T>());
303 return (static_cast<bool>(getInteger<uint8_t>()));
326 boost::posix_time::ptime
342 static MySqlBindingPtr
createString(
const unsigned long length);
349 static MySqlBindingPtr
createString(
const std::string& value);
365 static MySqlBindingPtr
createBlob(
const unsigned long length);
377 template<
typename Iterator>
378 static MySqlBindingPtr
createBlob(Iterator begin, Iterator end) {
379 MySqlBindingPtr binding(
new MySqlBinding(MYSQL_TYPE_BLOB,
380 std::distance(begin, end)));
381 binding->setBufferValue(begin, end);
395 binding->setValue<T>(0);
411 binding->setValue(value);
434 static MySqlBindingPtr
createFloat(
const float value);
447 createInteger<float> (
static_cast<float>(value.
get())));
456 static MySqlBindingPtr
createBool(
const bool value);
472 static MySqlBindingPtr
485 static MySqlBindingPtr
createTimestamp(
const boost::posix_time::ptime& timestamp);
501 MYSQL_TIME& output_time);
509 MYSQL_TIME& output_time);
531 const uint32_t valid_lifetime,
552 uint32_t valid_lifetime,
561 static boost::posix_time::ptime
573 MySqlBinding(enum_field_types buffer_type,
const size_t length);
583 template<
typename Iterator>
584 void setBufferValue(Iterator begin, Iterator end) {
585 length_ = std::distance(begin, end);
586 buffer_.assign(begin, end);
593 if (buffer_.empty()) {
596 bind_.buffer = &buffer_[0];
597 bind_.buffer_length = length_;
603 void setBufferLength(
const unsigned long length);
612 void setValue(T value) {
613 memcpy(static_cast<void*>(&buffer_[0]), reinterpret_cast<char*>(&value),
615 bind_.buffer = &buffer_[0];
623 void setTimestampValue(
const boost::posix_time::ptime& timestamp);
634 void validateAccess()
const {
637 isc_throw(InvalidOperation,
"retrieved value is null");
640 if (MySqlBindingTraits<T>::column_type !=
getType()) {
641 isc_throw(InvalidOperation,
"mismatched column type");
646 std::vector<uint8_t> buffer_;
649 unsigned long length_;
std::vector< uint8_t > getBlobOrDefault(const std::vector< uint8_t > &default_value) const
Returns value held in the binding as blob.
boost::posix_time::ptime getTimestampOrDefault(const boost::posix_time::ptime &default_value) const
Returns timestamp value held in the binding.
static MySqlBindingPtr createNull()
Creates binding encapsulating a NULL value.
static MySqlBindingPtr createInteger(T value)
Creates binding of numeric type for sending data.
bool my_bool
my_bool type in MySQL 8.x.
void unspecified(bool unspecified)
Modifies the flag that indicates whether the value is specified or unspecified.
std::vector< uint8_t > getBlob() const
Returns value held in the binding as blob.
std::string getString() const
Returns value held in the binding as string.
T getIntegerOrDefault(T default_value) const
Returns numeric value held in the binding.
static MySqlBindingPtr createTimestamp()
Creates binding of timestamp type for receiving data.
bool amNull() const
Checks if the bound value is NULL.
static const enum_field_types column_type
Column type represented in MySQL C API.
T getInteger() const
Returns numeric value held in the binding.
static MySqlBindingPtr createBlob(Iterator begin, Iterator end)
Creates binding of blob type for sending data.
bool getBool() const
Returns boolean value held in the binding.
static void convertToDatabaseTime(const time_t input_time, MYSQL_TIME &output_time)
Converts time_t value to database time.
boost::shared_ptr< Element > ElementPtr
enum_field_types getType() const
Returns MySQL column type for the binding.
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 MySqlBindingPtr condCreateBool(const util::Optional< bool > &value)
Conditionally creates binding of uint8_t type representing a boolean value if provided value is speci...
static const size_t length
Length of data in this column.
static MySqlBindingPtr condCreateInteger(const util::Optional< T > &value)
Conditionally creates binding of numeric type for sending data if provided value is specified...
Trait class for column types supported in MySQL.
static void convertFromDatabaseTime(const MYSQL_TIME &expire, uint32_t valid_lifetime, time_t &cltt)
Converts Database Time to Lease Times.
static MySqlBindingPtr condCreateFloat(const util::Optional< T > &value)
Conditionally creates binding of float type for sending data if provided value is specified...
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.
static MySqlBindingPtr condCreateString(const util::Optional< std::string > &value)
Conditionally creates binding of text type for sending data if provided value is unspecified.
T get() const
Retrieves the encapsulated value.
boost::posix_time::ptime getTimestamp() const
Returns timestamp value held in the binding.
static MySqlBindingPtr condCreateIPv4Address(const util::Optional< asiolink::IOAddress > &value)
Conditionally creates binding of uint32_t type representing an IPv4 address if provided value is spec...
float getFloat() const
Returns float value held in the binding.
static MySqlBindingPtr createFloat(const float value)
Creates binding having a float type for sending data.
static MySqlBindingPtr createBool(const bool value)
Creates binding having a bool type for sending data.
std::string getStringOrDefault(const std::string &default_value) const
Returns value held in the binding as string.
std::vector< MySqlBindingPtr > MySqlBindingCollection
Collection of bindings.
boost::shared_ptr< MySqlBinding > MySqlBindingPtr
Shared pointer to the Binding class.
static MySqlBindingPtr createBlob(const unsigned long length)
Creates binding of blob type for receiving data.
static MySqlBindingPtr createInteger()
Creates binding of numeric type for receiving data.
MySQL binding used in prepared statements.
data::ElementPtr getJSON() const
Returns value held in the binding as JSON.
const my_bool MLM_TRUE
MySQL true value.