diff options
author | Justin Clark-Casey (justincc) | 2012-11-14 04:45:59 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-11-14 04:45:59 +0000 |
commit | 94da908813e42c328572bc5da2ddc41b6664b59c (patch) | |
tree | 1a3e1ffaadb34cac64c798f5cc06eadf612c6af9 /OpenSim/Data/SQLite/SQLiteEstateData.cs | |
parent | If no ISimulationDataStore or IEstateDataStore implementations could be loade... (diff) | |
download | opensim-SC-94da908813e42c328572bc5da2ddc41b6664b59c.zip opensim-SC-94da908813e42c328572bc5da2ddc41b6664b59c.tar.gz opensim-SC-94da908813e42c328572bc5da2ddc41b6664b59c.tar.bz2 opensim-SC-94da908813e42c328572bc5da2ddc41b6664b59c.tar.xz |
More consistently dispose of SqliteCommand in OpenSim.Data.SQLite where possible.
Not doing SQLiteInventoryStore since this is no longer used and should disappear in the future.
Diffstat (limited to 'OpenSim/Data/SQLite/SQLiteEstateData.cs')
-rw-r--r-- | OpenSim/Data/SQLite/SQLiteEstateData.cs | 206 |
1 files changed, 112 insertions, 94 deletions
diff --git a/OpenSim/Data/SQLite/SQLiteEstateData.cs b/OpenSim/Data/SQLite/SQLiteEstateData.cs index c042ba2..d51f2d4 100644 --- a/OpenSim/Data/SQLite/SQLiteEstateData.cs +++ b/OpenSim/Data/SQLite/SQLiteEstateData.cs | |||
@@ -104,12 +104,13 @@ namespace OpenSim.Data.SQLite | |||
104 | { | 104 | { |
105 | 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"; | 105 | 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"; |
106 | 106 | ||
107 | SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); | 107 | using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand()) |
108 | 108 | { | |
109 | cmd.CommandText = sql; | 109 | cmd.CommandText = sql; |
110 | cmd.Parameters.AddWithValue(":RegionID", regionID.ToString()); | 110 | cmd.Parameters.AddWithValue(":RegionID", regionID.ToString()); |
111 | 111 | ||
112 | return DoLoad(cmd, regionID, create); | 112 | return DoLoad(cmd, regionID, create); |
113 | } | ||
113 | } | 114 | } |
114 | 115 | ||
115 | private EstateSettings DoLoad(SqliteCommand cmd, UUID regionID, bool create) | 116 | private EstateSettings DoLoad(SqliteCommand cmd, UUID regionID, bool create) |
@@ -186,37 +187,39 @@ namespace OpenSim.Data.SQLite | |||
186 | { | 187 | { |
187 | List<string> names = new List<string>(FieldList); | 188 | List<string> names = new List<string>(FieldList); |
188 | 189 | ||
189 | SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); | ||
190 | IDataReader r = null; | 190 | IDataReader r = null; |
191 | 191 | ||
192 | names.Remove("EstateID"); | 192 | using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand()) |
193 | { | ||
194 | names.Remove("EstateID"); | ||
193 | 195 | ||
194 | string sql = "insert into estate_settings ("+String.Join(",", names.ToArray())+") values ( :"+String.Join(", :", names.ToArray())+")"; | 196 | string sql = "insert into estate_settings ("+String.Join(",", names.ToArray())+") values ( :"+String.Join(", :", names.ToArray())+")"; |
195 | 197 | ||
196 | cmd.CommandText = sql; | 198 | cmd.CommandText = sql; |
197 | cmd.Parameters.Clear(); | 199 | cmd.Parameters.Clear(); |
198 | 200 | ||
199 | foreach (string name in FieldList) | 201 | foreach (string name in FieldList) |
200 | { | ||
201 | if (m_FieldMap[name].GetValue(es) is bool) | ||
202 | { | 202 | { |
203 | if ((bool)m_FieldMap[name].GetValue(es)) | 203 | if (m_FieldMap[name].GetValue(es) is bool) |
204 | cmd.Parameters.AddWithValue(":"+name, "1"); | 204 | { |
205 | if ((bool)m_FieldMap[name].GetValue(es)) | ||
206 | cmd.Parameters.AddWithValue(":"+name, "1"); | ||
207 | else | ||
208 | cmd.Parameters.AddWithValue(":"+name, "0"); | ||
209 | } | ||
205 | else | 210 | else |
206 | cmd.Parameters.AddWithValue(":"+name, "0"); | 211 | { |
207 | } | 212 | cmd.Parameters.AddWithValue(":"+name, m_FieldMap[name].GetValue(es).ToString()); |
208 | else | 213 | } |
209 | { | ||
210 | cmd.Parameters.AddWithValue(":"+name, m_FieldMap[name].GetValue(es).ToString()); | ||
211 | } | 214 | } |
212 | } | ||
213 | 215 | ||
214 | cmd.ExecuteNonQuery(); | 216 | cmd.ExecuteNonQuery(); |
215 | 217 | ||
216 | cmd.CommandText = "select LAST_INSERT_ROWID() as id"; | 218 | cmd.CommandText = "select LAST_INSERT_ROWID() as id"; |
217 | cmd.Parameters.Clear(); | 219 | cmd.Parameters.Clear(); |
218 | 220 | ||
219 | r = cmd.ExecuteReader(); | 221 | r = cmd.ExecuteReader(); |
222 | } | ||
220 | 223 | ||
221 | r.Read(); | 224 | r.Read(); |
222 | 225 | ||
@@ -239,26 +242,27 @@ namespace OpenSim.Data.SQLite | |||
239 | 242 | ||
240 | string sql = "update estate_settings set "+String.Join(", ", terms.ToArray())+" where EstateID = :EstateID"; | 243 | string sql = "update estate_settings set "+String.Join(", ", terms.ToArray())+" where EstateID = :EstateID"; |
241 | 244 | ||
242 | SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); | 245 | using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand()) |
243 | |||
244 | cmd.CommandText = sql; | ||
245 | |||
246 | foreach (string name in FieldList) | ||
247 | { | 246 | { |
248 | if (m_FieldMap[name].GetValue(es) is bool) | 247 | cmd.CommandText = sql; |
248 | |||
249 | foreach (string name in FieldList) | ||
249 | { | 250 | { |
250 | if ((bool)m_FieldMap[name].GetValue(es)) | 251 | if (m_FieldMap[name].GetValue(es) is bool) |
251 | cmd.Parameters.AddWithValue(":"+name, "1"); | 252 | { |
253 | if ((bool)m_FieldMap[name].GetValue(es)) | ||
254 | cmd.Parameters.AddWithValue(":"+name, "1"); | ||
255 | else | ||
256 | cmd.Parameters.AddWithValue(":"+name, "0"); | ||
257 | } | ||
252 | else | 258 | else |
253 | cmd.Parameters.AddWithValue(":"+name, "0"); | 259 | { |
254 | } | 260 | cmd.Parameters.AddWithValue(":"+name, m_FieldMap[name].GetValue(es).ToString()); |
255 | else | 261 | } |
256 | { | ||
257 | cmd.Parameters.AddWithValue(":"+name, m_FieldMap[name].GetValue(es).ToString()); | ||
258 | } | 262 | } |
259 | } | ||
260 | 263 | ||
261 | cmd.ExecuteNonQuery(); | 264 | cmd.ExecuteNonQuery(); |
265 | } | ||
262 | 266 | ||
263 | SaveBanList(es); | 267 | SaveBanList(es); |
264 | SaveUUIDList(es.EstateID, "estate_managers", es.EstateManagers); | 268 | SaveUUIDList(es.EstateID, "estate_managers", es.EstateManagers); |
@@ -270,12 +274,15 @@ namespace OpenSim.Data.SQLite | |||
270 | { | 274 | { |
271 | es.ClearBans(); | 275 | es.ClearBans(); |
272 | 276 | ||
273 | SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); | 277 | IDataReader r; |
274 | 278 | ||
275 | cmd.CommandText = "select bannedUUID from estateban where EstateID = :EstateID"; | 279 | using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand()) |
276 | cmd.Parameters.AddWithValue(":EstateID", es.EstateID); | 280 | { |
281 | cmd.CommandText = "select bannedUUID from estateban where EstateID = :EstateID"; | ||
282 | cmd.Parameters.AddWithValue(":EstateID", es.EstateID); | ||
277 | 283 | ||
278 | IDataReader r = cmd.ExecuteReader(); | 284 | r = cmd.ExecuteReader(); |
285 | } | ||
279 | 286 | ||
280 | while (r.Read()) | 287 | while (r.Read()) |
281 | { | 288 | { |
@@ -294,60 +301,64 @@ namespace OpenSim.Data.SQLite | |||
294 | 301 | ||
295 | private void SaveBanList(EstateSettings es) | 302 | private void SaveBanList(EstateSettings es) |
296 | { | 303 | { |
297 | SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); | 304 | using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand()) |
298 | |||
299 | cmd.CommandText = "delete from estateban where EstateID = :EstateID"; | ||
300 | cmd.Parameters.AddWithValue(":EstateID", es.EstateID.ToString()); | ||
301 | |||
302 | cmd.ExecuteNonQuery(); | ||
303 | |||
304 | cmd.Parameters.Clear(); | ||
305 | |||
306 | cmd.CommandText = "insert into estateban (EstateID, bannedUUID, bannedIp, bannedIpHostMask, bannedNameMask) values ( :EstateID, :bannedUUID, '', '', '' )"; | ||
307 | |||
308 | foreach (EstateBan b in es.EstateBans) | ||
309 | { | 305 | { |
306 | cmd.CommandText = "delete from estateban where EstateID = :EstateID"; | ||
310 | cmd.Parameters.AddWithValue(":EstateID", es.EstateID.ToString()); | 307 | cmd.Parameters.AddWithValue(":EstateID", es.EstateID.ToString()); |
311 | cmd.Parameters.AddWithValue(":bannedUUID", b.BannedUserID.ToString()); | ||
312 | 308 | ||
313 | cmd.ExecuteNonQuery(); | 309 | cmd.ExecuteNonQuery(); |
310 | |||
314 | cmd.Parameters.Clear(); | 311 | cmd.Parameters.Clear(); |
312 | |||
313 | cmd.CommandText = "insert into estateban (EstateID, bannedUUID, bannedIp, bannedIpHostMask, bannedNameMask) values ( :EstateID, :bannedUUID, '', '', '' )"; | ||
314 | |||
315 | foreach (EstateBan b in es.EstateBans) | ||
316 | { | ||
317 | cmd.Parameters.AddWithValue(":EstateID", es.EstateID.ToString()); | ||
318 | cmd.Parameters.AddWithValue(":bannedUUID", b.BannedUserID.ToString()); | ||
319 | |||
320 | cmd.ExecuteNonQuery(); | ||
321 | cmd.Parameters.Clear(); | ||
322 | } | ||
315 | } | 323 | } |
316 | } | 324 | } |
317 | 325 | ||
318 | void SaveUUIDList(uint EstateID, string table, UUID[] data) | 326 | void SaveUUIDList(uint EstateID, string table, UUID[] data) |
319 | { | 327 | { |
320 | SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); | 328 | using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand()) |
321 | |||
322 | cmd.CommandText = "delete from "+table+" where EstateID = :EstateID"; | ||
323 | cmd.Parameters.AddWithValue(":EstateID", EstateID.ToString()); | ||
324 | |||
325 | cmd.ExecuteNonQuery(); | ||
326 | |||
327 | cmd.Parameters.Clear(); | ||
328 | |||
329 | cmd.CommandText = "insert into "+table+" (EstateID, uuid) values ( :EstateID, :uuid )"; | ||
330 | |||
331 | foreach (UUID uuid in data) | ||
332 | { | 329 | { |
330 | cmd.CommandText = "delete from "+table+" where EstateID = :EstateID"; | ||
333 | cmd.Parameters.AddWithValue(":EstateID", EstateID.ToString()); | 331 | cmd.Parameters.AddWithValue(":EstateID", EstateID.ToString()); |
334 | cmd.Parameters.AddWithValue(":uuid", uuid.ToString()); | ||
335 | 332 | ||
336 | cmd.ExecuteNonQuery(); | 333 | cmd.ExecuteNonQuery(); |
334 | |||
337 | cmd.Parameters.Clear(); | 335 | cmd.Parameters.Clear(); |
336 | |||
337 | cmd.CommandText = "insert into "+table+" (EstateID, uuid) values ( :EstateID, :uuid )"; | ||
338 | |||
339 | foreach (UUID uuid in data) | ||
340 | { | ||
341 | cmd.Parameters.AddWithValue(":EstateID", EstateID.ToString()); | ||
342 | cmd.Parameters.AddWithValue(":uuid", uuid.ToString()); | ||
343 | |||
344 | cmd.ExecuteNonQuery(); | ||
345 | cmd.Parameters.Clear(); | ||
346 | } | ||
338 | } | 347 | } |
339 | } | 348 | } |
340 | 349 | ||
341 | UUID[] LoadUUIDList(uint EstateID, string table) | 350 | UUID[] LoadUUIDList(uint EstateID, string table) |
342 | { | 351 | { |
343 | List<UUID> uuids = new List<UUID>(); | 352 | List<UUID> uuids = new List<UUID>(); |
353 | IDataReader r; | ||
344 | 354 | ||
345 | SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); | 355 | using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand()) |
346 | 356 | { | |
347 | cmd.CommandText = "select uuid from "+table+" where EstateID = :EstateID"; | 357 | cmd.CommandText = "select uuid from "+table+" where EstateID = :EstateID"; |
348 | cmd.Parameters.AddWithValue(":EstateID", EstateID); | 358 | cmd.Parameters.AddWithValue(":EstateID", EstateID); |
349 | 359 | ||
350 | IDataReader r = cmd.ExecuteReader(); | 360 | r = cmd.ExecuteReader(); |
361 | } | ||
351 | 362 | ||
352 | while (r.Read()) | 363 | while (r.Read()) |
353 | { | 364 | { |
@@ -367,12 +378,13 @@ namespace OpenSim.Data.SQLite | |||
367 | { | 378 | { |
368 | string sql = "select estate_settings."+String.Join(",estate_settings.", FieldList)+" from estate_settings where estate_settings.EstateID = :EstateID"; | 379 | string sql = "select estate_settings."+String.Join(",estate_settings.", FieldList)+" from estate_settings where estate_settings.EstateID = :EstateID"; |
369 | 380 | ||
370 | SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); | 381 | using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand()) |
371 | 382 | { | |
372 | cmd.CommandText = sql; | 383 | cmd.CommandText = sql; |
373 | cmd.Parameters.AddWithValue(":EstateID", estateID.ToString()); | 384 | cmd.Parameters.AddWithValue(":EstateID", estateID.ToString()); |
374 | 385 | ||
375 | return DoLoad(cmd, UUID.Zero, false); | 386 | return DoLoad(cmd, UUID.Zero, false); |
387 | } | ||
376 | } | 388 | } |
377 | 389 | ||
378 | public List<EstateSettings> LoadEstateSettingsAll() | 390 | public List<EstateSettings> LoadEstateSettingsAll() |
@@ -391,13 +403,15 @@ namespace OpenSim.Data.SQLite | |||
391 | List<int> result = new List<int>(); | 403 | List<int> result = new List<int>(); |
392 | 404 | ||
393 | string sql = "select EstateID from estate_settings where estate_settings.EstateName = :EstateName"; | 405 | string sql = "select EstateID from estate_settings where estate_settings.EstateName = :EstateName"; |
406 | IDataReader r; | ||
394 | 407 | ||
395 | SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); | 408 | using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand()) |
396 | 409 | { | |
397 | cmd.CommandText = sql; | 410 | cmd.CommandText = sql; |
398 | cmd.Parameters.AddWithValue(":EstateName", search); | 411 | cmd.Parameters.AddWithValue(":EstateName", search); |
399 | 412 | ||
400 | IDataReader r = cmd.ExecuteReader(); | 413 | r = cmd.ExecuteReader(); |
414 | } | ||
401 | 415 | ||
402 | while (r.Read()) | 416 | while (r.Read()) |
403 | { | 417 | { |
@@ -413,12 +427,14 @@ namespace OpenSim.Data.SQLite | |||
413 | List<int> result = new List<int>(); | 427 | List<int> result = new List<int>(); |
414 | 428 | ||
415 | string sql = "select EstateID from estate_settings"; | 429 | string sql = "select EstateID from estate_settings"; |
430 | IDataReader r; | ||
416 | 431 | ||
417 | SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); | 432 | using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand()) |
418 | 433 | { | |
419 | cmd.CommandText = sql; | 434 | cmd.CommandText = sql; |
420 | 435 | ||
421 | IDataReader r = cmd.ExecuteReader(); | 436 | r = cmd.ExecuteReader(); |
437 | } | ||
422 | 438 | ||
423 | while (r.Read()) | 439 | while (r.Read()) |
424 | { | 440 | { |
@@ -434,13 +450,15 @@ namespace OpenSim.Data.SQLite | |||
434 | List<int> result = new List<int>(); | 450 | List<int> result = new List<int>(); |
435 | 451 | ||
436 | string sql = "select EstateID from estate_settings where estate_settings.EstateOwner = :EstateOwner"; | 452 | string sql = "select EstateID from estate_settings where estate_settings.EstateOwner = :EstateOwner"; |
453 | IDataReader r; | ||
437 | 454 | ||
438 | SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); | 455 | using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand()) |
439 | 456 | { | |
440 | cmd.CommandText = sql; | 457 | cmd.CommandText = sql; |
441 | cmd.Parameters.AddWithValue(":EstateOwner", ownerID); | 458 | cmd.Parameters.AddWithValue(":EstateOwner", ownerID); |
442 | 459 | ||
443 | IDataReader r = cmd.ExecuteReader(); | 460 | r = cmd.ExecuteReader(); |
461 | } | ||
444 | 462 | ||
445 | while (r.Read()) | 463 | while (r.Read()) |
446 | { | 464 | { |