From 9972b12812d343c48843057ddb2f4ea9c7f96bb4 Mon Sep 17 00:00:00 2001 From: Melanie Date: Sat, 26 Dec 2009 00:19:54 +0000 Subject: Add a generic REPLACE INTO handler for put into the generic table handler --- OpenSim/Data/MySQL/MySQLGenericTableHandler.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'OpenSim/Data/MySQL') diff --git a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs index 2f5937d..9b8a001 100644 --- a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs +++ b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs @@ -195,6 +195,31 @@ namespace OpenSim.Data.MySQL MySqlCommand cmd = new MySqlCommand(); string query = ""; + List names = new List(); + List values = new List(); + + foreach (FieldInfo fi in m_Fields.Values) + { + names.Add(fi.Name); + values.Add(fi.GetValue(row).ToString()); + } + + if (m_DataField != null) + { + Dictionary data = + (Dictionary)m_DataField.GetValue(row); + + foreach (KeyValuePair kvp in data) + { + names.Add(kvp.Key); + values.Add(kvp.Value); + } + } + + query = String.Format("replace into {0} (`", m_Realm) + String.Join("`,`", names.ToArray()) + "`) values ('" + String.Join("','", values.ToArray()) + "')"; + + if (ExecuteNonQuery(cmd) > 0) + return true; return false; } -- cgit v1.1 From 43c303e27a93f07022ed0b151ca6945e34169ee9 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 26 Dec 2009 03:24:46 +0100 Subject: Make the GenericTableHandler work as intended --- OpenSim/Data/MySQL/MySQLGenericTableHandler.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'OpenSim/Data/MySQL') diff --git a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs index 9b8a001..4dfc324 100644 --- a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs +++ b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs @@ -37,7 +37,7 @@ using OpenSim.Region.Framework.Interfaces; namespace OpenSim.Data.MySQL { - public class MySQLGenericTableHandler : MySqlFramework where T: struct + public class MySQLGenericTableHandler : MySqlFramework where T: class, new() { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -63,7 +63,7 @@ namespace OpenSim.Data.MySQL } Type t = typeof(T); - FieldInfo[] fields = t.GetFields(BindingFlags.NonPublic | + FieldInfo[] fields = t.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); @@ -165,7 +165,11 @@ namespace OpenSim.Data.MySQL new Dictionary(); foreach (string col in m_ColumnNames) + { data[col] = reader[col].ToString(); + if (data[col] == null) + data[col] = String.Empty; + } m_DataField.SetValue(row, data); } @@ -218,6 +222,8 @@ namespace OpenSim.Data.MySQL query = String.Format("replace into {0} (`", m_Realm) + String.Join("`,`", names.ToArray()) + "`) values ('" + String.Join("','", values.ToArray()) + "')"; + cmd.CommandText = query; + if (ExecuteNonQuery(cmd) > 0) return true; -- cgit v1.1