diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-05-31 13:18:17 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-05-31 13:18:17 +0100 |
commit | 63b2ca0dbdae190941d60a55c9cff99d4a75a0e1 (patch) | |
tree | d3766bcbc98fb5fb0fb2d8dddf2f194bedcb0325 /lib/output/pq/pqBindings.h | |
parent | Map std::size_t to a sensible header (diff) | |
download | mygrate-63b2ca0dbdae190941d60a55c9cff99d4a75a0e1.tar.bz2 mygrate-63b2ca0dbdae190941d60a55c9cff99d4a75a0e1.tar.xz mygrate-63b2ca0dbdae190941d60a55c9cff99d4a75a0e1.zip |
Initial commit of prepstmt, selects, record sets
This is full of holes, but all the basics are covered.
Diffstat (limited to 'lib/output/pq/pqBindings.h')
-rw-r--r-- | lib/output/pq/pqBindings.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/output/pq/pqBindings.h b/lib/output/pq/pqBindings.h new file mode 100644 index 0000000..ef0df84 --- /dev/null +++ b/lib/output/pq/pqBindings.h @@ -0,0 +1,57 @@ +#ifndef MYGRATE_OUTPUT_PQ_PQBINDINGS +#define MYGRATE_OUTPUT_PQ_PQBINDINGS + +#include <dbTypes.h> +#include <helpers.h> +#include <initializer_list> +#include <variant> +#include <vector> + +namespace MyGrate::Output::Pq { + struct Bindings { + // NOLINTNEXTLINE(hicpp-explicit-conversions) + explicit Bindings(const std::initializer_list<DbValue> & vs) + { + bufs.reserve(vs.size()); + values.reserve(vs.size()); + lengths.reserve(vs.size()); + for (const auto & v : vs) { + std::visit(*this, v); + } + } + template<Stringable T> + void + operator()(const T & v) + { + bufs.emplace_back(std::to_string(v)); + const auto & vw {bufs.back()}; + values.emplace_back(vw.data()); + lengths.emplace_back(vw.length()); + } + template<Viewable T> + void + operator()(const T & v) + { + values.emplace_back(v.data()); + lengths.emplace_back(v.size()); + } + template<typename T> + void + operator()(const T &) + { + throw std::runtime_error("Not implemented"); + } + void + operator()(const std::nullptr_t &) + { + values.emplace_back(nullptr); + lengths.emplace_back(0); + } + + std::vector<std::string> bufs; + std::vector<const char *> values; + std::vector<int> lengths; + }; +} + +#endif |