From fd8dc1214c0f0c46362cba3fd403b1138a202fcb Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Mon, 18 Aug 2014 12:28:21 -0700 Subject: [PATCH] Load converted to QueryDatabase --- common/ptimer.cpp | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/common/ptimer.cpp b/common/ptimer.cpp index 8e9f03dcf..bfca79452 100644 --- a/common/ptimer.cpp +++ b/common/ptimer.cpp @@ -127,41 +127,31 @@ PersistentTimer::PersistentTimer(uint32 char_id, pTimerType type, uint32 in_star } bool PersistentTimer::Load(Database *db) { - char errbuf[MYSQL_ERRMSG_SIZE]; - MYSQL_RES *result; - MYSQL_ROW row; - char *query = 0; - uint32 qlen = 0; - uint32 qcount = 0; - - qlen = MakeAnyLenString(&query, "SELECT start,duration,enable " - " FROM timers WHERE char_id=%lu AND type=%u", (unsigned long)_char_id, _type); #ifdef DEBUG_PTIMERS printf("Loading timer: char %lu of type %u\n", (unsigned long)_char_id, _type); #endif - - if (!db->RunQuery(query, qlen, errbuf, &result)) { - safe_delete_array(query); + std::string query = StringFormat("SELECT start, duration, enable " + "FROM timers WHERE char_id=%lu AND type=%u", + (unsigned long)_char_id, _type); + auto results = db->QueryDatabase(query); + if (!results.Success()) { #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 - return(false); + return false; } - safe_delete_array(query); - bool res = false; - qcount = mysql_num_rows(result); - if(qcount == 1 && (row = mysql_fetch_row(result)) ) { - start_time = strtoul(row[0], nullptr, 10); - timer_time = strtoul(row[1], nullptr, 10); - enabled = (row[2][0] == '1'); + if (results.RowCount() != 1) + return false; - res = true; - } - mysql_free_result(result); + auto row = results.begin(); - return(res); + start_time = strtoul(row[0], nullptr, 10); + timer_time = strtoul(row[1], nullptr, 10); + enabled = (row[2][0] == '1'); + + return true; } bool PersistentTimer::Store(Database *db) {