From f98ecb7ea6a64b02d2a28cd15e865afa76342327 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 23 May 2021 00:17:24 +0100 Subject: Add PQ basics --- lib/output/pq/pqConn.cpp | 27 +++++++++++++++++++++++++++ lib/output/pq/pqConn.h | 20 ++++++++++++++++++++ lib/output/pq/updateDatabase.cpp | 8 ++++++++ lib/output/pq/updateDatabase.h | 17 +++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 lib/output/pq/pqConn.cpp create mode 100644 lib/output/pq/pqConn.h create mode 100644 lib/output/pq/updateDatabase.cpp create mode 100644 lib/output/pq/updateDatabase.h (limited to 'lib') diff --git a/lib/output/pq/pqConn.cpp b/lib/output/pq/pqConn.cpp new file mode 100644 index 0000000..78cdc06 --- /dev/null +++ b/lib/output/pq/pqConn.cpp @@ -0,0 +1,27 @@ +#include "pqConn.h" +#include +#include + +namespace MyGrate::Output::Pq { + PqConn::PqConn(const char * const str) : conn {PQconnectdb(str)} + { + verify(PQstatus(conn) == CONNECTION_OK, "Connection failure"); + PQsetNoticeProcessor(conn, notice_processor, this); + } + + PqConn::~PqConn() + { + PQfinish(conn); + } + + void + PqConn::notice_processor(void * p, const char * n) + { + return static_cast(p)->notice_processor(n); + } + + void + PqConn::notice_processor(const char *) const + { + } +} diff --git a/lib/output/pq/pqConn.h b/lib/output/pq/pqConn.h new file mode 100644 index 0000000..bcf30b6 --- /dev/null +++ b/lib/output/pq/pqConn.h @@ -0,0 +1,20 @@ +#ifndef MYGRATE_OUTPUT_PQ_PQCONN_H +#define MYGRATE_OUTPUT_PQ_PQCONN_H + +#include + +namespace MyGrate::Output::Pq { + class PqConn { + public: + explicit PqConn(const char * const str); + virtual ~PqConn(); + + private: + static void notice_processor(void *, const char *); + virtual void notice_processor(const char *) const; + + PGconn * const conn; + }; +} + +#endif diff --git a/lib/output/pq/updateDatabase.cpp b/lib/output/pq/updateDatabase.cpp new file mode 100644 index 0000000..77a9ce5 --- /dev/null +++ b/lib/output/pq/updateDatabase.cpp @@ -0,0 +1,8 @@ +#include "updateDatabase.h" +#include "pqConn.h" +#include +#include + +namespace MyGrate::Output::Pq { + UpdateDatabase::UpdateDatabase(const char * const str, std::string p) : PqConn {str}, prefix {std::move(p)} { } +} diff --git a/lib/output/pq/updateDatabase.h b/lib/output/pq/updateDatabase.h new file mode 100644 index 0000000..bc54282 --- /dev/null +++ b/lib/output/pq/updateDatabase.h @@ -0,0 +1,17 @@ +#ifndef MYGRATE_OUTPUT_PQ_UPDATEDATABASE_H +#define MYGRATE_OUTPUT_PQ_UPDATEDATABASE_H + +#include "pqConn.h" +#include + +namespace MyGrate::Output::Pq { + class UpdateDatabase : PqConn { + public: + UpdateDatabase(const char * const str, std::string prefix); + + private: + std::string prefix; + }; +} + +#endif -- cgit v1.2.3