2023-11-22 02:05:15 +00:00
|
|
|
#include "CDRewardCodesTable.h"
|
|
|
|
|
|
|
|
void CDRewardCodesTable::LoadValuesFromDatabase() {
|
|
|
|
|
|
|
|
// First, get the size of the table
|
2024-01-09 07:54:14 +00:00
|
|
|
uint32_t size = 0;
|
2023-11-22 02:05:15 +00:00
|
|
|
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM RewardCodes");
|
|
|
|
while (!tableSize.eof()) {
|
|
|
|
size = tableSize.getIntField(0, 0);
|
|
|
|
|
|
|
|
tableSize.nextRow();
|
|
|
|
}
|
|
|
|
|
|
|
|
tableSize.finalize();
|
|
|
|
|
|
|
|
// Reserve the size
|
2024-02-09 13:37:58 +00:00
|
|
|
auto& entries = GetEntriesMutable();
|
|
|
|
entries.reserve(size);
|
2023-11-22 02:05:15 +00:00
|
|
|
|
|
|
|
// Now get the data
|
|
|
|
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM RewardCodes");
|
|
|
|
while (!tableData.eof()) {
|
|
|
|
CDRewardCode entry;
|
|
|
|
entry.id = tableData.getIntField("id", -1);
|
|
|
|
entry.code = tableData.getStringField("code", "");
|
|
|
|
entry.attachmentLOT = tableData.getIntField("attachmentLOT", -1);
|
|
|
|
UNUSED_COLUMN(entry.locStatus = tableData.getIntField("locStatus", -1));
|
|
|
|
UNUSED_COLUMN(entry.gate_version = tableData.getStringField("gate_version", ""));
|
|
|
|
|
2024-02-09 13:37:58 +00:00
|
|
|
entries.push_back(entry);
|
2023-11-22 02:05:15 +00:00
|
|
|
tableData.nextRow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LOT CDRewardCodesTable::GetAttachmentLOT(uint32_t rewardCodeId) const {
|
2024-02-09 13:37:58 +00:00
|
|
|
for (auto const &entry : GetEntries()){
|
2023-11-22 02:05:15 +00:00
|
|
|
if (rewardCodeId == entry.id) return entry.attachmentLOT;
|
|
|
|
}
|
|
|
|
return LOT_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t CDRewardCodesTable::GetCodeID(std::string code) const {
|
2024-02-09 13:37:58 +00:00
|
|
|
for (auto const &entry : GetEntries()){
|
2023-11-22 02:05:15 +00:00
|
|
|
if (code == entry.code) return entry.id;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|