19 validateAccess<std::string>();
21 return (std::string());
23 return (std::string(buffer_.begin(), buffer_.begin() + length_));
29 return (default_value);
46 validateAccess<std::vector<uint8_t> >();
48 return (std::vector<uint8_t>());
50 return (std::vector<uint8_t>(buffer_.begin(), buffer_.begin() + length_));
56 return (default_value);
61boost::posix_time::ptime
64 validateAccess<boost::posix_time::ptime>();
67 const MYSQL_TIME* database_time =
reinterpret_cast<const MYSQL_TIME*
>(&buffer_[0]);
71boost::posix_time::ptime
74 return (default_value);
90 binding->setBufferValue(value.begin(), value.end());
110 binding->setTimestampValue(timestamp);
129 MYSQL_TIME& output_time) {
133 (void) localtime_r(&input_time, &time_tm);
136 output_time.year = time_tm.tm_year + 1900;
137 output_time.month = time_tm.tm_mon + 1;
138 output_time.day = time_tm.tm_mday;
139 output_time.hour = time_tm.tm_hour;
140 output_time.minute = time_tm.tm_min;
141 output_time.second = time_tm.tm_sec;
142 output_time.second_part = 0;
143 output_time.neg = my_bool(0);
148 const uint32_t valid_lifetime,
149 MYSQL_TIME& expire) {
153 int64_t expire_time_64 =
static_cast<int64_t
>(cltt) +
154 static_cast<int64_t
>(valid_lifetime);
162 const time_t expire_time =
static_cast<const time_t
>(expire_time_64);
166 (void) localtime_r(&expire_time, &expire_tm);
169 expire.year = expire_tm.tm_year + 1900;
170 expire.month = expire_tm.tm_mon + 1;
171 expire.day = expire_tm.tm_mday;
172 expire.hour = expire_tm.tm_hour;
173 expire.minute = expire_tm.tm_min;
174 expire.second = expire_tm.tm_sec;
175 expire.second_part = 0;
176 expire.neg = my_bool(0);
181 uint32_t valid_lifetime,
185 memset(&expire_tm, 0,
sizeof(expire_tm));
187 expire_tm.tm_year = expire.year - 1900;
188 expire_tm.tm_mon = expire.month - 1;
189 expire_tm.tm_mday = expire.day;
190 expire_tm.tm_hour = expire.hour;
191 expire_tm.tm_min = expire.minute;
192 expire_tm.tm_sec = expire.second;
193 expire_tm.tm_isdst = -1;
196 cltt = mktime(&expire_tm) - valid_lifetime;
199boost::posix_time::ptime
202 struct tm converted_tm;
203 memset(&converted_tm, 0,
sizeof(converted_tm));
205 converted_tm.tm_year = database_time.year - 1900;
206 converted_tm.tm_mon = database_time.month - 1;
207 converted_tm.tm_mday = database_time.day;
208 converted_tm.tm_hour = database_time.hour;
209 converted_tm.tm_min = database_time.minute;
210 converted_tm.tm_sec = database_time.second;
211 converted_tm.tm_isdst = -1;
214 return (boost::posix_time::ptime_from_tm(converted_tm));
217MySqlBinding::MySqlBinding(enum_field_types buffer_type,
219 : buffer_(length), length_(length),
220 null_value_(buffer_type == MYSQL_TYPE_NULL) {
221 memset(&bind_, 0,
sizeof(MYSQL_BIND));
222 bind_.buffer_type = buffer_type;
224 if (buffer_type != MYSQL_TYPE_NULL) {
225 bind_.buffer = &buffer_[0];
226 bind_.buffer_length = length_;
227 bind_.length = &length_;
228 bind_.is_null = &null_value_;
233MySqlBinding::setBufferLength(
const unsigned long length) {
241 buffer_.resize(length_ > 0 ? length_ : 1);
242 bind_.buffer = &buffer_[0];
243 bind_.buffer_length = length_;
247MySqlBinding::setTimestampValue(
const boost::posix_time::ptime& timestamp) {
249 tm td_tm = to_tm(timestamp);
251 time_t tt = mktime(&td_tm);
253 MYSQL_TIME database_time;
256 memcpy(
static_cast<void*
>(&buffer_[0]),
reinterpret_cast<char*
>(&database_time),
258 bind_.buffer = &buffer_[0];
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
static ElementPtr fromJSON(const std::string &in, bool preproc=false)
These functions will parse the given string (JSON) representation of a compound element.
static const time_t MAX_DB_TIME
Defines maximum value for time that can be reliably stored.
MySQL binding used in prepared statements.
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::vector< uint8_t > getBlob() const
Returns value held in the binding as blob.
static MySqlBindingPtr createString(const unsigned long length)
Creates binding of text type for receiving data.
bool amNull() const
Checks if the bound value is NULL.
std::string getString() const
Returns value held in the binding as string.
data::ElementPtr getJSON() const
Returns value held in the binding as JSON.
std::string getStringOrDefault(const std::string &default_value) const
Returns value held in the binding as string.
static MySqlBindingPtr condCreateString(const std::string &value)
Conditionally creates binding of text type for sending data if provided value is not empty.
static MySqlBindingPtr createTimestamp()
Creates binding of timestamp type for receiving data.
boost::posix_time::ptime getTimestamp() const
Returns timestamp value held in the binding.
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 createBlob(const unsigned long length)
Creates binding of blob type for receiving data.
static void convertToDatabaseTime(const time_t input_time, MYSQL_TIME &output_time)
Converts time_t value to database time.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< MySqlBinding > MySqlBindingPtr
Shared pointer to the Binding class.
Defines the logger used by the top-level component of kea-dhcp-ddns.
Trait class for column types supported in MySQL.