diff options
author | Machiavelli <none@none> | 2010-08-21 03:19:25 +0200 |
---|---|---|
committer | Machiavelli <none@none> | 2010-08-21 03:19:25 +0200 |
commit | 994186f2672547761392c71ed15ded2a83e8c20d (patch) | |
tree | 53eec0c7571642b9490d2a664671cb216a730993 /src/server/game/Groups/Group.cpp | |
parent | a7498d2f560e24b2ae3b4f6cc46ea2223a41e16f (diff) |
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
Diffstat (limited to 'src/server/game/Groups/Group.cpp')
-rw-r--r-- | src/server/game/Groups/Group.cpp | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/src/server/game/Groups/Group.cpp b/src/server/game/Groups/Group.cpp index 837f7d3ad77..7a8ffb061b5 100644 --- a/src/server/game/Groups/Group.cpp +++ b/src/server/game/Groups/Group.cpp @@ -116,20 +116,19 @@ bool Group::Create(const uint64 &guid, const char * name) Player::ConvertInstancesToGroup(leader, this, guid); + if (!AddMember(guid, name)) + return false; + // store group in database - CharacterDatabase.BeginTransaction(); - CharacterDatabase.PExecute("DELETE FROM groups WHERE guid ='%u'", lowguid); - CharacterDatabase.PExecute("DELETE FROM group_member WHERE guid ='%u'", lowguid); - CharacterDatabase.PExecute("INSERT INTO groups (guid,leaderGuid,lootMethod,looterGuid,lootThreshold,icon1,icon2,icon3,icon4,icon5,icon6,icon7,icon8,groupType,difficulty,raiddifficulty) " + SQLTransaction trans = CharacterDatabase.BeginTransaction(); + trans->PAppend("DELETE FROM groups WHERE guid ='%u'", lowguid); + trans->PAppend("DELETE FROM group_member WHERE guid ='%u'", lowguid); + trans->PAppend("INSERT INTO groups (guid,leaderGuid,lootMethod,looterGuid,lootThreshold,icon1,icon2,icon3,icon4,icon5,icon6,icon7,icon8,groupType,difficulty,raiddifficulty) " "VALUES ('%u','%u','%u','%u','%u','" UI64FMTD "','" UI64FMTD "','" UI64FMTD "','" UI64FMTD "','" UI64FMTD "','" UI64FMTD "','" UI64FMTD "','" UI64FMTD "','%u','%u','%u')", lowguid, GUID_LOPART(m_leaderGuid), uint32(m_lootMethod), GUID_LOPART(m_looterGuid), uint32(m_lootThreshold), m_targetIcons[0], m_targetIcons[1], m_targetIcons[2], m_targetIcons[3], m_targetIcons[4], m_targetIcons[5], m_targetIcons[6], m_targetIcons[7], uint8(m_groupType), uint32(m_dungeonDifficulty), m_raidDifficulty); - if (!AddMember(guid, name)) - { - CharacterDatabase.RollbackTransaction(); - return false; - } - CharacterDatabase.CommitTransaction(); + + CharacterDatabase.CommitTransaction(trans); } else if (!AddMember(guid, name)) return false; @@ -497,10 +496,10 @@ void Group::Disband(bool hideDestroy) if (!isBGGroup()) { uint32 lowguid = GUID_LOPART(m_guid); - CharacterDatabase.BeginTransaction(); - CharacterDatabase.PExecute("DELETE FROM groups WHERE guid=%u", lowguid); - CharacterDatabase.PExecute("DELETE FROM group_member WHERE guid=%u", lowguid); - CharacterDatabase.CommitTransaction(); + SQLTransaction trans = CharacterDatabase.BeginTransaction(); + trans->PAppend("DELETE FROM groups WHERE guid=%u", lowguid); + trans->PAppend("DELETE FROM group_member WHERE guid=%u", lowguid); + CharacterDatabase.CommitTransaction(trans); ResetInstances(INSTANCE_RESET_GROUP_DISBAND, false, NULL); ResetInstances(INSTANCE_RESET_GROUP_DISBAND, true, NULL); } @@ -1334,14 +1333,14 @@ void Group::_setLeader(const uint64 &guid) if (!isBGGroup()) { // TODO: set a time limit to have this function run rarely cause it can be slow - CharacterDatabase.BeginTransaction(); + SQLTransaction trans = CharacterDatabase.BeginTransaction(); // update the group's bound instances when changing leaders // remove all permanent binds from the group // in the DB also remove solo binds that will be replaced with permbinds // from the new leader - CharacterDatabase.PExecute( + trans->PAppend( "DELETE FROM group_instance WHERE guid=%u AND (permanent = 1 OR " "instance IN (SELECT instance FROM character_instance WHERE guid = '%u')" ")", GUID_LOPART(m_guid), GUID_LOPART(slot->guid) @@ -1371,8 +1370,8 @@ void Group::_setLeader(const uint64 &guid) Player::ConvertInstancesToGroup(player, this, slot->guid); // update the group leader - CharacterDatabase.PExecute("UPDATE groups SET leaderGuid='%u' WHERE guid='%u'", GUID_LOPART(slot->guid), GUID_LOPART(m_guid)); - CharacterDatabase.CommitTransaction(); + trans->PAppend("UPDATE groups SET leaderGuid='%u' WHERE guid='%u'", GUID_LOPART(slot->guid), GUID_LOPART(m_guid)); + CharacterDatabase.CommitTransaction(trans); } m_leaderGuid = slot->guid; |