#include "postgres_parameter_binder.h" #include "matador/utils/string.hpp" #include namespace matador::backends::postgres { namespace detail { template void bind_value(postgres_parameter_binder::bind_data &data, const size_t index, const T &x) { data.strings[index] = std::to_string(x); data.values[index] = data.strings[index].c_str(); data.lengths[index] = static_cast(data.strings[index].size()); data.formats[index] = 0; } // template<> // void bind_value(postgres_parameter_binder::bind_data &data, size_t index, const char &x) { // data.strings[index] = std::to_string(x); // data.values[index] = data.strings[index].data(); // data.formats[index] = 0; // } // template<> // void bind_value(postgres_parameter_binder::bind_data &data, size_t index, const unsigned char &x) { // data.strings[index] = std::to_string(x); // data.values[index] = data.strings[index].data(); // data.formats[index] = 0; // } //template <> //void bind_value(std::vector &strings, std::vector ¶ms, size_t &index, const matador::date &x) //{ // strings[index] = matador::to_string(x, date_format::ISO8601); // params[index] = strings[index].c_str(); // ++index; //} // //template <> //void bind_value(std::vector &strings, std::vector ¶ms, size_t &index, const matador::time &x) //{ // strings[index] = matador::to_string(x, "%Y-%m-%d %T.%f"); // params[index] = strings[index].c_str(); // ++index; //} } postgres_parameter_binder::bind_data::bind_data(const size_t size) : strings(size) , bytes(size) , values(size) , lengths(size) , formats(size) {} postgres_parameter_binder::postgres_parameter_binder(size_t size) : bind_data_(size) {} void postgres_parameter_binder::write_value(const size_t pos, const int8_t &x) { detail::bind_value(bind_data_, pos, x); } void postgres_parameter_binder::write_value(const size_t pos, const int16_t &x) { detail::bind_value(bind_data_, pos, x); } void postgres_parameter_binder::write_value(const size_t pos, const int32_t &x) { detail::bind_value(bind_data_, pos, x); } void postgres_parameter_binder::write_value(const size_t pos, const int64_t &x) { detail::bind_value(bind_data_, pos, x); } void postgres_parameter_binder::write_value(const size_t pos, const uint8_t &x) { detail::bind_value(bind_data_, pos, x); } void postgres_parameter_binder::write_value(const size_t pos, const uint16_t &x) { detail::bind_value(bind_data_, pos, x); } void postgres_parameter_binder::write_value(const size_t pos, const uint32_t &x) { detail::bind_value(bind_data_, pos, x); } void postgres_parameter_binder::write_value(const size_t pos, const uint64_t &x) { detail::bind_value(bind_data_, pos, x); } void postgres_parameter_binder::write_value(const size_t pos, const bool &x) { detail::bind_value(bind_data_, pos, x); } void postgres_parameter_binder::write_value(const size_t pos, const float &x) { detail::bind_value(bind_data_, pos, x); } void postgres_parameter_binder::write_value(const size_t pos, const double &x) { detail::bind_value(bind_data_, pos, x); } void postgres_parameter_binder::write_value(const size_t pos, const char *x) { bind_data_.values[pos] = x; bind_data_.lengths[pos] = static_cast(std::strlen(x)); bind_data_.formats[pos] = 0; } void postgres_parameter_binder::write_value(const size_t pos, const char *x, size_t /*size*/) { bind_data_.values[pos] = x; bind_data_.lengths[pos] = static_cast(std::strlen(x)); bind_data_.formats[pos] = 0; } void postgres_parameter_binder::write_value(const size_t pos, const std::string &x) { bind_data_.values[pos] = x.data(); bind_data_.lengths[pos] = static_cast(x.size()); bind_data_.formats[pos] = 0; } void postgres_parameter_binder::write_value(const size_t pos, const std::string &x, size_t /*size*/) { write_value(pos, x); } void postgres_parameter_binder::write_value(const size_t pos, const time &/*x*/) { // bind_data_.strings[pos] = utils::to_string(x, "%Y-%m-%d %T.%f"); bind_data_.values[pos] = bind_data_.strings[pos].data(); bind_data_.lengths[pos] = static_cast(bind_data_.strings[pos].size()); bind_data_.formats[pos] = 0; } void postgres_parameter_binder::write_value(const size_t pos, const date &/*x*/) { // bind_data_.strings[pos] = utils::to_string(x, utils::date_format::ISO8601); bind_data_.values[pos] = bind_data_.strings[pos].data(); bind_data_.lengths[pos] = static_cast(bind_data_.strings[pos].size()); bind_data_.formats[pos] = 0; } void postgres_parameter_binder::write_value(const size_t pos, const utils::blob &x) { bind_data_.bytes[pos] = x; bind_data_.values[pos] = reinterpret_cast(bind_data_.bytes[pos].data()); bind_data_.lengths[pos] = static_cast(bind_data_.bytes[pos].size()); bind_data_.formats[pos] = 1; } void postgres_parameter_binder::write_value(const size_t /*pos*/, const utils::value &/*x*/, size_t /*size*/) {} const postgres_parameter_binder::bind_data &postgres_parameter_binder::params() const { return bind_data_; } }