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
@@ -102,9 +102,9 @@ bool Bag::Create(uint32 guidlow, uint32 itemid, Player const* owner)
return true;
}
void Bag::SaveToDB()
void Bag::SaveToDB(SQLTransaction& trans)
{
Item::SaveToDB();
Item::SaveToDB(trans);
}
bool Bag::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result, uint32 entry)
@@ -125,13 +125,13 @@ bool Bag::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result,
return true;
}
void Bag::DeleteFromDB()
void Bag::DeleteFromDB(SQLTransaction& trans)
{
for (uint8 i = 0; i < MAX_BAG_SIZE; ++i)
if (m_bagslot[i])
m_bagslot[i]->DeleteFromDB();
m_bagslot[i]->DeleteFromDB(trans);
Item::DeleteFromDB();
Item::DeleteFromDB(trans);
}
uint32 Bag::GetFreeSlots() const
@@ -54,11 +54,11 @@ class Bag : public Item
// DB operations
// overwrite virtual Item::SaveToDB
void SaveToDB();
void SaveToDB(SQLTransaction& trans);
// overwrite virtual Item::LoadFromDB
bool LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result, uint32 entry);
// overwrite virtual Item::DeleteFromDB
void DeleteFromDB();
void DeleteFromDB(SQLTransaction& trans);
void BuildCreateUpdateBlockForPlayer(UpdateData *data, Player *target) const;
+14 -14
View File
@@ -301,7 +301,7 @@ void Item::UpdateDuration(Player* owner, uint32 diff)
SetState(ITEM_CHANGED, owner); // save new time in database
}
void Item::SaveToDB()
void Item::SaveToDB(SQLTransaction& trans)
{
uint32 guid = GetGUIDLow();
switch (uState)
@@ -334,7 +334,7 @@ void Item::SaveToDB()
ss << GetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME) << ",'";
ss << text << "')";
CharacterDatabase.Execute(ss.str().c_str());
trans->Append(ss.str().c_str());
}break;
case ITEM_CHANGED:
{
@@ -364,16 +364,16 @@ void Item::SaveToDB()
ss << ", playedTime = " << GetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME);
ss << ", text = '" << text << "' WHERE guid = " << guid;
CharacterDatabase.Execute(ss.str().c_str());
trans->Append(ss.str().c_str());
if (HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_WRAPPED))
CharacterDatabase.PExecute("UPDATE character_gifts SET guid = '%u' WHERE item_guid = '%u'", GUID_LOPART(GetOwnerGUID()),GetGUIDLow());
trans->PAppend("UPDATE character_gifts SET guid = '%u' WHERE item_guid = '%u'", GUID_LOPART(GetOwnerGUID()),GetGUIDLow());
}break;
case ITEM_REMOVED:
{
CharacterDatabase.PExecute("DELETE FROM item_instance WHERE guid = '%u'", guid);
trans->PAppend("DELETE FROM item_instance WHERE guid = '%u'", guid);
if (HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_WRAPPED))
CharacterDatabase.PExecute("DELETE FROM character_gifts WHERE item_guid = '%u'", GetGUIDLow());
trans->PAppend("DELETE FROM character_gifts WHERE item_guid = '%u'", GetGUIDLow());
delete this;
return;
}
@@ -471,14 +471,14 @@ bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result
return true;
}
void Item::DeleteFromDB()
void Item::DeleteFromDB(SQLTransaction& trans)
{
CharacterDatabase.PExecute("DELETE FROM item_instance WHERE guid = '%u'",GetGUIDLow());
trans->PAppend("DELETE FROM item_instance WHERE guid = '%u'",GetGUIDLow());
}
void Item::DeleteFromInventoryDB()
void Item::DeleteFromInventoryDB(SQLTransaction& trans)
{
CharacterDatabase.PExecute("DELETE FROM character_inventory WHERE item = '%u'",GetGUIDLow());
trans->PAppend("DELETE FROM character_inventory WHERE item = '%u'",GetGUIDLow());
}
ItemPrototype const *Item::GetProto() const
@@ -1103,11 +1103,11 @@ void Item::BuildUpdate(UpdateDataMapType& data_map)
void Item::SaveRefundDataToDB()
{
CharacterDatabase.BeginTransaction();
CharacterDatabase.PExecute("DELETE FROM item_refund_instance WHERE item_guid = '%u'", GetGUIDLow());
CharacterDatabase.PExecute("INSERT INTO item_refund_instance (`item_guid`,`player_guid`,`paidMoney`,`paidExtendedCost`)"
SQLTransaction trans = CharacterDatabase.BeginTransaction();
trans->PAppend("DELETE FROM item_refund_instance WHERE item_guid = '%u'", GetGUIDLow());
trans->PAppend("INSERT INTO item_refund_instance (`item_guid`,`player_guid`,`paidMoney`,`paidExtendedCost`)"
" VALUES('%u','%u','%u','%u')", GetGUIDLow(), GetRefundRecipient(), GetPaidMoney(), GetPaidExtendedCost());
CharacterDatabase.CommitTransaction();
CharacterDatabase.CommitTransaction(trans);
}
void Item::DeleteRefundDataFromDB()
+3 -3
View File
@@ -244,10 +244,10 @@ class Item : public Object
bool IsBoundAccountWide() const { return (GetProto()->Flags & ITEM_PROTO_FLAG_BIND_TO_ACCOUNT) != 0; }
bool IsBindedNotWith(Player const* player) const;
bool IsBoundByEnchant() const;
virtual void SaveToDB();
virtual void SaveToDB(SQLTransaction& trans);
virtual bool LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result, uint32 entry);
virtual void DeleteFromDB();
void DeleteFromInventoryDB();
virtual void DeleteFromDB(SQLTransaction& trans);
void DeleteFromInventoryDB(SQLTransaction& trans);
void SaveRefundDataToDB();
void DeleteRefundDataFromDB();