blob: ffdd2e0b3189380ef2f46bcdb43b58385ddb8518 (
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_DBCONN_H
#define MYGRATE_DBCONN_H
#include <dbRecordSet.h>
#include <dbTypes.h>
#include <initializer_list>
namespace MyGrate {
class DbPrepStmt {
public:
virtual ~DbPrepStmt() = default;
virtual void execute(const std::initializer_list<DbValue> &) = 0;
virtual std::size_t rows() const = 0;
virtual RecordSetPtr recordSet() = 0;
};
using DbPrepStmtPtr = std::unique_ptr<DbPrepStmt>;
enum class ParamMode { None, DollarNum, QMark };
class DbConn {
public:
virtual ~DbConn() = default;
virtual void query(const char * const) = 0;
virtual void query(const char * const, const std::initializer_list<DbValue> &) = 0;
virtual DbPrepStmtPtr prepare(const char * const, std::size_t nParams) = 0;
virtual void beginTx() = 0;
virtual void commitTx() = 0;
virtual void rollbackTx() = 0;
};
class Tx {
public:
explicit Tx(DbConn *);
Tx(const Tx &) = delete;
Tx(Tx &&) = delete;
~Tx();
template<typename C>
auto
operator()(C && callback)
{
return callback();
}
private:
DbConn * conn;
};
}
#endif
|