summaryrefslogtreecommitdiffstats
path: root/src/lib/mysql/mysql_binding.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/mysql/mysql_binding.cc')
-rw-r--r--src/lib/mysql/mysql_binding.cc40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/lib/mysql/mysql_binding.cc b/src/lib/mysql/mysql_binding.cc
index ad07c4a97a..974bb3fa82 100644
--- a/src/lib/mysql/mysql_binding.cc
+++ b/src/lib/mysql/mysql_binding.cc
@@ -8,6 +8,8 @@
#include <mysql/mysql_binding.h>
+using namespace isc::data;
+
namespace isc {
namespace db {
@@ -21,6 +23,23 @@ MySqlBinding::getString() const {
return (std::string(buffer_.begin(), buffer_.begin() + length_));
}
+std::string
+MySqlBinding::getStringOrDefault(const std::string& default_value) const {
+ if (amNull()) {
+ return (default_value);
+ }
+ return (getString());
+}
+
+ElementPtr
+MySqlBinding::getJSON() const {
+ if (amNull()) {
+ return (ElementPtr());
+ }
+ std::string s = getString();
+ return (Element::fromJSON(s));
+}
+
std::vector<uint8_t>
MySqlBinding::getBlob() const {
// Make sure the binding type is blob.
@@ -31,6 +50,14 @@ MySqlBinding::getBlob() const {
return (std::vector<uint8_t>(buffer_.begin(), buffer_.begin() + length_));
}
+std::vector<uint8_t>
+MySqlBinding::getBlobOrDefault(const std::vector<uint8_t>& default_value) const {
+ if (amNull()) {
+ return (default_value);
+ }
+ return (getBlob());
+}
+
boost::posix_time::ptime
MySqlBinding::getTimestamp() const {
// Make sure the binding type is timestamp.
@@ -41,6 +68,14 @@ MySqlBinding::getTimestamp() const {
return (convertFromDatabaseTime(*database_time));
}
+boost::posix_time::ptime
+MySqlBinding::getTimestampOrDefault(const boost::posix_time::ptime& default_value) const {
+ if (amNull()) {
+ return (default_value);
+ }
+ return (getTimestamp());
+}
+
MySqlBindingPtr
MySqlBinding::createString(const unsigned long length) {
MySqlBindingPtr binding(new MySqlBinding(MySqlBindingTraits<std::string>::column_type,
@@ -57,6 +92,11 @@ MySqlBinding::createString(const std::string& value) {
}
MySqlBindingPtr
+MySqlBinding::condCreateString(const std::string& value) {
+ return (value.empty() ? MySqlBinding::createNull() : createString(value));
+}
+
+MySqlBindingPtr
MySqlBinding::createBlob(const unsigned long length) {
MySqlBindingPtr binding(new MySqlBinding(MySqlBindingTraits<std::vector<uint8_t> >::column_type,
length));