From bdd7849094996392417ea3e5080578a04b69afac Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 19 May 2011 00:51:14 +0100 Subject: Allow item links to be deleted even when other deletes and purges are disabled. If these links are not deleted, then they will build up in the player's inventory until they can no longer log in. Accidental deletion of links due to bugs or other causes is potentially inconvenient but on a par with items being accidentally moved. When a link is deleted, the target of the link is never touched. This is a general solution that accounts for the use of links anywhere in the user's inventory. --- OpenSim/Data/MSSQL/MSSQLGenericTableHandler.cs | 35 +++++++++++++++++--------- 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'OpenSim/Data/MSSQL/MSSQLGenericTableHandler.cs') diff --git a/OpenSim/Data/MSSQL/MSSQLGenericTableHandler.cs b/OpenSim/Data/MSSQL/MSSQLGenericTableHandler.cs index f5492b3..317afac 100644 --- a/OpenSim/Data/MSSQL/MSSQLGenericTableHandler.cs +++ b/OpenSim/Data/MSSQL/MSSQLGenericTableHandler.cs @@ -335,24 +335,35 @@ namespace OpenSim.Data.MSSQL } } - public virtual bool Delete(string field, string val) + public virtual bool Delete(string field, string key) { + return Delete(new string[] { field }, new string[] { key }); + } + + public virtual bool Delete(string[] fields, string[] keys) + { + if (fields.Length != keys.Length) + return false; + + List terms = new List(); + using (SqlConnection conn = new SqlConnection(m_ConnectionString)) using (SqlCommand cmd = new SqlCommand()) { - string deleteCommand = String.Format("DELETE FROM {0} WHERE [{1}] = @{1}", m_Realm, field); - cmd.CommandText = deleteCommand; - - cmd.Parameters.Add(m_database.CreateParameter(field, val)); - cmd.Connection = conn; - conn.Open(); - - if (cmd.ExecuteNonQuery() > 0) + for (int i = 0; i < fields.Length; i++) { - //m_log.Warn("[MSSQLGenericTable]: " + deleteCommand); - return true; + cmd.Parameters.Add(m_database.CreateParameter(fields[i], keys[i])); + terms.Add("[" + fields[i] + "] = @" + fields[i]); } - return false; + + string where = String.Join(" AND ", terms.ToArray()); + + string query = String.Format("DELETE * FROM {0} WHERE {1}", m_Realm, where); + + cmd.Connection = conn; + cmd.CommandText = query; + conn.Open(); + return cmd.ExecuteNonQuery() > 0; } } } -- cgit v1.1