[11055] Save pet related data in one single transaction. Also merge Pet::DeleteFromDB() queries into one single transaction request.

Signed-off-by: Ambal <pogrebniak@gala.net>
This commit is contained in:
Ambal 2011-01-21 00:06:58 +02:00
parent 07c9f0cbb8
commit 7ef75985b9
4 changed files with 12 additions and 7 deletions

View file

@ -380,17 +380,15 @@ void Pet::SavePetToDB(PetSaveMode mode)
if (mode != PET_SAVE_AS_CURRENT)
RemoveAllAuras();
//save pet's spell data as one single transaction
//save pet's data as one single transaction
CharacterDatabase.BeginTransaction();
_SaveSpells();
_SaveSpellCooldowns();
_SaveAuras();
CharacterDatabase.CommitTransaction();
uint32 ownerLow = GetOwnerGuid().GetCounter();
std::string name = m_name;
CharacterDatabase.escape_string(name);
CharacterDatabase.BeginTransaction();
// remove current data
CharacterDatabase.PExecute("DELETE FROM character_pet WHERE owner = '%u' AND id = '%u'", ownerLow, m_charmInfo->GetPetNumber());
@ -445,13 +443,19 @@ void Pet::SavePetToDB(PetSaveMode mode)
}
}
void Pet::DeleteFromDB(uint32 guidlow)
void Pet::DeleteFromDB(uint32 guidlow, bool separate_transaction)
{
if(separate_transaction)
CharacterDatabase.BeginTransaction();
CharacterDatabase.PExecute("DELETE FROM character_pet WHERE id = '%u'", guidlow);
CharacterDatabase.PExecute("DELETE FROM character_pet_declinedname WHERE id = '%u'", guidlow);
CharacterDatabase.PExecute("DELETE FROM pet_aura WHERE guid = '%u'", guidlow);
CharacterDatabase.PExecute("DELETE FROM pet_spell WHERE guid = '%u'", guidlow);
CharacterDatabase.PExecute("DELETE FROM pet_spell_cooldown WHERE guid = '%u'", guidlow);
if(separate_transaction)
CharacterDatabase.CommitTransaction();
}
void Pet::SetDeathState(DeathState s) // overwrite virtual Creature::SetDeathState and Unit::SetDeathState

View file

@ -154,7 +154,7 @@ class Pet : public Creature
bool LoadPetFromDB( Player* owner,uint32 petentry = 0,uint32 petnumber = 0, bool current = false );
void SavePetToDB(PetSaveMode mode);
void Unsummon(PetSaveMode mode, Unit* owner = NULL);
static void DeleteFromDB(uint32 guidlow);
static void DeleteFromDB(uint32 guidlow, bool separate_transaction = true);
void SetDeathState(DeathState s); // overwrite virtual Creature::SetDeathState and Unit::SetDeathState
void Update(uint32 update_diff, uint32 diff); // overwrite virtual Creature::Update and Unit::Update

View file

@ -4307,7 +4307,8 @@ void Player::DeleteFromDB(ObjectGuid playerguid, uint32 accountId, bool updateRe
{
Field *fields3 = resultPets->Fetch();
uint32 petguidlow = fields3[0].GetUInt32();
Pet::DeleteFromDB(petguidlow);
//do not create separate transaction for pet delete otherwise we will get fatal error!
Pet::DeleteFromDB(petguidlow, false);
} while (resultPets->NextRow());
delete resultPets;
}

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "11054"
#define REVISION_NR "11055"
#endif // __REVISION_NR_H__