diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-05-23 00:17:24 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-05-23 00:17:24 +0100 |
commit | f98ecb7ea6a64b02d2a28cd15e865afa76342327 (patch) | |
tree | 102e8431d3facb74225a575e582bb372e53ff4d1 /lib | |
parent | IWYU built for LLVM-12 fixes (diff) | |
download | mygrate-f98ecb7ea6a64b02d2a28cd15e865afa76342327.tar.bz2 mygrate-f98ecb7ea6a64b02d2a28cd15e865afa76342327.tar.xz mygrate-f98ecb7ea6a64b02d2a28cd15e865afa76342327.zip |
Add PQ basics
Diffstat (limited to 'lib')
-rw-r--r-- | lib/output/pq/pqConn.cpp | 27 | ||||
-rw-r--r-- | lib/output/pq/pqConn.h | 20 | ||||
-rw-r--r-- | lib/output/pq/updateDatabase.cpp | 8 | ||||
-rw-r--r-- | lib/output/pq/updateDatabase.h | 17 |
4 files changed, 72 insertions, 0 deletions
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 <helpers.h> +#include <stdexcept> + +namespace MyGrate::Output::Pq { + PqConn::PqConn(const char * const str) : conn {PQconnectdb(str)} + { + verify<std::runtime_error>(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<PqConn *>(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 <libpq-fe.h> + +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 <string> +#include <utility> + +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 <string> + +namespace MyGrate::Output::Pq { + class UpdateDatabase : PqConn { + public: + UpdateDatabase(const char * const str, std::string prefix); + + private: + std::string prefix; + }; +} + +#endif |