aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/SQLite/SQLiteEstateData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/SQLite/SQLiteEstateData.cs')
-rw-r--r--OpenSim/Data/SQLite/SQLiteEstateData.cs131
1 files changed, 89 insertions, 42 deletions
diff --git a/OpenSim/Data/SQLite/SQLiteEstateData.cs b/OpenSim/Data/SQLite/SQLiteEstateData.cs
index 1be99ee..9dd4a2e 100644
--- a/OpenSim/Data/SQLite/SQLiteEstateData.cs
+++ b/OpenSim/Data/SQLite/SQLiteEstateData.cs
@@ -30,7 +30,7 @@ using System.Collections.Generic;
30using System.Data; 30using System.Data;
31using System.Reflection; 31using System.Reflection;
32using log4net; 32using log4net;
33using Mono.Data.SqliteClient; 33using Mono.Data.Sqlite;
34using OpenMetaverse; 34using OpenMetaverse;
35using OpenSim.Framework; 35using OpenSim.Framework;
36using OpenSim.Region.Framework.Interfaces; 36using OpenSim.Region.Framework.Interfaces;
@@ -62,8 +62,8 @@ namespace OpenSim.Data.SQLite
62 Migration m = new Migration(m_connection, assem, "EstateStore"); 62 Migration m = new Migration(m_connection, assem, "EstateStore");
63 m.Update(); 63 m.Update();
64 64
65 m_connection.Close(); 65 //m_connection.Close();
66 m_connection.Open(); 66 // m_connection.Open();
67 67
68 Type t = typeof(EstateSettings); 68 Type t = typeof(EstateSettings);
69 m_Fields = t.GetFields(BindingFlags.NonPublic | 69 m_Fields = t.GetFields(BindingFlags.NonPublic |
@@ -80,17 +80,22 @@ namespace OpenSim.Data.SQLite
80 get { return new List<string>(m_FieldMap.Keys).ToArray(); } 80 get { return new List<string>(m_FieldMap.Keys).ToArray(); }
81 } 81 }
82 82
83 public EstateSettings LoadEstateSettings(UUID regionID) 83 public EstateSettings LoadEstateSettings(UUID regionID, bool create)
84 { 84 {
85 EstateSettings es = new EstateSettings();
86 es.OnSave += StoreEstateSettings;
87
88 string sql = "select estate_settings."+String.Join(",estate_settings.", FieldList)+" from estate_map left join estate_settings on estate_map.EstateID = estate_settings.EstateID where estate_settings.EstateID is not null and RegionID = :RegionID"; 85 string sql = "select estate_settings."+String.Join(",estate_settings.", FieldList)+" from estate_map left join estate_settings on estate_map.EstateID = estate_settings.EstateID where estate_settings.EstateID is not null and RegionID = :RegionID";
89 86
90 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); 87 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
91 88
92 cmd.CommandText = sql; 89 cmd.CommandText = sql;
93 cmd.Parameters.Add(":RegionID", regionID.ToString()); 90 cmd.Parameters.AddWithValue(":RegionID", regionID.ToString());
91
92 return DoLoad(cmd, regionID, create);
93 }
94
95 private EstateSettings DoLoad(SqliteCommand cmd, UUID regionID, bool create)
96 {
97 EstateSettings es = new EstateSettings();
98 es.OnSave += StoreEstateSettings;
94 99
95 IDataReader r = cmd.ExecuteReader(); 100 IDataReader r = cmd.ExecuteReader();
96 101
@@ -120,17 +125,15 @@ namespace OpenSim.Data.SQLite
120 } 125 }
121 r.Close(); 126 r.Close();
122 } 127 }
123 else 128 else if (create)
124 { 129 {
125 // Migration case
126 //
127 r.Close(); 130 r.Close();
128 131
129 List<string> names = new List<string>(FieldList); 132 List<string> names = new List<string>(FieldList);
130 133
131 names.Remove("EstateID"); 134 names.Remove("EstateID");
132 135
133 sql = "insert into estate_settings ("+String.Join(",", names.ToArray())+") values ( :"+String.Join(", :", names.ToArray())+")"; 136 string sql = "insert into estate_settings ("+String.Join(",", names.ToArray())+") values ( :"+String.Join(", :", names.ToArray())+")";
134 137
135 cmd.CommandText = sql; 138 cmd.CommandText = sql;
136 cmd.Parameters.Clear(); 139 cmd.Parameters.Clear();
@@ -140,13 +143,13 @@ namespace OpenSim.Data.SQLite
140 if (m_FieldMap[name].GetValue(es) is bool) 143 if (m_FieldMap[name].GetValue(es) is bool)
141 { 144 {
142 if ((bool)m_FieldMap[name].GetValue(es)) 145 if ((bool)m_FieldMap[name].GetValue(es))
143 cmd.Parameters.Add(":"+name, "1"); 146 cmd.Parameters.AddWithValue(":"+name, "1");
144 else 147 else
145 cmd.Parameters.Add(":"+name, "0"); 148 cmd.Parameters.AddWithValue(":"+name, "0");
146 } 149 }
147 else 150 else
148 { 151 {
149 cmd.Parameters.Add(":"+name, m_FieldMap[name].GetValue(es).ToString()); 152 cmd.Parameters.AddWithValue(":"+name, m_FieldMap[name].GetValue(es).ToString());
150 } 153 }
151 } 154 }
152 155
@@ -164,8 +167,8 @@ namespace OpenSim.Data.SQLite
164 r.Close(); 167 r.Close();
165 168
166 cmd.CommandText = "insert into estate_map values (:RegionID, :EstateID)"; 169 cmd.CommandText = "insert into estate_map values (:RegionID, :EstateID)";
167 cmd.Parameters.Add(":RegionID", regionID.ToString()); 170 cmd.Parameters.AddWithValue(":RegionID", regionID.ToString());
168 cmd.Parameters.Add(":EstateID", es.EstateID.ToString()); 171 cmd.Parameters.AddWithValue(":EstateID", es.EstateID.ToString());
169 172
170 // This will throw on dupe key 173 // This will throw on dupe key
171 try 174 try
@@ -176,20 +179,6 @@ namespace OpenSim.Data.SQLite
176 { 179 {
177 } 180 }
178 181
179 // Munge and transfer the ban list
180 //
181 cmd.Parameters.Clear();
182 cmd.CommandText = "insert into estateban select "+es.EstateID.ToString()+", bannedUUID, bannedIp, bannedIpHostMask, '' from regionban where regionban.regionUUID = :UUID";
183 cmd.Parameters.Add(":UUID", regionID.ToString());
184
185 try
186 {
187 cmd.ExecuteNonQuery();
188 }
189 catch (Exception)
190 {
191 }
192
193 es.Save(); 182 es.Save();
194 } 183 }
195 184
@@ -222,13 +211,13 @@ namespace OpenSim.Data.SQLite
222 if (m_FieldMap[name].GetValue(es) is bool) 211 if (m_FieldMap[name].GetValue(es) is bool)
223 { 212 {
224 if ((bool)m_FieldMap[name].GetValue(es)) 213 if ((bool)m_FieldMap[name].GetValue(es))
225 cmd.Parameters.Add(":"+name, "1"); 214 cmd.Parameters.AddWithValue(":"+name, "1");
226 else 215 else
227 cmd.Parameters.Add(":"+name, "0"); 216 cmd.Parameters.AddWithValue(":"+name, "0");
228 } 217 }
229 else 218 else
230 { 219 {
231 cmd.Parameters.Add(":"+name, m_FieldMap[name].GetValue(es).ToString()); 220 cmd.Parameters.AddWithValue(":"+name, m_FieldMap[name].GetValue(es).ToString());
232 } 221 }
233 } 222 }
234 223
@@ -247,7 +236,7 @@ namespace OpenSim.Data.SQLite
247 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); 236 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
248 237
249 cmd.CommandText = "select bannedUUID from estateban where EstateID = :EstateID"; 238 cmd.CommandText = "select bannedUUID from estateban where EstateID = :EstateID";
250 cmd.Parameters.Add(":EstateID", es.EstateID); 239 cmd.Parameters.AddWithValue(":EstateID", es.EstateID);
251 240
252 IDataReader r = cmd.ExecuteReader(); 241 IDataReader r = cmd.ExecuteReader();
253 242
@@ -271,7 +260,7 @@ namespace OpenSim.Data.SQLite
271 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); 260 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
272 261
273 cmd.CommandText = "delete from estateban where EstateID = :EstateID"; 262 cmd.CommandText = "delete from estateban where EstateID = :EstateID";
274 cmd.Parameters.Add(":EstateID", es.EstateID.ToString()); 263 cmd.Parameters.AddWithValue(":EstateID", es.EstateID.ToString());
275 264
276 cmd.ExecuteNonQuery(); 265 cmd.ExecuteNonQuery();
277 266
@@ -281,8 +270,8 @@ namespace OpenSim.Data.SQLite
281 270
282 foreach (EstateBan b in es.EstateBans) 271 foreach (EstateBan b in es.EstateBans)
283 { 272 {
284 cmd.Parameters.Add(":EstateID", es.EstateID.ToString()); 273 cmd.Parameters.AddWithValue(":EstateID", es.EstateID.ToString());
285 cmd.Parameters.Add(":bannedUUID", b.BannedUserID.ToString()); 274 cmd.Parameters.AddWithValue(":bannedUUID", b.BannedUserID.ToString());
286 275
287 cmd.ExecuteNonQuery(); 276 cmd.ExecuteNonQuery();
288 cmd.Parameters.Clear(); 277 cmd.Parameters.Clear();
@@ -294,7 +283,7 @@ namespace OpenSim.Data.SQLite
294 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); 283 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
295 284
296 cmd.CommandText = "delete from "+table+" where EstateID = :EstateID"; 285 cmd.CommandText = "delete from "+table+" where EstateID = :EstateID";
297 cmd.Parameters.Add(":EstateID", EstateID.ToString()); 286 cmd.Parameters.AddWithValue(":EstateID", EstateID.ToString());
298 287
299 cmd.ExecuteNonQuery(); 288 cmd.ExecuteNonQuery();
300 289
@@ -304,8 +293,8 @@ namespace OpenSim.Data.SQLite
304 293
305 foreach (UUID uuid in data) 294 foreach (UUID uuid in data)
306 { 295 {
307 cmd.Parameters.Add(":EstateID", EstateID.ToString()); 296 cmd.Parameters.AddWithValue(":EstateID", EstateID.ToString());
308 cmd.Parameters.Add(":uuid", uuid.ToString()); 297 cmd.Parameters.AddWithValue(":uuid", uuid.ToString());
309 298
310 cmd.ExecuteNonQuery(); 299 cmd.ExecuteNonQuery();
311 cmd.Parameters.Clear(); 300 cmd.Parameters.Clear();
@@ -319,7 +308,7 @@ namespace OpenSim.Data.SQLite
319 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); 308 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
320 309
321 cmd.CommandText = "select uuid from "+table+" where EstateID = :EstateID"; 310 cmd.CommandText = "select uuid from "+table+" where EstateID = :EstateID";
322 cmd.Parameters.Add(":EstateID", EstateID); 311 cmd.Parameters.AddWithValue(":EstateID", EstateID);
323 312
324 IDataReader r = cmd.ExecuteReader(); 313 IDataReader r = cmd.ExecuteReader();
325 314
@@ -336,5 +325,63 @@ namespace OpenSim.Data.SQLite
336 325
337 return uuids.ToArray(); 326 return uuids.ToArray();
338 } 327 }
328
329 public EstateSettings LoadEstateSettings(int estateID)
330 {
331 string sql = "select estate_settings."+String.Join(",estate_settings.", FieldList)+" from estate_settings where estate_settings.EstateID :EstateID";
332
333 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
334
335 cmd.CommandText = sql;
336 cmd.Parameters.AddWithValue(":EstateID", estateID.ToString());
337
338 return DoLoad(cmd, UUID.Zero, false);
339 }
340
341 public List<int> GetEstates(string search)
342 {
343 List<int> result = new List<int>();
344
345 string sql = "select EstateID from estate_settings where estate_settings.EstateName :EstateName";
346
347 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
348
349 cmd.CommandText = sql;
350 cmd.Parameters.AddWithValue(":EstateName", search);
351
352 IDataReader r = cmd.ExecuteReader();
353
354 while (r.Read())
355 {
356 result.Add(Convert.ToInt32(r["EstateID"]));
357 }
358 r.Close();
359
360 return result;
361 }
362
363 public bool LinkRegion(UUID regionID, int estateID)
364 {
365 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
366
367 cmd.CommandText = "insert into estate_map values (:RegionID, :EstateID)";
368 cmd.Parameters.AddWithValue(":RegionID", regionID.ToString());
369 cmd.Parameters.AddWithValue(":EstateID", estateID.ToString());
370
371 if (cmd.ExecuteNonQuery() == 0)
372 return false;
373
374 return true;
375 }
376
377 public List<UUID> GetRegions(int estateID)
378 {
379 return new List<UUID>();
380 }
381
382 public bool DeleteEstate(int estateID)
383 {
384 return false;
385 }
339 } 386 }
340} 387}