aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLGenericTableHandler.cs')
-rw-r--r--OpenSim/Data/MySQL/MySQLGenericTableHandler.cs35
1 files changed, 33 insertions, 2 deletions
diff --git a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs
index 2f5937d..4dfc324 100644
--- a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs
+++ b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs
@@ -37,7 +37,7 @@ using OpenSim.Region.Framework.Interfaces;
37 37
38namespace OpenSim.Data.MySQL 38namespace OpenSim.Data.MySQL
39{ 39{
40 public class MySQLGenericTableHandler<T> : MySqlFramework where T: struct 40 public class MySQLGenericTableHandler<T> : MySqlFramework where T: class, new()
41 { 41 {
42 private static readonly ILog m_log = 42 private static readonly ILog m_log =
43 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 43 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@@ -63,7 +63,7 @@ namespace OpenSim.Data.MySQL
63 } 63 }
64 64
65 Type t = typeof(T); 65 Type t = typeof(T);
66 FieldInfo[] fields = t.GetFields(BindingFlags.NonPublic | 66 FieldInfo[] fields = t.GetFields(BindingFlags.Public |
67 BindingFlags.Instance | 67 BindingFlags.Instance |
68 BindingFlags.DeclaredOnly); 68 BindingFlags.DeclaredOnly);
69 69
@@ -165,7 +165,11 @@ namespace OpenSim.Data.MySQL
165 new Dictionary<string, string>(); 165 new Dictionary<string, string>();
166 166
167 foreach (string col in m_ColumnNames) 167 foreach (string col in m_ColumnNames)
168 {
168 data[col] = reader[col].ToString(); 169 data[col] = reader[col].ToString();
170 if (data[col] == null)
171 data[col] = String.Empty;
172 }
169 173
170 m_DataField.SetValue(row, data); 174 m_DataField.SetValue(row, data);
171 } 175 }
@@ -195,6 +199,33 @@ namespace OpenSim.Data.MySQL
195 MySqlCommand cmd = new MySqlCommand(); 199 MySqlCommand cmd = new MySqlCommand();
196 200
197 string query = ""; 201 string query = "";
202 List<String> names = new List<String>();
203 List<String> values = new List<String>();
204
205 foreach (FieldInfo fi in m_Fields.Values)
206 {
207 names.Add(fi.Name);
208 values.Add(fi.GetValue(row).ToString());
209 }
210
211 if (m_DataField != null)
212 {
213 Dictionary<string, string> data =
214 (Dictionary<string, string>)m_DataField.GetValue(row);
215
216 foreach (KeyValuePair<string, string> kvp in data)
217 {
218 names.Add(kvp.Key);
219 values.Add(kvp.Value);
220 }
221 }
222
223 query = String.Format("replace into {0} (`", m_Realm) + String.Join("`,`", names.ToArray()) + "`) values ('" + String.Join("','", values.ToArray()) + "')";
224
225 cmd.CommandText = query;
226
227 if (ExecuteNonQuery(cmd) > 0)
228 return true;
198 229
199 return false; 230 return false;
200 } 231 }