From 5378ffd0aca410c50887fee57899776e62bfb766 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 8 Aug 2021 12:48:37 +0100 Subject: Extract WritePqCopyStrm into its own file --- lib/output/pq/updateDatabase.cpp | 97 ++------------------------------------- lib/output/pq/writePqCopyStrm.cpp | 82 +++++++++++++++++++++++++++++++++ lib/output/pq/writePqCopyStrm.h | 38 +++++++++++++++ 3 files changed, 123 insertions(+), 94 deletions(-) create mode 100644 lib/output/pq/writePqCopyStrm.cpp create mode 100644 lib/output/pq/writePqCopyStrm.h (limited to 'lib/output') diff --git a/lib/output/pq/updateDatabase.cpp b/lib/output/pq/updateDatabase.cpp index 46641fc..485c914 100644 --- a/lib/output/pq/updateDatabase.cpp +++ b/lib/output/pq/updateDatabase.cpp @@ -1,6 +1,7 @@ #include "updateDatabase.h" #include "pqConn.h" #include "typeMapper.h" +#include "writePqCopyStrm.h" #include #include #include @@ -129,99 +130,6 @@ namespace MyGrate::Output::Pq { }); } - struct WritePqCopyStream { - explicit WritePqCopyStream(FILE * o) : out {o} { } - WritePqCopyStream(const WritePqCopyStream &) = delete; - WritePqCopyStream(WritePqCopyStream &&) = delete; - WritePqCopyStream & operator=(const WritePqCopyStream &) = delete; - WritePqCopyStream & operator=(WritePqCopyStream &&) = delete; - - ~WritePqCopyStream() - { - fputc('\n', out); - } - - void - nextField() - { - fputc('\t', out); - } - - void operator()(std::nullptr_t) const - { - fputs("\\N", out); - } -#define BASIC_PRINT(T, fmt) \ - void operator()(T v) const \ - { \ - fprintf(out, fmt, v); \ - } - BASIC_PRINT(double, "%f") - BASIC_PRINT(float, "%f") - BASIC_PRINT(int8_t, "%hhd") - BASIC_PRINT(uint8_t, "%hhu") - BASIC_PRINT(int16_t, "%hd") - BASIC_PRINT(uint16_t, "%hu") - BASIC_PRINT(int32_t, "%d") - BASIC_PRINT(uint32_t, "%u") - BASIC_PRINT(int64_t, "%ld") - BASIC_PRINT(uint64_t, "%lu") -#undef BASIC_PRINT - void operator()(timespec) const - { - throw std::logic_error("timespec not implemented"); - } - void - operator()(Date v) const - { - fprintf(out, "%d-%d-%d", v.year, v.month, v.day); - } - void - operator()(Time v) const - { - fprintf(out, "%d:%d:%d", v.hour, v.minute, v.second); - } - void - operator()(DateTime v) const - { - operator()(static_cast(v)); - fputc('T', out); - operator()(static_cast