#include "pqConn.h" #include "pqBindings.h" #include "pqStmt.h" #include #include #include #include #include #include #include #include namespace MyGrate::Output::Pq { PqConn::PqConn(const char * const str) : conn {PQconnectdb(str), PQfinish} { verify(PQstatus(conn.get()) == CONNECTION_OK, "Connection failure"); PQsetNoticeProcessor(conn.get(), notice_processor, this); } void PqConn::query(const char * const q) { ResPtr res {PQexec(conn.get(), q), &PQclear}; verify(PQresultStatus(res.get()) == PGRES_COMMAND_OK, q); } void PqConn::query(const char * const q, const std::initializer_list & vs) { Bindings b {vs}; ResPtr res {PQexecParams(conn.get(), q, (int)vs.size(), nullptr, b.values.data(), b.lengths.data(), nullptr, 0), &PQclear}; verify(PQresultStatus(res.get()) == PGRES_COMMAND_OK, q); } DbPrepStmtPtr PqConn::prepare(const char * const q, std::size_t n) { return std::make_unique(q, n, this); } void PqConn::notice_processor(void * p, const char * n) { return static_cast(p)->notice_processor(n); } void PqConn::notice_processor(const char *) const { } }