-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStatement.h
More file actions
95 lines (78 loc) · 2.27 KB
/
Statement.h
File metadata and controls
95 lines (78 loc) · 2.27 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* File: Statement.h
* Created on 27 luglio 2018
*/
#ifndef STATEMENT_H
#define STATEMENT_H
#include <unordered_map>
#include "Transaction.h"
class Statement {
public:
// class to cache received metadata
class Field {
public:
Statement* stmt = nullptr;
unsigned type = 0;
unsigned length = 0;
unsigned offset = 0;
unsigned nullOffset= 0;
explicit operator bool() const;
int64_t asInteger() const;
double asDouble() const;
std::string asString() const;
std::string formatDate(const std::string &format = "%Y-%m-%d") const;
};
class Parameter {
public:
Statement* stmt;
unsigned type = 0;
unsigned length = 0;
unsigned offset = 0;
unsigned nullOffset= 0;
explicit operator bool() const;
void setInt(uint64_t v);
void setDouble(double v);
void setText(const char* v);
void setNull();
};
Statement();
void setSql(std::string sql);
void setTransaction(Transaction* transaction);
Field fieldByName(const char* name);
Field field(unsigned int idx);
Parameter paramByName(const char* name);
Parameter parameter(unsigned int idx);
virtual ~Statement();
void open();
void execute();
void close();
void reset();
bool fetch();
bool bof();
bool eof();
void next();
uint64_t getAffectedRecords();
private:
void checkTransaction();
void prepare();
void initParametersByName();
void release();
Parameter* parameters = nullptr;
std::unordered_map<std::string, unsigned int> namedParameters;
unsigned int parametersCount = 0;
unsigned char* parametersValueBuffer = nullptr;
Field* fields = nullptr;
std::unordered_map<std::string, unsigned int> namedFields;
unsigned int fieldsCount = 0;
unsigned char* fieldsValueBuffer = nullptr;
std::string sql;
Transaction* transaction;
IStatement* stmt_ = nullptr;
ThrowStatusWrapper* status = nullptr;
IResultSet* resSet_ = nullptr;
IMessageMetadata* inMeta = nullptr;
IMessageMetadata* outMeta = nullptr;
bool isPrepared = false;
EventDispatcher<DBStateEvents>::CBID transactionCallbackID;
};
#endif /* STATEMENT_H */