Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #39

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 6 additions & 54 deletions src/game/CharacterDatabaseCleaner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,64 +46,16 @@ void CharacterDatabaseCleaner::CleanDatabase()
CharacterDatabase.Execute("UPDATE saved_variables SET cleaning_flags = 0");
}

void CharacterDatabaseCleaner::CheckUnique(const char* column, const char* table, bool (*check)(uint32))
{
QueryResult* result = CharacterDatabase.PQuery("SELECT DISTINCT %s FROM %s", column, table);
if (!result)
{
sLog.outString("Table %s is empty.", table);
return;
}

bool found = false;
std::ostringstream ss;
BarGoLink bar(result->GetRowCount());
do
{
bar.step();

Field *fields = result->Fetch();

uint32 id = fields[0].GetUInt32();

if (!check(id))
{
if (!found)
{
ss << "DELETE FROM " << table << " WHERE " << column << " IN (";
found = true;
}
else
ss << ",";
ss << id;
}
}
while (result->NextRow());
delete result;

if (found)
{
ss << ")";
CharacterDatabase.Execute(ss.str().c_str());
}
}

bool CharacterDatabaseCleaner::SkillCheck(uint32 skill)
{
return sSkillLineStore.LookupEntry(skill);
}

void CharacterDatabaseCleaner::CleanCharacterSkills()
{
CheckUnique("skill", "character_skills", &SkillCheck);
}

bool CharacterDatabaseCleaner::SpellCheck(uint32 spell_id)
{
return sSpellStore.LookupEntry(spell_id);
uint32 count = sSkillLineStore.GetNumRows();

CharacterDatabase.PExecute("DELETE FROM character_skills WHERE skill >= %u", count);
}

void CharacterDatabaseCleaner::CleanCharacterSpell()
{
CheckUnique("spell", "character_spell", &SpellCheck);
uint32 count = sSpellStore.GetNumRows();

CharacterDatabase.PExecute("DELETE FROM character_spell WHERE spell >= %u", count);
}
5 changes: 0 additions & 5 deletions src/game/CharacterDatabaseCleaner.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ namespace CharacterDatabaseCleaner

void CleanDatabase();

void CheckUnique(const char* column, const char* table, bool (*check)(uint32));

bool SkillCheck(uint32 skill);
bool SpellCheck(uint32 spell_id);

void CleanCharacterSkills();
void CleanCharacterSpell();
}
Expand Down