#include "dbcore.h"
|
| DBcore () |
|
| ~DBcore () |
|
void | Close () |
|
void | Initialize (std::string host, std::string user, std::string password, std::string database, bool compress=false, bool SSL=false, int16 port=3306, bool socket=false, bool reconnect=false, bool profile=false) |
|
bool | RunQuery (DBQueryResult &into, const char *query_fmt,...) |
|
bool | RunQuery (DBerror &err, const char *query_fmt,...) |
|
bool | RunQuery (DBerror &err, uint32 &affected_rows, const char *query_fmt,...) |
|
bool | RunQueryLID (DBerror &err, uint32 &last_insert_id, const char *query_fmt,...) |
|
int32 | DoEscapeString (char *tobuf, const char *frombuf, int32 fromlen) |
|
void | DoEscapeString (std::string &to, const std::string &from) |
|
void | ping () |
|
eStatus | GetStatus () const |
|
| Singleton () |
| Primary constructor. More...
|
|
Definition at line 132 of file dbcore.h.
Enumerator |
---|
Closed |
|
Connected |
|
Error |
|
Definition at line 136 of file dbcore.h.
void DBcore::Connect |
( |
uint * |
errnum = 0 , |
|
|
char * |
errbuf = 0 |
|
) |
| |
|
protected |
Definition at line 60 of file dbcore.cpp.
References DBerror::c_str(), Connected, Error, mysql, pCompress, pDatabase, pHost, pPassword, pPort, pReconnect, pSocket, pSSL, pStatus, pUser, DBerror::SetError(), sLog, and snprintf.
Referenced by Initialize(), and Reconnect().
62 sLog.Cyan(
" DB User",
" %s",
pUser.c_str());
67 enum mysql_protocol_type prot_type = MYSQL_PROTOCOL_SOCKET;
68 if (mysql_options(
mysql, MYSQL_OPT_PROTOCOL, (
void*)&prot_type) == 0) {
69 sLog.Cyan(
" DB Server",
" Unix Socket Connection");
71 sLog.Error(
" DB Server",
" Unix Socket Connection Option Failed");
72 enum mysql_protocol_type prot_type = MYSQL_PROTOCOL_TCP;
73 if (mysql_options(
mysql, MYSQL_OPT_PROTOCOL, (
void*)&prot_type) == 0)
76 sLog.Error(
" DB Server",
" TCP Connection Option Failed");
79 enum mysql_protocol_type prot_type = MYSQL_PROTOCOL_TCP;
80 if (mysql_options(
mysql, MYSQL_OPT_PROTOCOL, (
void*)&prot_type) == 0)
83 sLog.Error(
" DB Server",
" TCP Connection Option Failed");
86 int32 flags = CLIENT_FOUND_ROWS;
88 flags |= CLIENT_COMPRESS;
92 sLog.Cyan(
" Connect Flags",
" %x", flags);
109 my_bool reconnect =
true;
110 if (mysql_options(
mysql, MYSQL_OPT_RECONNECT, (
void*)&reconnect) == 0)
111 sLog.Green(
" DataBase Manager",
"DataBase AutoReconnect Enabled");
113 sLog.Error(
" DataBase Manager",
"DataBase AutoReconnect Option Failed");
115 sLog.Yellow(
" DataBase Manager",
"DataBase AutoReconnect Disabled");
119 *errnum = mysql_errno(
mysql);
120 if (errbuf !=
nullptr)
121 snprintf(errbuf, MYSQL_ERRMSG_SIZE,
"#%i: %s", mysql_errno(
mysql), mysql_error(
mysql));
124 sLog.Error(
" ServerInit",
"Unable to connect to the database: %s", err.
c_str() );
129 sLog.Blue(
" DataBase Manager",
"DataBase Connected");
133 if (mysql_set_character_set(
mysql,
"utf8") == 0)
134 sLog.Cyan(
" DataBase Manager",
"DataBase Character set: %s", mysql_character_set_name(
mysql));
void SetError(uint err, const char *str)
#define sLog
Evaluates to a NewLog instance.
const char * c_str() const
int32 DBcore::DoEscapeString |
( |
char * |
tobuf, |
|
|
const char * |
frombuf, |
|
|
int32 |
fromlen |
|
) |
| |
Definition at line 358 of file dbcore.cpp.
References mysql.
360 return mysql_real_escape_string(
mysql, tobuf, frombuf, fromlen);
void DBcore::DoEscapeString |
( |
std::string & |
to, |
|
|
const std::string & |
from |
|
) |
| |
Definition at line 363 of file dbcore.cpp.
References mysql.
368 uint32 esc_len = mysql_real_escape_string(
mysql, &to[0], from.c_str(), len);
369 to.resize(esc_len + 1);
bool DBcore::DoQuery_locked |
( |
DBerror & |
err, |
|
|
const char * |
query, |
|
|
int |
querylen, |
|
|
bool |
retry = true |
|
) |
| |
|
private |
Definition at line 308 of file dbcore.cpp.
References _log, DBerror::c_str(), DBerror::ClearError(), codelog, Connected, Error, DBerror::GetErrNo(), GetTimeUSeconds(), is_log_enabled, mysql, pProfile, pStatus, Reconnect(), DBerror::SetError(), and sProfiler.
Referenced by RunQuery(), and RunQueryLID().
312 if (
mysql ==
nullptr) {
314 codelog(DATABASE__ERROR,
"DBCore - mysql = null");
320 codelog(DATABASE__ERROR,
"DBCore - Status != Connected");
321 _log(DATABASE__MESSAGE,
"DBCore error detected. Look for error msgs in logs prior to this point.");
327 _log(DATABASE__QUERIES,
"DBcore Query - %s", query);
329 if (mysql_real_query(
mysql, query, querylen)) {
330 uint num = mysql_errno(
mysql);
335 if ((num == CR_SERVER_LOST) or (num == CR_SERVER_GONE_ERROR)) {
336 _log(DATABASE__ERROR,
"DBCore error - server lost or gone.");
#define _log(type, fmt,...)
bool DoQuery_locked(DBerror &err, const char *query, int querylen, bool retry=true)
void SetError(uint err, const char *str)
#define is_log_enabled(type)
const char * c_str() const
#define codelog(type, fmt,...)
MYSQL* DBcore::getMySQL |
( |
| ) |
|
|
inlineprotected |
eStatus DBcore::GetStatus |
( |
| ) |
const |
|
inline |
void DBcore::Initialize |
( |
std::string |
host, |
|
|
std::string |
user, |
|
|
std::string |
password, |
|
|
std::string |
database, |
|
|
bool |
compress = false , |
|
|
bool |
SSL = false , |
|
|
int16 |
port = 3306 , |
|
|
bool |
socket = false , |
|
|
bool |
reconnect = false , |
|
|
bool |
profile = false |
|
) |
| |
Definition at line 154 of file dbcore.cpp.
References Connect(), Connected, MDatabase, mysql, pCompress, pDatabase, pHost, pPassword, pPort, pProfile, pReconnect, pSocket, pSSL, pStatus, pUser, and sLog.
157 if (
mysql ==
nullptr)
158 mysql = mysql_init(
nullptr);
159 if (
mysql ==
nullptr) {
160 sLog.Error(
" ServerInit",
"Unable to connect to the database: mysql_init returned null");
178 sLog.Error(
" ServerInit",
"Unable to connect to the database: required connect field(s) are empty.");
189 sLog.Blue(
" DataBase Manager",
"DataBase Manager Initialized");
A lock for a Lockable object.
#define sLog
Evaluates to a NewLog instance.
void Connect(uint *errnum=0, char *errbuf=0)
bool DBcore::IsSafeString |
( |
const char * |
str | ) |
|
|
static |
Definition at line 373 of file dbcore.cpp.
374 for(; *str !=
'\0'; str++) {
bool DBcore::IsSafeString |
( |
std::string & |
s | ) |
|
|
static |
Definition at line 384 of file dbcore.cpp.
385 for (uint i = 0; i < s.length(); ++i) {
bool DBcore::Reconnect |
( |
| ) |
|
|
protected |
Definition at line 137 of file dbcore.cpp.
References _log, Close(), Connect(), Connected, MDatabase, mysql, and pStatus.
Referenced by DoQuery_locked().
139 _log(DATABASE__MESSAGE,
"DBCore attempting to recover...");
141 mysql = mysql_init(
nullptr);
149 _log(DATABASE__MESSAGE,
"DBCore recovery successful. Continuing.");
#define _log(type, fmt,...)
A lock for a Lockable object.
void Connect(uint *errnum=0, char *errbuf=0)
bool DBcore::RunQuery |
( |
DBQueryResult & |
into, |
|
|
const char * |
query_fmt, |
|
|
|
... |
|
) |
| |
Definition at line 222 of file dbcore.cpp.
References codelog, DoQuery_locked(), DBQueryResult::error, MDatabase, mysql, DBerror::SetError(), DBQueryResult::SetResult(), EvE::traceStack(), and vsnprintf.
227 va_start(vlist, query_fmt);
234 uint col_count = mysql_field_count(
mysql);
235 if (col_count == 0) {
237 codelog(DATABASE__ERROR,
"DBCore::RunQuery: %s failed because it did not return a result", query);
A lock for a Lockable object.
bool DoQuery_locked(DBerror &err, const char *query, int querylen, bool retry=true)
void SetError(uint err, const char *str)
#define codelog(type, fmt,...)
void SetResult(MYSQL_RES *res, uint32 colCount)
bool DBcore::RunQuery |
( |
DBerror & |
err, |
|
|
const char * |
query_fmt, |
|
|
|
... |
|
) |
| |
Definition at line 248 of file dbcore.cpp.
References args, DoQuery_locked(), MDatabase, and vasprintf().
252 va_start(args, query_fmt);
253 char* query(
nullptr);
254 int querylen =
vasprintf(&query, query_fmt, args);
A lock for a Lockable object.
bool DoQuery_locked(DBerror &err, const char *query, int querylen, bool retry=true)
int vasprintf(char **strp, const char *fmt, va_list ap)
bool DBcore::RunQuery |
( |
DBerror & |
err, |
|
|
uint32 & |
affected_rows, |
|
|
const char * |
query_fmt, |
|
|
|
... |
|
) |
| |
Definition at line 267 of file dbcore.cpp.
References args, DoQuery_locked(), MDatabase, mysql, and vasprintf().
271 va_start(args, query_fmt);
272 char* query(
nullptr);
273 int querylen =
vasprintf(&query, query_fmt, args);
282 affected_rows = (
uint32)mysql_affected_rows(
mysql);
A lock for a Lockable object.
bool DoQuery_locked(DBerror &err, const char *query, int querylen, bool retry=true)
int vasprintf(char **strp, const char *fmt, va_list ap)
bool DBcore::RunQueryLID |
( |
DBerror & |
err, |
|
|
uint32 & |
last_insert_id, |
|
|
const char * |
query_fmt, |
|
|
|
... |
|
) |
| |
Definition at line 288 of file dbcore.cpp.
References args, DoQuery_locked(), MDatabase, mysql, and vasprintf().
292 va_start(args, query_fmt);
293 char* query(
nullptr);
294 int querylen =
vasprintf(&query, query_fmt, args);
A lock for a Lockable object.
bool DoQuery_locked(DBerror &err, const char *query, int querylen, bool retry=true)
int vasprintf(char **strp, const char *fmt, va_list ap)
Definition at line 181 of file dbcore.h.
Referenced by Close(), Connect(), DBcore(), DoEscapeString(), DoQuery_locked(), getMySQL(), Initialize(), ping(), Reconnect(), RunQuery(), and RunQueryLID().
std::string DBcore::pDatabase |
|
private |
std::string DBcore::pHost |
|
private |
std::string DBcore::pPassword |
|
private |
std::string DBcore::pUser |
|
private |
The documentation for this class was generated from the following files:
- /backups/local/src/eve/EvEmu_Crucible/src/eve-core/database/dbcore.h
- /backups/local/src/eve/EvEmu_Crucible/src/eve-core/database/dbcore.cpp