Use "REPLACE INTO" instead of "DELETE" + "INSERT INTO" in Item::SaveToDB call to fix a cause of items randomly disappearing (issue 925).
Note: due to the hierarchy of the function calls, it's not possible to use DB transactions in this function. --HG-- branch : trunk
This commit is contained in:
+4
-9
@@ -300,17 +300,14 @@ void Item::SaveToDB()
|
||||
switch (uState)
|
||||
{
|
||||
case ITEM_NEW:
|
||||
{
|
||||
CharacterDatabase.PExecute( "DELETE FROM item_instance WHERE guid = '%u'", guid );
|
||||
std::ostringstream ss;
|
||||
ss << "INSERT INTO item_instance (guid,owner_guid,data) VALUES (" << guid << "," << GUID_LOPART(GetOwnerGUID()) << ",'";
|
||||
ss << "REPLACE INTO item_instance (guid,owner_guid,data) VALUES (" << guid << "," << GUID_LOPART(GetOwnerGUID()) << ",'";
|
||||
for (uint16 i = 0; i < m_valuesCount; ++i )
|
||||
ss << GetUInt32Value(i) << " ";
|
||||
ss << "' )";
|
||||
CharacterDatabase.Execute( ss.str().c_str() );
|
||||
} break;
|
||||
CharacterDatabase.Execute(ss.str().c_str());
|
||||
break;
|
||||
case ITEM_CHANGED:
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << "UPDATE item_instance SET data = '";
|
||||
for (uint16 i = 0; i < m_valuesCount; ++i )
|
||||
@@ -321,9 +318,8 @@ void Item::SaveToDB()
|
||||
|
||||
if(HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPED))
|
||||
CharacterDatabase.PExecute("UPDATE character_gifts SET guid = '%u' WHERE item_guid = '%u'", GUID_LOPART(GetOwnerGUID()),GetGUIDLow());
|
||||
} break;
|
||||
break;
|
||||
case ITEM_REMOVED:
|
||||
{
|
||||
if (GetUInt32Value(ITEM_FIELD_ITEM_TEXT_ID) > 0 )
|
||||
CharacterDatabase.PExecute("DELETE FROM item_text WHERE id = '%u'", GetUInt32Value(ITEM_FIELD_ITEM_TEXT_ID));
|
||||
CharacterDatabase.PExecute("DELETE FROM item_instance WHERE guid = '%u'", guid);
|
||||
@@ -331,7 +327,6 @@ void Item::SaveToDB()
|
||||
CharacterDatabase.PExecute("DELETE FROM character_gifts WHERE item_guid = '%u'", GetGUIDLow());
|
||||
delete this;
|
||||
return;
|
||||
}
|
||||
case ITEM_UNCHANGED:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user