-
Notifications
You must be signed in to change notification settings - Fork 145
/
Query.h
107 lines (79 loc) · 2.22 KB
/
Query.h
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
95
96
97
98
99
100
101
102
103
104
105
106
107
#ifndef CQUERY_H_
#define CQUERY_H_
#include "Interface/Query.h"
#include "Interface/Mutex.h"
#include "Interface/SharedMutex.h"
#include <memory>
struct sqlite3_stmt;
struct sqlite3;
class CDatabase;
class DatabaseCursor;
#define LOG_WRITE_QUERIES
#define LOG_READ_QUERIES
#if defined(LOG_WRITE_QUERIES) || defined(LOG_READ_QUERIES)
#define LOG_QUERIES
#endif
class ScopedAddActiveQuery;
class CQuery : public IQuery
{
public:
CQuery(const std::string &pStmt_str, sqlite3_stmt *prepared_statement, CDatabase *pDB);
~CQuery();
static void init_mutex(void);
virtual void Bind(const std::string &str);
virtual void Bind(int p);
virtual void Bind(unsigned int p);
virtual void Bind(double p);
virtual void Bind(int64 p);
#if defined(_WIN64) || defined(_LP64)
virtual void Bind(size_t p);
#endif
virtual void Bind(const char* buffer, _u32 bsize);
virtual void Reset(void);
virtual bool Write(int timeoutms=-1);
db_results Read(int *timeoutms=NULL);
virtual IDatabaseCursor* Cursor(int *timeoutms=NULL);
void setupStepping(int *timeoutms, bool with_read_lock);
void shutdownStepping(int err, int *timeoutms, bool& transaction_lock);
int step(db_single_result& res, int *timeoutms, int& tries, bool& transaction_lock, bool& reset);
bool resultOkay(int rc);
std::string getStatement(void);
std::string getErrMsg(void);
private:
bool Execute(int timeoutms);
void addActiveQuery(const std::string& query_str);
void removeActiveQuery(const std::string& query_str);
void showActiveQueries(int loglevel);
sqlite3_stmt *ps;
std::string stmt_str;
CDatabase *db;
int curr_idx;
DatabaseCursor *cursor;
#ifdef LOG_QUERIES
static IMutex* active_mutex;
static std::vector<std::string> active_queries;
#endif
std::unique_ptr<IScopedReadLock> single_use_lock;
friend class ScopedAddActiveQuery;
};
class CQuery;
class ScopedAddActiveQuery
{
public:
ScopedAddActiveQuery(CQuery* query)
: query(query)
{
#ifdef LOG_QUERIES
query->addActiveQuery(query->stmt_str);
#endif
}
~ScopedAddActiveQuery()
{
#ifdef LOG_QUERIES
query->removeActiveQuery(query->stmt_str);
#endif
}
private:
CQuery* query;
};
#endif //CQUERY_H_