initial matador ng commit
This commit is contained in:
@@ -1,29 +1,32 @@
|
||||
#include "postgres_parameter_binder.h"
|
||||
|
||||
#include "matador/utils/string.hpp"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace matador::backends::postgres {
|
||||
|
||||
namespace detail {
|
||||
|
||||
template < class T >
|
||||
void bind_value(std::vector<std::string> &strings, std::vector<const char*> ¶ms, size_t index, T &x)
|
||||
{
|
||||
strings[index] = std::to_string(x);
|
||||
params[index] = strings[index].c_str();
|
||||
template<class T>
|
||||
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<int>(data.strings[index].size());
|
||||
data.formats[index] = 0;
|
||||
}
|
||||
|
||||
template <>
|
||||
void bind_value(std::vector<std::string> &strings, std::vector<const char*> ¶ms, size_t index, char &x)
|
||||
{
|
||||
strings[index] = std::to_string(x);
|
||||
params[index] = strings[index].data();
|
||||
}
|
||||
// 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(std::vector<std::string> &strings, std::vector<const char*> ¶ms, size_t index, unsigned char &x)
|
||||
{
|
||||
strings[index] = std::to_string(x);
|
||||
params[index] = strings[index].data();
|
||||
}
|
||||
// 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<std::string> &strings, std::vector<const char*> ¶ms, size_t &index, const matador::date &x)
|
||||
@@ -40,108 +43,111 @@ void bind_value(std::vector<std::string> &strings, std::vector<const char*> &par
|
||||
// params[index] = strings[index].c_str();
|
||||
// ++index;
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
postgres_parameter_binder::postgres_parameter_binder(size_t size)
|
||||
: strings_(size)
|
||||
, params_(size)
|
||||
postgres_parameter_binder::bind_data::bind_data(const size_t size)
|
||||
: strings(size)
|
||||
, bytes(size)
|
||||
, values(size)
|
||||
, lengths(size)
|
||||
, formats(size)
|
||||
{}
|
||||
|
||||
void postgres_parameter_binder::bind(size_t pos, char i)
|
||||
{
|
||||
detail::bind_value(strings_, params_, pos, i);
|
||||
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::bind(size_t pos, short i)
|
||||
{
|
||||
detail::bind_value(strings_, params_, pos, i);
|
||||
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::bind(size_t pos, int i)
|
||||
{
|
||||
detail::bind_value(strings_, params_, pos, i);
|
||||
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::bind(size_t pos, long i)
|
||||
{
|
||||
detail::bind_value(strings_, params_, pos, i);
|
||||
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::bind(size_t pos, long long int i)
|
||||
{
|
||||
detail::bind_value(strings_, params_, pos, i);
|
||||
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::bind(size_t pos, unsigned char i)
|
||||
{
|
||||
detail::bind_value(strings_, params_, pos, i);
|
||||
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::bind(size_t pos, unsigned short i)
|
||||
{
|
||||
detail::bind_value(strings_, params_, pos, i);
|
||||
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::bind(size_t pos, unsigned int i)
|
||||
{
|
||||
detail::bind_value(strings_, params_, pos, i);
|
||||
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::bind(size_t pos, unsigned long i)
|
||||
{
|
||||
detail::bind_value(strings_, params_, pos, i);
|
||||
void postgres_parameter_binder::write_value(const size_t pos, const bool &x) {
|
||||
detail::bind_value(bind_data_, pos, x);
|
||||
}
|
||||
|
||||
void postgres_parameter_binder::bind(size_t pos, unsigned long long int i)
|
||||
{
|
||||
detail::bind_value(strings_, params_, pos, i);
|
||||
void postgres_parameter_binder::write_value(const size_t pos, const float &x) {
|
||||
detail::bind_value(bind_data_, pos, x);
|
||||
}
|
||||
|
||||
void postgres_parameter_binder::bind(size_t pos, bool b)
|
||||
{
|
||||
detail::bind_value(strings_, params_, pos, b);
|
||||
void postgres_parameter_binder::write_value(const size_t pos, const double &x) {
|
||||
detail::bind_value(bind_data_, pos, x);
|
||||
}
|
||||
|
||||
void postgres_parameter_binder::bind(size_t pos, float d)
|
||||
{
|
||||
detail::bind_value(strings_, params_, pos, d);
|
||||
void postgres_parameter_binder::write_value(const size_t pos, const char *x) {
|
||||
bind_data_.values[pos] = x;
|
||||
bind_data_.lengths[pos] = static_cast<int>(std::strlen(x));
|
||||
bind_data_.formats[pos] = 0;
|
||||
}
|
||||
|
||||
void postgres_parameter_binder::bind(size_t pos, double d)
|
||||
{
|
||||
detail::bind_value(strings_, params_, pos, d);
|
||||
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<int>(std::strlen(x));
|
||||
bind_data_.formats[pos] = 0;
|
||||
}
|
||||
|
||||
void postgres_parameter_binder::bind(size_t pos, const char *str)
|
||||
{
|
||||
params_[pos] = str;
|
||||
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<int>(x.size());
|
||||
bind_data_.formats[pos] = 0;
|
||||
}
|
||||
|
||||
void postgres_parameter_binder::bind(size_t pos, const char *str, size_t size)
|
||||
{
|
||||
params_[pos] = str;
|
||||
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::bind(size_t pos, const std::string &str)
|
||||
{
|
||||
strings_[pos] = str;
|
||||
params_[pos] = strings_[pos].c_str();
|
||||
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<int>(bind_data_.strings[pos].size());
|
||||
bind_data_.formats[pos] = 0;
|
||||
}
|
||||
|
||||
void postgres_parameter_binder::bind(size_t pos, const std::string &str, size_t size)
|
||||
{
|
||||
bind(pos, str);
|
||||
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<int>(bind_data_.strings[pos].size());
|
||||
bind_data_.formats[pos] = 0;
|
||||
}
|
||||
|
||||
void postgres_parameter_binder::bind(size_t pos, const utils::blob &blob)
|
||||
{
|
||||
params_[pos] = "";
|
||||
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<char*>(bind_data_.bytes[pos].data());
|
||||
bind_data_.lengths[pos] = static_cast<int>(bind_data_.bytes[pos].size());
|
||||
bind_data_.formats[pos] = 1;
|
||||
}
|
||||
|
||||
const std::vector<const char *> &postgres_parameter_binder::params() const
|
||||
{
|
||||
return params_;
|
||||
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_;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user