DB Layer:

- Make SQL Transactions actual objects used in code. (Thanks to Derex for the idea)
* Uncommitted transactions will be automatically rolled back and cleaned up using ACE_Refcounted_Auto_Ptr, so no need to call Rollback() in the code.
* Prevents recursive transactions and makes developers aware of transactions going on.
* Gets rid of unneccesary overhead iterating over a concurrent map.
- Some cleanups in affected code, including better usage of transaction control in AH / mail related code to prevent data loss.

*** Experimental, use at own risk, recommended to backup your DBs. ***

--HG--
branch : trunk
This commit is contained in:
Machiavelli
2010-08-21 03:19:25 +02:00
parent a7498d2f56
commit 994186f267
49 changed files with 861 additions and 774 deletions
+7 -7
View File
@@ -105,8 +105,8 @@ bool Corpse::Create(uint32 guidlow, Player *owner)
void Corpse::SaveToDB()
{
// prevent DB data inconsistence problems and duplicates
CharacterDatabase.BeginTransaction();
DeleteFromDB();
SQLTransaction trans = CharacterDatabase.BeginTransaction();
DeleteFromDB(trans);
std::ostringstream ss;
ss << "INSERT INTO corpse (guid,player,position_x,position_y,position_z,orientation,zone,map,displayId,itemCache,bytes1,bytes2,guild,flags,dynFlags,time,corpse_type,instance,phaseMask) VALUES ("
@@ -131,8 +131,8 @@ void Corpse::SaveToDB()
<< uint32(GetType()) << ", "
<< int(GetInstanceId()) << ", "
<< uint16(GetPhaseMask()) << ")"; // prevent out of range error
CharacterDatabase.Execute(ss.str().c_str());
CharacterDatabase.CommitTransaction();
trans->Append(ss.str().c_str());
CharacterDatabase.CommitTransaction(trans);
}
void Corpse::DeleteBonesFromWorld()
@@ -149,14 +149,14 @@ void Corpse::DeleteBonesFromWorld()
AddObjectToRemoveList();
}
void Corpse::DeleteFromDB()
void Corpse::DeleteFromDB(SQLTransaction& trans)
{
if (GetType() == CORPSE_BONES)
// only specific bones
CharacterDatabase.PExecute("DELETE FROM corpse WHERE guid = '%d'", GetGUIDLow());
trans->PAppend("DELETE FROM corpse WHERE guid = '%d'", GetGUIDLow());
else
// all corpses (not bones)
CharacterDatabase.PExecute("DELETE FROM corpse WHERE player = '%d' AND corpse_type <> '0'", GUID_LOPART(GetOwnerGUID()));
trans->PAppend("DELETE FROM corpse WHERE player = '%d' AND corpse_type <> '0'", GUID_LOPART(GetOwnerGUID()));
}
bool Corpse::LoadFromDB(uint32 guid, Field *fields)
+1 -1
View File
@@ -64,7 +64,7 @@ class Corpse : public WorldObject, public GridObject<Corpse>
bool LoadFromDB(uint32 guid, Field *fields);
void DeleteBonesFromWorld();
void DeleteFromDB();
void DeleteFromDB(SQLTransaction& trans);
uint64 const& GetOwnerGUID() const { return GetUInt64Value(CORPSE_FIELD_OWNER); }