summaryrefslogtreecommitdiff
path: root/lib/output/pq/pqStmt.h
blob: 887a326111dbdef4f1bbef1ad6c4c44d05a8961c (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
#ifndef MYGRATE_OUTPUT_PQ_PQSTMT_H
#define MYGRATE_OUTPUT_PQ_PQSTMT_H

#include "dbConn.h"
#include "dbRecordSet.h"
#include <cstddef>
#include <initializer_list>
#include <libpq-fe.h>
#include <memory>
#include <string>

namespace MyGrate {
	class DbValue;
}
namespace MyGrate::Output::Pq {
	class PqConn;

	using ResPtr = std::unique_ptr<PGresult, decltype(&PQclear)>;

	class PqPrepStmt : public DbPrepStmt {
	public:
		PqPrepStmt(const char * const q, std::size_t n, PqConn * c);

		void execute(const std::initializer_list<DbValue> & vs) override;

		std::size_t rows() const override;

		RecordSetPtr recordSet() override;

		CursorPtr cursor() override;

	private:
		static std::string prepareAsNeeded(const char * const q, std::size_t n, PqConn * c);

		PGconn * conn;
		std::string name;
		ResPtr res;
	};
}

#endif