mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-14 11:31:30 +00:00
Load converted to QueryDatabase
This commit is contained in:
parent
cbed61db7e
commit
3cde8d9af8
@ -279,61 +279,47 @@ PTimerList::~PTimerList() {
|
|||||||
|
|
||||||
|
|
||||||
bool PTimerList::Load(Database *db) {
|
bool PTimerList::Load(Database *db) {
|
||||||
std::map<pTimerType, PersistentTimer *>::iterator s;
|
|
||||||
s = _list.begin();
|
for (auto timerIterator = _list.begin(); timerIterator != _list.end(); ++timerIterator)
|
||||||
while(s != _list.end()) {
|
if(timerIterator->second != nullptr)
|
||||||
if(s->second != nullptr)
|
delete timerIterator->second;
|
||||||
delete s->second;
|
|
||||||
++s;
|
|
||||||
}
|
|
||||||
_list.clear();
|
_list.clear();
|
||||||
|
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
|
||||||
MYSQL_RES *result;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
char *query = 0;
|
|
||||||
uint32 qlen = 0;
|
|
||||||
uint32 qcount = 0;
|
|
||||||
|
|
||||||
qlen = MakeAnyLenString(&query, "SELECT type,start,duration,enable "
|
|
||||||
" FROM timers WHERE char_id=%lu", (unsigned long)_char_id);
|
|
||||||
|
|
||||||
#ifdef DEBUG_PTIMERS
|
#ifdef DEBUG_PTIMERS
|
||||||
printf("Loading all timers for char %lu\n", (unsigned long)_char_id);
|
printf("Loading all timers for char %lu\n", (unsigned long)_char_id);
|
||||||
#endif
|
#endif
|
||||||
|
std::string query = StringFormat("SELECT type, start, duration, enable "
|
||||||
if (!db->RunQuery(query, qlen, errbuf, &result)) {
|
"FROM timers WHERE char_id = %lu",
|
||||||
safe_delete_array(query);
|
(unsigned long)_char_id);
|
||||||
|
auto results = db->QueryDatabase(query);
|
||||||
|
if (!results.Success()) {
|
||||||
#if EQDEBUG > 5
|
#if EQDEBUG > 5
|
||||||
LogFile->write(EQEMuLog::Error, "Error in PersistentTimer::Load, error: %s", errbuf);
|
LogFile->write(EQEMuLog::Error, "Error in PersistentTimer::Load, error: %s", results.ErrorMessage().c_str());
|
||||||
#endif
|
#endif
|
||||||
return(false);
|
return false;
|
||||||
}
|
}
|
||||||
safe_delete_array(query);
|
|
||||||
|
|
||||||
pTimerType type;
|
pTimerType type;
|
||||||
uint32 start_time, timer_time;
|
uint32 start_time, timer_time;
|
||||||
bool enabled;
|
bool enabled;
|
||||||
|
|
||||||
PersistentTimer *cur;
|
PersistentTimer *cur;
|
||||||
qcount = mysql_num_rows(result);
|
|
||||||
while((row = mysql_fetch_row(result)) ) {
|
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||||
type = atoi(row[0]);
|
type = atoi(row[0]);
|
||||||
start_time = strtoul(row[1], nullptr, 10);
|
start_time = strtoul(row[1], nullptr, 10);
|
||||||
timer_time = strtoul(row[2], nullptr, 10);
|
timer_time = strtoul(row[2], nullptr, 10);
|
||||||
enabled = (row[3][0] == '1');
|
enabled = (row[3][0] == '1');
|
||||||
|
|
||||||
//if it expired allready, dont bother.
|
//if it expired allready, dont bother.
|
||||||
|
|
||||||
cur = new PersistentTimer(_char_id, type, start_time, timer_time, enabled);
|
cur = new PersistentTimer(_char_id, type, start_time, timer_time, enabled);
|
||||||
if(!cur->Expired(nullptr))
|
if(!cur->Expired(nullptr))
|
||||||
_list[type] = cur;
|
_list[type] = cur;
|
||||||
else
|
else
|
||||||
delete cur;
|
delete cur;
|
||||||
}
|
}
|
||||||
mysql_free_result(result);
|
|
||||||
|
|
||||||
return(true);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PTimerList::Store(Database *db) {
|
bool PTimerList::Store(Database *db) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user