Removed DBCore::RunQuery

Converted last corpse.cpp function that mixed database code with corpse code
This commit is contained in:
Akkadius
2014-11-23 22:57:46 -06:00
parent c30850f00a
commit e4f45d7b35
6 changed files with 28 additions and 129 deletions
+1 -1
View File
@@ -2303,7 +2303,7 @@ bool Database::CheckDatabaseConversions() {
}
}
}
QueryDatabase(StringFormat("ALTER TABLE `character_corpses` DROP COLUMN `data`"));
QueryDatabase(StringFormat("ALTER TABLE `character_corpses` DROP COLUMN `data`"));
}
-89
View File
@@ -155,95 +155,6 @@ MySQLRequestResult DBcore::QueryDatabase(const char* query, uint32 querylen, boo
return requestResult;
}
bool DBcore::RunQuery(const char* query, uint32 querylen, char* errbuf, MYSQL_RES** result, uint32* affected_rows, uint32* last_insert_id, uint32* errnum, bool retry) {
if (errnum)
*errnum = 0;
if (errbuf)
errbuf[0] = 0;
bool ret = false;
LockMutex lock(&MDatabase);
if (pStatus != Connected)
Open();
if (mysql_real_query(&mysql, query, querylen)) {
if (mysql_errno(&mysql) == CR_SERVER_GONE_ERROR)
pStatus = Error;
if (mysql_errno(&mysql) == CR_SERVER_LOST || mysql_errno(&mysql) == CR_SERVER_GONE_ERROR) {
if (retry) {
std::cout << "Database Error: Lost connection, attempting to recover...." << std::endl;
ret = RunQuery(query, querylen, errbuf, result, affected_rows, last_insert_id, errnum, false);
if (ret)
std::cout << "Reconnection to database successful." << std::endl;
}
else {
pStatus = Error;
if (errnum)
*errnum = mysql_errno(&mysql);
if (errbuf)
snprintf(errbuf, MYSQL_ERRMSG_SIZE, "#%i: %s", mysql_errno(&mysql), mysql_error(&mysql));
std::cout << "DB Query Error #" << mysql_errno(&mysql) << ": " << mysql_error(&mysql) << std::endl;
ret = false;
}
}
else {
if (errnum)
*errnum = mysql_errno(&mysql);
if (errbuf)
snprintf(errbuf, MYSQL_ERRMSG_SIZE, "#%i: %s", mysql_errno(&mysql), mysql_error(&mysql));
#ifdef _EQDEBUG
std::cout << "DB Query Error #" << mysql_errno(&mysql) << ": " << mysql_error(&mysql) << std::endl;
#endif
ret = false;
}
}
else {
if (result && mysql_field_count(&mysql)) {
*result = mysql_store_result(&mysql);
#ifdef _EQDEBUG
DBMemLeak::Alloc(*result, query);
#endif
}
else if (result)
*result = 0;
if (affected_rows)
*affected_rows = mysql_affected_rows(&mysql);
if (last_insert_id)
*last_insert_id = (uint32)mysql_insert_id(&mysql);
if (result) {
if (*result) {
ret = true;
}
else {
#ifdef _EQDEBUG
std::cout << "DB Query Error: No Result" << std::endl;
#endif
if (errnum)
*errnum = UINT_MAX;
if (errbuf)
strcpy(errbuf, "DBcore::RunQuery: No Result");
ret = false;
}
}
else {
ret = true;
}
}
#if DEBUG_MYSQL_QUERIES >= 1
if (ret) {
std::cout << "query successful";
if (result && (*result))
std::cout << ", " << (int) mysql_num_rows(*result) << " rows returned";
if (affected_rows)
std::cout << ", " << (*affected_rows) << " rows affected";
std::cout<< std::endl;
}
else {
std::cout << "QUERY: query FAILED" << std::endl;
}
#endif
return ret;
}
void DBcore::TransactionBegin() {
QueryDatabase("START TRANSACTION");
}
-1
View File
@@ -23,7 +23,6 @@ public:
DBcore();
~DBcore();
eStatus GetStatus() { return pStatus; }
bool RunQuery(const char* query, uint32 querylen, char* errbuf = 0, MYSQL_RES** result = 0, uint32* affected_rows = 0, uint32* last_insert_id = 0, uint32* errnum = 0, bool retry = true);
MySQLRequestResult QueryDatabase(const char* query, uint32 querylen, bool retryOnFailureOnce = true);
MySQLRequestResult QueryDatabase(std::string query, bool retryOnFailureOnce = true);
void TransactionBegin();