#ifndef MYGRATE_INPUT_MYSQLBINDINGS_H #define MYGRATE_INPUT_MYSQLBINDINGS_H #include #include #include #include #include #include #include #include namespace MyGrate::Input { struct BingingData { explicit BingingData(unsigned long l, my_bool n = 0) : len {l}, null {n} { } unsigned long len; my_bool null; }; MYSQL_TIME & operator<<(MYSQL_TIME & t, const Date &); MYSQL_TIME & operator<<(MYSQL_TIME & t, const Time &); MYSQL_TIME & operator<<(MYSQL_TIME & t, const DateTime & dt); struct Bindings { struct Buffer { virtual ~Buffer() = default; }; template struct BufferOf : public Buffer { template BufferOf(const S & src) : val {} { val << src; } T val; }; explicit Bindings(const std::span vs) { binds.reserve(vs.size()); data.reserve(vs.size()); for (const auto & v : vs) { v.visit(*this); } } template void operator()(const T & v) { auto & b = binds.emplace_back(); b.buffer_type = MySQL::CType::type; b.buffer = const_cast(&v); b.is_unsigned = std::unsigned_integral; } template void operator()(const T & v) { auto & b = binds.emplace_back(); b.buffer_type = MySQL::CType::type; b.buffer = const_cast(&v); } template void operator()(const T & v) { auto & b = binds.emplace_back(); b.buffer_type = MySQL::CType::type; b.buffer = const_cast(v.data()); b.length = &data.emplace_back(v.size(), 0).len; } void operator()(const std::nullptr_t &) { auto & b = binds.emplace_back(); b.buffer = nullptr; b.is_null = &data.emplace_back(0, 1).null; } void operator()(const DateTime & dt) { auto & b = binds.emplace_back(); auto t = std::make_unique>(dt); b.buffer_type = MySQL::CType::type; b.buffer = &t->val; b.buffer_length = sizeof(t->val); buffers.push_back(std::move(t)); } void operator()(const Time & dt) { auto & b = binds.emplace_back(); auto t = std::make_unique>(dt); b.buffer_type = MySQL::CType