diff --git a/OpenSim/Data/MySQL/MySQLSimulationData.cs b/OpenSim/Data/MySQL/MySQLSimulationData.cs index 97c8c8bcb6..2b7e895f20 100644 --- a/OpenSim/Data/MySQL/MySQLSimulationData.cs +++ b/OpenSim/Data/MySQL/MySQLSimulationData.cs @@ -30,6 +30,7 @@ using System.Collections.Generic; using System.Data; using System.Drawing; using System.Reflection; +using System.Text; using log4net; using MySql.Data.MySqlClient; using OpenMetaverse; @@ -260,16 +261,7 @@ namespace OpenSim.Data.MySQL { // m_log.DebugFormat("[REGION DB]: Deleting scene object {0} from {1} in database", obj, regionUUID); - List uuids = new List(); - - // Formerly, this used to check the region UUID. - // That makes no sense, as we remove the contents of a prim - // unconditionally, but the prim dependent on the region ID. - // So, we would destroy an object and cause hard to detect - // issues if we delete the contents only. Deleting it all may - // cause the loss of a prim, but is cleaner. - // It's also faster because it uses the primary key. - // + List uuids = new List(); lock (m_dbLock) { using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) @@ -284,24 +276,49 @@ namespace OpenSim.Data.MySQL using (IDataReader reader = ExecuteReader(cmd)) { while (reader.Read()) - uuids.Add(DBGuid.FromDB(reader["UUID"].ToString())); + uuids.Add(reader["UUID"].ToString()); + } + + if(uuids.Count == 0) + { + dbcon.Close(); + return; } // delete the main prims cmd.CommandText = "delete from prims where SceneGroupID= ?UUID"; ExecuteNonQuery(cmd); - } - dbcon.Close(); - } - } - // there is no way this should be < 1 unless there is - // a very corrupt database, but in that case be extra - // safe anyway. - if (uuids.Count > 0) - { - RemoveShapes(uuids); - RemoveItems(uuids); + cmd.Parameters.Clear(); + + string sqlparams; + if (uuids.Count > 1) + { + StringBuilder sb = new StringBuilder(uuids.Count * 37); + sb.Append("IN ("); + for(int i = 0; i < uuids.Count - 1; ++i ) + { + sb.Append("'"); + sb.Append(uuids[i]); + sb.Append("',"); + } + sb.Append("'"); + sb.Append(uuids[uuids.Count - 1]); + sb.Append("')"); + sqlparams = sb.ToString(); + } + else + sqlparams = "='" + uuids[0] + "'"; + + cmd.CommandText = "delete from primshapes where UUID " + sqlparams; + ExecuteNonQuery(cmd); + + cmd.CommandText = "delete from primitems where PrimID " + sqlparams; + ExecuteNonQuery(cmd); + + dbcon.Close(); + } + } } }