From f268aec98176049136bceb2741f3615841e5c516 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 23 Dec 2015 23:15:18 +0000 Subject: MySQL files prefixed with my- --- libmysqlpp/my-column.cpp | 118 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 libmysqlpp/my-column.cpp (limited to 'libmysqlpp/my-column.cpp') diff --git a/libmysqlpp/my-column.cpp b/libmysqlpp/my-column.cpp new file mode 100644 index 0000000..4e3038e --- /dev/null +++ b/libmysqlpp/my-column.cpp @@ -0,0 +1,118 @@ +#include "my-column.h" +#include "my-selectcommand.h" +#include "my-error.h" +#include +#include + +MySQL::ColumnBase::ColumnBase(const char * name, unsigned int i) : + DB::Column(name, i) +{ +} + +bool +MySQL::ColumnBase::isNull() const +{ + return is_null; +} + +void +MySQL::ColumnBase::rebind(DB::Command *, unsigned int) const +{ + throw Error("Not supported"); +} + +MySQL::StringColumn::StringColumn(const char * name, unsigned int field, MYSQL_BIND * b, unsigned int len) : + ColumnBase(name, field), + value(new char[len]) +{ + b->is_null = &is_null; + b->buffer_type = MYSQL_TYPE_STRING; + b->is_unsigned = 0; + b->buffer = value; + b->buffer_length = len; + b->length = &length; +} +MySQL::StringColumn::~StringColumn() +{ + delete[] value; +} +void +MySQL::StringColumn::apply(DB::HandleField & h) const +{ + if (is_null) { + h.null(); + } + else { + h.string(value, length); + } +} +MySQL::NullColumn::NullColumn(const char * name, unsigned int field, MYSQL_BIND * b) : + ColumnBase(name, field) +{ + b->is_null = &is_null; + b->buffer_type = MYSQL_TYPE_NULL; + b->buffer = NULL; + b->buffer_length = 0; +} +void +MySQL::NullColumn::apply(DB::HandleField & h) const +{ + h.null(); +} + +namespace MySQL { + template Column::Column(const char * name, unsigned int field, MYSQL_BIND * b) : + ColumnBase(name, field) + { + b->is_null = &is_null; + b->buffer_type = MT; + b->is_unsigned = 0; + b->buffer = &value; + b->buffer_length = sizeof(T); + } + + template <> void Column::apply(DB::HandleField & h) const + { + if (is_null) { + h.null(); + } + else { + h.integer(value); + } + } + template <> void Column::apply(DB::HandleField & h) const + { + if (is_null) { + h.null(); + } + else { + h.floatingpoint(value); + } + } + template <> void Column::apply(DB::HandleField & h) const + { + if (is_null) { + h.null(); + } + else { + h.timestamp(boost::posix_time::ptime( + boost::gregorian::date(value.year, value.month, value.day), + boost::posix_time::time_duration(value.hour, value.minute, value.second) + boost::posix_time::microseconds(value.second_part))); + } + } + template <> void Column::apply(DB::HandleField & h) const + { + if (is_null) { + h.null(); + } + else { + h.interval( + boost::posix_time::time_duration(value.hour, value.minute, value.second) + boost::posix_time::microseconds(value.second_part)); + } + } + + template class Column; + template class Column; + template class Column; + template class Column; +} -- cgit v1.2.3