forked from stfc2/Combat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_core.hh
85 lines (56 loc) · 1.83 KB
/
db_core.hh
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
/*
This file is part of STFC.
Copyright 2006-2007 by Michael Krauss ([email protected]) and Tobias Gafner
STFC is based on STGC,
Copyright 2003-2007 by Florian Brede ([email protected]) and Philipp Schmidt
STFC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
STFC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __DB_CORE_H__
#define __DB_CORE_H__
#include <mysql/mysql.h>
enum e_db_state { DBSTATE_UNCONNECTED, DBSTATE_CONNECTED };
class c_db_result {
private:
MYSQL_RES* result_id;
public:
MYSQL_ROW row;
c_db_result(MYSQL_RES* in_result_id);
~c_db_result();
bool fetch_row();
my_ulonglong num_rows();
};
class c_db_core {
private:
e_db_state state;
MYSQL mysql;
char* db_host;
char* db_name;
char* db_user;
char* db_passwd;
bool raise_error(char* sql);
MYSQL_RES* last_result;
public:
c_db_core();
~c_db_core();
bool init_by_str(char* in_host, char* in_name, char* in_user, char* in_passwd);
//bool init_by_lua(c_lua_base* lua_base);
//bool init_by_xml(TiXmlHandle* config_handle);
bool open();
void end();
bool query(const char* sql_line);
bool query(char* sql_line, ...);
bool query(c_db_result** in_result_var, char* sql_line, ...);
void ping();
int affected_rows();
int last_insert_id();
};
#endif