-
Notifications
You must be signed in to change notification settings - Fork 3
/
db_conn.h
55 lines (38 loc) · 907 Bytes
/
db_conn.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
#ifndef __DB_CONN_H__
#define __DB_CONN_H__
#include <mysql.h>
#include <map>
#include <string>
#include "util.h"
#include "logger.h"
using namespace pluto;
class CResultSet
{
public:
typedef map<string, int> KeyMap;
CResultSet(MYSQL_RES* res);
virtual ~CResultSet();
bool Next();
int GetInt(const char* key);
char* GetString(const char* key);
KeyMap& GetKeyMap(){return key_map_;}
private:
int _GetIndex(const char* key);
MYSQL_RES* res_;
MYSQL_ROW row_;
KeyMap key_map_;
};
class CDBConn
{
public:
CDBConn();
virtual ~CDBConn();
int Init(const char* host, const char* user, const char* passwd, const char* db, unsigned int port);
CResultSet* ExecuteQuery(const char* sql_query);
bool ExecuteUpdate(const char* sql_query);
uint32_t GetInsertId();
MYSQL* GetMysql(){return mysql_;}
private:
MYSQL* mysql_;
};
#endif