mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-12 09:31:30 +00:00
Converted LoadVariables, and LoadVariables_result to QueryDatabase
This commit is contained in:
parent
87cb659dc2
commit
74d65f6fda
@ -843,7 +843,7 @@ void Database::GetAccountName(uint32 accountid, char* name, uint32* oLSAccountID
|
|||||||
|
|
||||||
if (!results.Success())
|
if (!results.Success())
|
||||||
{
|
{
|
||||||
std::cerr << "Error in GetAccountName query '" << query << "' " << errbuf << std::endl;
|
std::cerr << "Error in GetAccountName query '" << query << "' " << results.ErrorMessage() << std::endl;
|
||||||
safe_delete_array(query);
|
safe_delete_array(query);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -881,42 +881,42 @@ void Database::GetCharName(uint32 char_id, char* name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Database::LoadVariables() {
|
bool Database::LoadVariables() {
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
char *query = nullptr;
|
||||||
char *query = 0;
|
|
||||||
MYSQL_RES *result;
|
|
||||||
|
|
||||||
if (RunQuery(query, LoadVariables_MQ(&query), errbuf, &result)) {
|
auto results = QueryDatabase(query, LoadVariables_MQ(&query));
|
||||||
|
|
||||||
|
if (!results.Success())
|
||||||
|
{
|
||||||
|
std::cerr << "Error in LoadVariables query '" << query << "' " << results.ErrorMessage() << std::endl;
|
||||||
safe_delete_array(query);
|
safe_delete_array(query);
|
||||||
bool ret = LoadVariables_result(result);
|
|
||||||
mysql_free_result(result);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
std::cerr << "Error in LoadVariables query '" << query << "' " << errbuf << std::endl;
|
|
||||||
safe_delete_array(query);
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
safe_delete_array(query);
|
||||||
|
return LoadVariables_result(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 Database::LoadVariables_MQ(char** query) {
|
uint32 Database::LoadVariables_MQ(char** query)
|
||||||
// the read of this single variable should be atomic... this was causing strange problems
|
{
|
||||||
// LockMutex lock(&Mvarcache);
|
|
||||||
return MakeAnyLenString(query, "SELECT varname, value, unix_timestamp() FROM variables where unix_timestamp(ts) >= %d", varcache_lastupdate);
|
return MakeAnyLenString(query, "SELECT varname, value, unix_timestamp() FROM variables where unix_timestamp(ts) >= %d", varcache_lastupdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Database::LoadVariables_result(MYSQL_RES* result) {
|
// always returns true? not sure about this.
|
||||||
uint32 i;
|
bool Database::LoadVariables_result(MySQLRequestResult results) {
|
||||||
MYSQL_ROW row;
|
uint32 i = 0;
|
||||||
LockMutex lock(&Mvarcache);
|
LockMutex lock(&Mvarcache);
|
||||||
if (mysql_num_rows(result) > 0) {
|
|
||||||
|
if (results.RowCount() == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
if (!varcache_array) {
|
if (!varcache_array) {
|
||||||
varcache_max = mysql_num_rows(result);
|
varcache_max = results.RowCount();
|
||||||
varcache_array = new VarCache_Struct*[varcache_max];
|
varcache_array = new VarCache_Struct*[varcache_max];
|
||||||
for (i=0; i<varcache_max; i++)
|
for (i=0; i<varcache_max; i++)
|
||||||
varcache_array[i] = 0;
|
varcache_array[i] = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
uint32 tmpnewmax = varcache_max + mysql_num_rows(result);
|
uint32 tmpnewmax = varcache_max + results.RowCount();
|
||||||
VarCache_Struct** tmp = new VarCache_Struct*[tmpnewmax];
|
VarCache_Struct** tmp = new VarCache_Struct*[tmpnewmax];
|
||||||
for (i=0; i<tmpnewmax; i++)
|
for (i=0; i<tmpnewmax; i++)
|
||||||
tmp[i] = 0;
|
tmp[i] = 0;
|
||||||
@ -927,7 +927,9 @@ bool Database::LoadVariables_result(MYSQL_RES* result) {
|
|||||||
varcache_max = tmpnewmax;
|
varcache_max = tmpnewmax;
|
||||||
delete [] tmpdel;
|
delete [] tmpdel;
|
||||||
}
|
}
|
||||||
while ((row = mysql_fetch_row(result))) {
|
|
||||||
|
for (auto row = results.begin(); row != results.end(); ++row)
|
||||||
|
{
|
||||||
varcache_lastupdate = atoi(row[2]);
|
varcache_lastupdate = atoi(row[2]);
|
||||||
for (i=0; i<varcache_max; i++) {
|
for (i=0; i<varcache_max; i++) {
|
||||||
if (varcache_array[i]) {
|
if (varcache_array[i]) {
|
||||||
@ -947,6 +949,7 @@ bool Database::LoadVariables_result(MYSQL_RES* result) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 max_used = 0;
|
uint32 max_used = 0;
|
||||||
for (i=0; i<varcache_max; i++) {
|
for (i=0; i<varcache_max; i++) {
|
||||||
if (varcache_array[i]) {
|
if (varcache_array[i]) {
|
||||||
@ -954,9 +957,9 @@ bool Database::LoadVariables_result(MYSQL_RES* result) {
|
|||||||
max_used = i;
|
max_used = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
max_used++;
|
|
||||||
varcache_max = max_used;
|
varcache_max = max_used + 1;
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -223,7 +223,7 @@ public:
|
|||||||
bool SetVariable(const char* varname, const char* varvalue);
|
bool SetVariable(const char* varname, const char* varvalue);
|
||||||
bool LoadVariables();
|
bool LoadVariables();
|
||||||
uint32 LoadVariables_MQ(char** query);
|
uint32 LoadVariables_MQ(char** query);
|
||||||
bool LoadVariables_result(MYSQL_RES* result);
|
bool LoadVariables_result(MySQLRequestResult results);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* General Queries
|
* General Queries
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user