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/MySQL/MySQLGenericTableHandler.cs | 27 ++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'OpenSim/Data/MySQL/MySQLGenericTableHandler.cs') diff --git a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs index cfffbd8..754cf72 100644 --- a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs +++ b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs @@ -264,18 +264,33 @@ namespace OpenSim.Data.MySQL } } - 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 (MySqlCommand cmd = new MySqlCommand()) { + for (int i = 0 ; i < fields.Length ; i++) + { + cmd.Parameters.AddWithValue(fields[i], keys[i]); + terms.Add("`" + fields[i] + "` = ?" + fields[i]); + } - cmd.CommandText = String.Format("delete from {0} where `{1}` = ?{1}", m_Realm, field); - cmd.Parameters.AddWithValue(field, val); + string where = String.Join(" and ", terms.ToArray()); - if (ExecuteNonQuery(cmd) > 0) - return true; + string query = String.Format("delete from {0} where {1}", m_Realm, where); - return false; + cmd.CommandText = query; + + return ExecuteNonQuery(cmd) > 0; } } } -- cgit v1.1