forked from roba269/wai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_wrapper.h
More file actions
47 lines (44 loc) · 934 Bytes
/
db_wrapper.h
File metadata and controls
47 lines (44 loc) · 934 Bytes
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
#ifndef DB_WRAPPER_H
#define DB_WRAPPER_H
#include <cassert>
#include "mysql.h"
class DBWrapper {
public:
/*
static DBWrapper *GetInstance() {
if (s_wrapper == NULL) {
s_wrapper = new DBWrapper();
s_wrapper->InitInstance();
}
return s_wrapper;
}
*/
DBWrapper() {
InitInstance();
}
~DBWrapper() {
DestroyInstance();
}
static void DestroyInstance() {
mysql_close(s_mysql_handle);
s_mysql_handle = NULL;
// if (s_wrapper)
// delete s_wrapper;
}
/*
int Query(const char *str);
MYSQL_ROW FetchRow();
int FreeResult();
*/
static MYSQL *GetHandle() {
// FIXME: mutex?
if (s_mysql_handle == NULL) {
InitInstance();
}
return s_mysql_handle;
}
private:
static void InitInstance();
static MYSQL *s_mysql_handle;
};
#endif