// // MySQLException.cpp // // Library: Data/MySQL // Package: MySQL // Module: Binder // // Copyright (c) 2008, Applied Informatics Software Engineering GmbH. // and Contributors. // // SPDX-License-Identifier: BSL-1.0 // #include "Poco/Data/MySQL/Binder.h" namespace Poco { namespace Data { namespace MySQL { Binder::Binder() { } Binder::~Binder() { for (std::vector::iterator it = _dates.begin(); it != _dates.end(); ++it) { delete *it; *it = 0; } } void Binder::bind(std::size_t pos, const Poco::Int8& val, Direction dir) { poco_assert(dir == PD_IN); realBind(pos, MYSQL_TYPE_TINY, &val, 0); } void Binder::bind(std::size_t pos, const Poco::UInt8& val, Direction dir) { poco_assert(dir == PD_IN); realBind(pos, MYSQL_TYPE_TINY, &val, 0, true); } void Binder::bind(std::size_t pos, const Poco::Int16& val, Direction dir) { poco_assert(dir == PD_IN); realBind(pos, MYSQL_TYPE_SHORT, &val, 0); } void Binder::bind(std::size_t pos, const Poco::UInt16& val, Direction dir) { poco_assert(dir == PD_IN); realBind(pos, MYSQL_TYPE_SHORT, &val, 0, true); } void Binder::bind(std::size_t pos, const Poco::Int32& val, Direction dir) { poco_assert(dir == PD_IN); realBind(pos, MYSQL_TYPE_LONG, &val, 0); } void Binder::bind(std::size_t pos, const Poco::UInt32& val, Direction dir) { poco_assert(dir == PD_IN); realBind(pos, MYSQL_TYPE_LONG, &val, 0, true); } void Binder::bind(std::size_t pos, const Poco::Int64& val, Direction dir) { poco_assert(dir == PD_IN); realBind(pos, MYSQL_TYPE_LONGLONG, &val, 0); } void Binder::bind(std::size_t pos, const Poco::UInt64& val, Direction dir) { poco_assert(dir == PD_IN); realBind(pos, MYSQL_TYPE_LONGLONG, &val, 0, true); } #ifndef POCO_INT64_IS_LONG void Binder::bind(std::size_t pos, const long& val, Direction dir) { poco_assert(dir == PD_IN); realBind(pos, MYSQL_TYPE_LONG, &val, 0); } void Binder::bind(std::size_t pos, const unsigned long& val, Direction dir) { poco_assert(dir == PD_IN); realBind(pos, MYSQL_TYPE_LONG, &val, 0, true); } #endif // POCO_LONG_IS_64_BIT void Binder::bind(std::size_t pos, const bool& val, Direction dir) { poco_assert(dir == PD_IN); realBind(pos, MYSQL_TYPE_TINY, &val, 0); } void Binder::bind(std::size_t pos, const float& val, Direction dir) { poco_assert(dir == PD_IN); realBind(pos, MYSQL_TYPE_FLOAT, &val, 0); } void Binder::bind(std::size_t pos, const double& val, Direction dir) { poco_assert(dir == PD_IN); realBind(pos, MYSQL_TYPE_DOUBLE, &val, 0); } void Binder::bind(std::size_t pos, const char& val, Direction dir) { poco_assert(dir == PD_IN); realBind(pos, MYSQL_TYPE_TINY, &val, 0); } void Binder::bind(std::size_t pos, const std::string& val, Direction dir) { poco_assert(dir == PD_IN); realBind(pos, MYSQL_TYPE_STRING, val.c_str(), static_cast(val.length())); } void Binder::bind(std::size_t pos, const Poco::Data::BLOB& val, Direction dir) { poco_assert(dir == PD_IN); realBind(pos, MYSQL_TYPE_BLOB, val.rawContent(), static_cast(val.size())); } void Binder::bind(std::size_t pos, const Poco::Data::CLOB& val, Direction dir) { poco_assert(dir == PD_IN); realBind(pos, MYSQL_TYPE_BLOB, val.rawContent(), static_cast(val.size())); } void Binder::bind(std::size_t pos, const DateTime& val, Direction dir) { poco_assert(dir == PD_IN); MYSQL_TIME mt = {0}; mt.year = val.year(); mt.month = val.month(); mt.day = val.day(); mt.hour = val.hour(); mt.minute = val.minute(); mt.second = val.second(); mt.second_part = val.millisecond() * 1000 + val.microsecond(); mt.time_type = MYSQL_TIMESTAMP_DATETIME; _dates.push_back(new MYSQL_TIME(mt)); realBind(pos, MYSQL_TYPE_DATETIME, _dates.back(), sizeof(MYSQL_TIME)); } void Binder::bind(std::size_t pos, const Date& val, Direction dir) { poco_assert(dir == PD_IN); MYSQL_TIME mt = {0}; mt.year = val.year(); mt.month = val.month(); mt.day = val.day(); mt.time_type = MYSQL_TIMESTAMP_DATE; _dates.push_back(new MYSQL_TIME(mt)); realBind(pos, MYSQL_TYPE_DATE, _dates.back(), sizeof(MYSQL_TIME)); } void Binder::bind(std::size_t pos, const Time& val, Direction dir) { poco_assert(dir == PD_IN); MYSQL_TIME mt = {0}; mt.hour = val.hour(); mt.minute = val.minute(); mt.second = val.second(); mt.time_type = MYSQL_TIMESTAMP_TIME; _dates.push_back(new MYSQL_TIME(mt)); realBind(pos, MYSQL_TYPE_TIME, _dates.back(), sizeof(MYSQL_TIME)); } void Binder::bind(std::size_t pos, const NullData&, Direction dir) { poco_assert(dir == PD_IN); realBind(pos, MYSQL_TYPE_NULL, 0, 0); } std::size_t Binder::size() const { return static_cast(_bindArray.size()); } MYSQL_BIND* Binder::getBindArray() const { if (_bindArray.size() == 0) { return 0; } return const_cast(&_bindArray[0]); } /*void Binder::updateDates() { for (std::size_t i = 0; i < _dates.size(); i++) { switch (_dates[i].mt.time_type) { case MYSQL_TIMESTAMP_DATE: _dates[i].mt.year = _dates[i].link.date->year(); _dates[i].mt.month = _dates[i].link.date->month(); _dates[i].mt.day = _dates[i].link.date->day(); break; case MYSQL_TIMESTAMP_DATETIME: _dates[i].mt.year = _dates[i].link.dateTime->year(); _dates[i].mt.month = _dates[i].link.dateTime->month(); _dates[i].mt.day = _dates[i].link.dateTime->day(); _dates[i].mt.hour = _dates[i].link.dateTime->hour(); _dates[i].mt.minute = _dates[i].link.dateTime->minute(); _dates[i].mt.second = _dates[i].link.dateTime->second(); _dates[i].mt.second_part = _dates[i].link.dateTime->millisecond(); break; case MYSQL_TIMESTAMP_TIME: _dates[i].mt.hour = _dates[i].link.time->hour(); _dates[i].mt.minute = _dates[i].link.time->minute(); _dates[i].mt.second = _dates[i].link.time->second(); break; } } }*/ /////////////////// // // Private // //////////////////// void Binder::realBind(std::size_t pos, enum_field_types type, const void* buffer, int length, bool isUnsigned) { if (pos >= _bindArray.size()) { std::size_t s = static_cast(_bindArray.size()); _bindArray.resize(pos + 1); std::memset(&_bindArray[s], 0, sizeof(MYSQL_BIND) * (_bindArray.size() - s)); } MYSQL_BIND b = {0}; b.buffer_type = type; b.buffer = const_cast(buffer); b.buffer_length = length; b.is_unsigned = isUnsigned; _bindArray[pos] = b; } void Binder::bind(std::size_t pos, const std::vector& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::deque& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::list& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::vector& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::deque& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::list& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::vector& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::deque& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::list& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::vector& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::deque& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::list& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::vector& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::deque& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::list& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::vector& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::deque& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::list& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::vector& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::deque& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::list& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::vector& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::deque& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::list& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::vector& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::deque& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::list& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::vector& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::deque& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::list& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::vector& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::deque& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::list& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::vector& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::deque& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::list& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::vector& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::deque& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::list& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::vector& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::deque& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::list& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::vector& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::deque& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::list& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::vector& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::deque& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::list& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::vector& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::deque& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::list& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::vector& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::deque& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::list& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::vector& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::deque& val, Direction dir) { throw NotImplementedException(); } void Binder::bind(std::size_t pos, const std::list& val, Direction dir) { throw NotImplementedException(); } } } } // namespace Poco::Data::MySQL