blob: 3b27f97afdd60411720bab30644419a22026ab3d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#ifndef MYGRATE_OUTPUT_PQ_PQCONN_H
#define MYGRATE_OUTPUT_PQ_PQCONN_H
#include <cstddef>
#include <dbConn.h>
#include <functional>
#include <initializer_list>
#include <libpq-fe.h>
#include <map>
#include <memory>
#include <string>
namespace MyGrate {
class DbValue;
}
namespace MyGrate::Output::Pq {
class PqErr : public std::runtime_error {
public:
PqErr(const std::string & when, PGconn *);
PqErr(const std::string & when, PGresult *);
};
class PqConn : public DbConn {
public:
static constexpr auto paramMode {ParamMode::DollarNum};
explicit PqConn(const char * const str);
virtual ~PqConn() = default;
void query(const char * const) override;
void query(const char * const, const std::initializer_list<DbValue> &) override;
DbPrepStmtPtr prepare(const char * const, std::size_t nParams) override;
void beginTx() override;
void commitTx() override;
void rollbackTx() override;
const std::string connstr;
private:
static void notice_processor(void *, const char *);
virtual void notice_processor(const char *) const;
std::unique_ptr<PGconn, decltype(&PQfinish)> const conn;
friend class PqPrepStmt;
std::map<std::string, std::string, std::less<>> stmts;
};
}
#endif
|