aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs414
1 files changed, 347 insertions, 67 deletions
diff --git a/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs b/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs
index 478e8b5..804fd5f 100644
--- a/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs
+++ b/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs
@@ -26,22 +26,26 @@
26* 26*
27*/ 27*/
28using System; 28using System;
29using System.Collections.Generic; 29using System.IO;
30using System.Data; 30using System.Data;
31using System.Reflection;
32using System.Collections.Generic;
31using libsecondlife; 33using libsecondlife;
32using OpenSim.Framework.Types; 34using OpenSim.Framework.Types;
35using OpenSim.Framework.Console;
36using MySql.Data.MySqlClient;
33 37
34namespace OpenSim.Framework.Data.MySQL 38namespace OpenSim.Framework.Data.MySQL
35{ 39{
36 /// <summary> 40 /// <summary>
37 /// A MySQL interface for the inventory server 41 /// A MySQL interface for the inventory server
38 /// </summary> 42 /// </summary>
39 class MySQLInventoryData : IInventoryData 43 public class MySQLInventoryData : IInventoryData
40 { 44 {
41 /// <summary> 45 /// <summary>
42 /// The database manager 46 /// The database manager
43 /// </summary> 47 /// </summary>
44 public MySQLManager database; 48 private MySQLManager database;
45 49
46 /// <summary> 50 /// <summary>
47 /// Loads and initialises this database plugin 51 /// Loads and initialises this database plugin
@@ -57,8 +61,101 @@ namespace OpenSim.Framework.Data.MySQL
57 string settingPort = GridDataMySqlFile.ParseFileReadValue("port"); 61 string settingPort = GridDataMySqlFile.ParseFileReadValue("port");
58 62
59 database = new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword, settingPooling, settingPort); 63 database = new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword, settingPooling, settingPort);
64 TestTables(database.Connection);
60 } 65 }
61 66
67 #region Test and initialization code
68 /// <summary>
69 /// Extract a named string resource from the embedded resources
70 /// </summary>
71 /// <param name="name">name of embedded resource</param>
72 /// <returns>string contained within the embedded resource</returns>
73 private string getResourceString(string name)
74 {
75 Assembly assem = this.GetType().Assembly;
76 string[] names = assem.GetManifestResourceNames();
77
78 foreach(string s in names)
79 if(s.EndsWith(name))
80 using (Stream resource = assem.GetManifestResourceStream(s))
81 {
82 using (StreamReader resourceReader = new StreamReader(resource))
83 {
84 string resourceString = resourceReader.ReadToEnd();
85 return resourceString;
86 }
87 }
88 throw new Exception(string.Format("Resource '{0}' was not found", name));
89 }
90
91 private void ExecuteResourceSql(MySqlConnection conn, string name)
92 {
93 MySqlCommand cmd = new MySqlCommand(getResourceString(name), conn);
94 cmd.ExecuteNonQuery();
95 }
96
97 private void UpgradeFoldersTable(MySqlConnection conn, string oldVersion)
98 {
99 // null as the version, indicates that the table didn't exist
100 if (oldVersion == null)
101 {
102 ExecuteResourceSql(conn, "CreateFoldersTable.sql");
103 return;
104 }
105
106 // if the table is already at the current version, then we can exit immediately
107 if (oldVersion == "Rev. 2")
108 return;
109
110 ExecuteResourceSql(conn, "UpgradeFoldersTableToVersion2.sql");
111 }
112
113 private void UpgradeItemsTable(MySqlConnection conn, string oldVersion)
114 {
115 // null as the version, indicates that the table didn't exist
116 if (oldVersion == null)
117 {
118 ExecuteResourceSql(conn, "CreateItemsTable.sql");
119 return;
120 }
121
122 // if the table is already at the current version, then we can exit immediately
123 if (oldVersion == "Rev. 2")
124 return;
125
126 ExecuteResourceSql(conn, "UpgradeItemsTableToVersion2.sql");
127 }
128
129 private void TestTables(MySqlConnection conn)
130 {
131
132 Dictionary<string, string> tableList = new Dictionary<string, string>();
133
134 tableList["inventoryfolders"] = null;
135 tableList["inventoryitems"] = null;
136
137 MySqlCommand tablesCmd = new MySqlCommand("SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='opensim'", conn);
138 MySqlDataReader tables = tablesCmd.ExecuteReader();
139 while (tables.Read())
140 {
141 try
142 {
143 string tableName = (string)tables["TABLE_NAME"];
144 string comment = (string)tables["TABLE_COMMENT"];
145 tableList[tableName] = comment;
146 }
147 catch (Exception e)
148 {
149 MainLog.Instance.Error(e.ToString());
150 }
151 }
152 tables.Close();
153
154 UpgradeFoldersTable(conn, tableList["inventoryfolders"]);
155 UpgradeItemsTable(conn, tableList["inventoryitems"]);
156 }
157 #endregion
158
62 /// <summary> 159 /// <summary>
63 /// The name of this DB provider 160 /// The name of this DB provider
64 /// </summary> 161 /// </summary>
@@ -82,7 +179,12 @@ namespace OpenSim.Framework.Data.MySQL
82 /// <returns>A string containing the DB provider</returns> 179 /// <returns>A string containing the DB provider</returns>
83 public string getVersion() 180 public string getVersion()
84 { 181 {
85 return "0.1"; 182 System.Reflection.Module module = this.GetType().Module;
183 string dllName = module.Assembly.ManifestModule.Name;
184 Version dllVersion = module.Assembly.GetName().Version;
185
186
187 return string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, dllVersion.Revision);
86 } 188 }
87 189
88 /// <summary> 190 /// <summary>
@@ -96,13 +198,14 @@ namespace OpenSim.Framework.Data.MySQL
96 { 198 {
97 lock (database) 199 lock (database)
98 { 200 {
99 Dictionary<string, string> param = new Dictionary<string, string>(); 201 List<InventoryItemBase> items = new List<InventoryItemBase>();
100 param["?uuid"] = folderID.ToStringHyphenated();
101 202
102 IDbCommand result = database.Query("SELECT * FROM inventoryitems WHERE parentFolderID = ?uuid", param); 203 MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE parentFolderID = ?uuid", database.Connection);
103 IDataReader reader = result.ExecuteReader(); 204 result.Parameters.Add("?uuid", folderID.ToStringHyphenated());
205 MySqlDataReader reader = result.ExecuteReader();
104 206
105 List<InventoryItemBase> items = database.readInventoryItems(reader); 207 while(reader.Read())
208 items.Add(readInventoryItem(reader));
106 209
107 reader.Close(); 210 reader.Close();
108 result.Dispose(); 211 result.Dispose();
@@ -113,7 +216,7 @@ namespace OpenSim.Framework.Data.MySQL
113 catch (Exception e) 216 catch (Exception e)
114 { 217 {
115 database.Reconnect(); 218 database.Reconnect();
116 Console.WriteLine(e.ToString()); 219 MainLog.Instance.Error(e.ToString());
117 return null; 220 return null;
118 } 221 }
119 } 222 }
@@ -129,14 +232,15 @@ namespace OpenSim.Framework.Data.MySQL
129 { 232 {
130 lock (database) 233 lock (database)
131 { 234 {
132 Dictionary<string, string> param = new Dictionary<string, string>(); 235 MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", database.Connection);
133 param["?uuid"] = user.ToStringHyphenated(); 236 result.Parameters.Add("?uuid", user.ToStringHyphenated());
134 param["?zero"] = LLUUID.Zero.ToStringHyphenated(); 237 result.Parameters.Add("?zero", LLUUID.Zero.ToStringHyphenated());
238 MySqlDataReader reader = result.ExecuteReader();
135 239
136 IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", param); 240 List<InventoryFolderBase> items = new List<InventoryFolderBase>();
137 IDataReader reader = result.ExecuteReader(); 241 while(reader.Read())
242 items.Add(readInventoryFolder(reader));
138 243
139 List<InventoryFolderBase> items = database.readInventoryFolders(reader);
140 244
141 reader.Close(); 245 reader.Close();
142 result.Dispose(); 246 result.Dispose();
@@ -147,7 +251,7 @@ namespace OpenSim.Framework.Data.MySQL
147 catch (Exception e) 251 catch (Exception e)
148 { 252 {
149 database.Reconnect(); 253 database.Reconnect();
150 Console.WriteLine(e.ToString()); 254 MainLog.Instance.Error(e.ToString());
151 return null; 255 return null;
152 } 256 }
153 } 257 }
@@ -167,10 +271,16 @@ namespace OpenSim.Framework.Data.MySQL
167 param["?uuid"] = user.ToStringHyphenated(); 271 param["?uuid"] = user.ToStringHyphenated();
168 param["?zero"] = LLUUID.Zero.ToStringHyphenated(); 272 param["?zero"] = LLUUID.Zero.ToStringHyphenated();
169 273
170 IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", param); 274 MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", database.Connection);
171 IDataReader reader = result.ExecuteReader(); 275 result.Parameters.Add("?uuid", user.ToStringHyphenated());
276 result.Parameters.Add("?zero", LLUUID.Zero.ToStringHyphenated());
277
278 MySqlDataReader reader = result.ExecuteReader();
279
280 List<InventoryFolderBase> items = new List<InventoryFolderBase>();
281 while(reader.Read())
282 items.Add(readInventoryFolder(reader));
172 283
173 List<InventoryFolderBase> items = database.readInventoryFolders(reader);
174 InventoryFolderBase rootFolder = items[0]; //should only be one folder with parent set to zero (the root one). 284 InventoryFolderBase rootFolder = items[0]; //should only be one folder with parent set to zero (the root one).
175 reader.Close(); 285 reader.Close();
176 result.Dispose(); 286 result.Dispose();
@@ -181,7 +291,7 @@ namespace OpenSim.Framework.Data.MySQL
181 catch (Exception e) 291 catch (Exception e)
182 { 292 {
183 database.Reconnect(); 293 database.Reconnect();
184 Console.WriteLine(e.ToString()); 294 MainLog.Instance.Error(e.ToString());
185 return null; 295 return null;
186 } 296 }
187 } 297 }
@@ -197,13 +307,14 @@ namespace OpenSim.Framework.Data.MySQL
197 { 307 {
198 lock (database) 308 lock (database)
199 { 309 {
200 Dictionary<string, string> param = new Dictionary<string, string>(); 310 MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?uuid", database.Connection);
201 param["?uuid"] = parentID.ToStringHyphenated(); 311 result.Parameters.Add("?uuid", parentID.ToStringHyphenated());
312 MySqlDataReader reader = result.ExecuteReader();
202 313
203 IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = ?uuid", param); 314 List<InventoryFolderBase> items = new List<InventoryFolderBase>();
204 IDataReader reader = result.ExecuteReader(); 315
205 316 while(reader.Read())
206 List<InventoryFolderBase> items = database.readInventoryFolders(reader); 317 items.Add(readInventoryFolder(reader));
207 318
208 reader.Close(); 319 reader.Close();
209 result.Dispose(); 320 result.Dispose();
@@ -214,87 +325,134 @@ namespace OpenSim.Framework.Data.MySQL
214 catch (Exception e) 325 catch (Exception e)
215 { 326 {
216 database.Reconnect(); 327 database.Reconnect();
217 Console.WriteLine(e.ToString()); 328 MainLog.Instance.Error(e.ToString());
218 return null; 329 return null;
219 } 330 }
220 } 331 }
221 332
222 /// <summary> 333 /// <summary>
334 /// Reads a one item from an SQL result
335 /// </summary>
336 /// <param name="reader">The SQL Result</param>
337 /// <returns>the item read</returns>
338 public InventoryItemBase readInventoryItem(MySqlDataReader reader)
339 {
340 try
341 {
342 InventoryItemBase item = new InventoryItemBase();
343
344 item.inventoryID = new LLUUID((string)reader["inventoryID"]);
345 item.assetID = new LLUUID((string)reader["assetID"]);
346 item.assetType = (int)reader["assetType"];
347 item.parentFolderID = new LLUUID((string)reader["parentFolderID"]);
348 item.avatarID = new LLUUID((string)reader["avatarID"]);
349 item.inventoryName = (string)reader["inventoryName"];
350 item.inventoryDescription = (string)reader["inventoryDescription"];
351 item.inventoryNextPermissions = (uint)reader["inventoryNextPermissions"];
352 item.inventoryCurrentPermissions = (uint)reader["inventoryCurrentPermissions"];
353 item.invType = (int)reader["invType"];
354 item.creatorsID = new LLUUID((string)reader["creatorID"]);
355 item.inventoryBasePermissions = (uint)reader["inventoryBasePermissions"];
356 item.inventoryEveryOnePermissions = (uint)reader["inventoryEveryOnePermissions"];
357 return item;
358 }
359 catch (MySqlException e)
360 {
361 MainLog.Instance.Error(e.ToString());
362 }
363
364 return null;
365 }
366
367 /// <summary>
223 /// Returns a specified inventory item 368 /// Returns a specified inventory item
224 /// </summary> 369 /// </summary>
225 /// <param name="item">The item to return</param> 370 /// <param name="item">The item to return</param>
226 /// <returns>An inventory item</returns> 371 /// <returns>An inventory item</returns>
227 public InventoryItemBase getInventoryItem(LLUUID item) 372 public InventoryItemBase getInventoryItem(LLUUID itemID)
228 { 373 {
229 try 374 try
230 { 375 {
231 lock (database) 376 lock (database)
232 { 377 {
233 Dictionary<string, string> param = new Dictionary<string, string>(); 378 Dictionary<string, string> param = new Dictionary<string, string>();
234 param["?uuid"] = item.ToStringHyphenated();
235 379
236 IDbCommand result = database.Query("SELECT * FROM inventoryitems WHERE inventoryID = ?uuid", param); 380 MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE inventoryID = ?uuid", database.Connection);
237 IDataReader reader = result.ExecuteReader(); 381 result.Parameters.Add("?uuid", itemID.ToStringHyphenated());
382 MySqlDataReader reader = result.ExecuteReader();
238 383
239 List<InventoryItemBase> items = database.readInventoryItems(reader); 384 InventoryItemBase item = null;
385 if(reader.Read())
386 item = readInventoryItem(reader);
240 387
241 reader.Close(); 388 reader.Close();
242 result.Dispose(); 389 result.Dispose();
243 390
244 if (items.Count > 0) 391 return item;
245 {
246 return items[0];
247 }
248 else
249 {
250 return null;
251 }
252 } 392 }
253 } 393 }
254 catch (Exception e) 394 catch (Exception e)
255 { 395 {
256 database.Reconnect(); 396 database.Reconnect();
257 Console.WriteLine(e.ToString()); 397 MainLog.Instance.Error(e.ToString());
258 return null;
259 } 398 }
399 return null;
260 } 400 }
261 401
262 /// <summary> 402 /// <summary>
403 /// Reads a list of inventory folders returned by a query.
404 /// </summary>
405 /// <param name="reader">A MySQL Data Reader</param>
406 /// <returns>A List containing inventory folders</returns>
407 protected InventoryFolderBase readInventoryFolder(MySqlDataReader reader)
408 {
409 try
410 {
411 InventoryFolderBase folder = new InventoryFolderBase();
412 folder.agentID = new LLUUID((string)reader["agentID"]);
413 folder.parentID = new LLUUID((string)reader["parentFolderID"]);
414 folder.folderID = new LLUUID((string)reader["folderID"]);
415 folder.name = (string)reader["folderName"];
416 folder.type = (short)reader["type"];
417 folder.version = (ushort)((int)reader["version"]);
418 return folder;
419 }
420 catch (Exception e)
421 {
422 MainLog.Instance.Error(e.ToString());
423 }
424
425 return null;
426 }
427
428
429 /// <summary>
263 /// Returns a specified inventory folder 430 /// Returns a specified inventory folder
264 /// </summary> 431 /// </summary>
265 /// <param name="folder">The folder to return</param> 432 /// <param name="folder">The folder to return</param>
266 /// <returns>A folder class</returns> 433 /// <returns>A folder class</returns>
267 public InventoryFolderBase getInventoryFolder(LLUUID folder) 434 public InventoryFolderBase getInventoryFolder(LLUUID folderID)
268 { 435 {
269 try 436 try
270 { 437 {
271 lock (database) 438 lock (database)
272 { 439 {
273 Dictionary<string, string> param = new Dictionary<string, string>(); 440 MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", database.Connection);
274 param["?uuid"] = folder.ToStringHyphenated(); 441 result.Parameters.Add("?uuid", folderID.ToStringHyphenated());
275 442 MySqlDataReader reader = result.ExecuteReader();
276 IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", param);
277 IDataReader reader = result.ExecuteReader();
278
279 List<InventoryFolderBase> items = database.readInventoryFolders(reader);
280 443
444 reader.Read();
445 InventoryFolderBase folder = readInventoryFolder(reader);
281 reader.Close(); 446 reader.Close();
282 result.Dispose(); 447 result.Dispose();
283 448
284 if (items.Count > 0) 449 return folder;
285 {
286 return items[0];
287 }
288 else
289 {
290 return null;
291 }
292 } 450 }
293 } 451 }
294 catch (Exception e) 452 catch (Exception e)
295 { 453 {
296 database.Reconnect(); 454 database.Reconnect();
297 Console.WriteLine(e.ToString()); 455 MainLog.Instance.Error(e.ToString());
298 return null; 456 return null;
299 } 457 }
300 } 458 }
@@ -305,9 +463,31 @@ namespace OpenSim.Framework.Data.MySQL
305 /// <param name="item">The inventory item</param> 463 /// <param name="item">The inventory item</param>
306 public void addInventoryItem(InventoryItemBase item) 464 public void addInventoryItem(InventoryItemBase item)
307 { 465 {
308 lock (database) 466 string sql = "REPLACE INTO inventoryitems (inventoryID, assetID, assetType, parentFolderID, avatarID, inventoryName, inventoryDescription, inventoryNextPermissions, inventoryCurrentPermissions, invType, creatorID, inventoryBasePermissions, inventoryEveryOnePermissions) VALUES ";
467 sql += "(?inventoryID, ?assetID, ?assetType, ?parentFolderID, ?avatarID, ?inventoryName, ?inventoryDescription, ?inventoryNextPermissions, ?inventoryCurrentPermissions, ?invType, ?creatorID, ?inventoryBasePermissions, ?inventoryEveryOnePermissions)";
468
469 try
309 { 470 {
310 database.insertItem(item); 471 MySqlCommand result = new MySqlCommand(sql, database.Connection);
472 result.Parameters.Add("?inventoryID", item.inventoryID.ToStringHyphenated());
473 result.Parameters.Add("?assetID", item.assetID.ToStringHyphenated());
474 result.Parameters.Add("?assetType", item.assetType.ToString());
475 result.Parameters.Add("?parentFolderID", item.parentFolderID.ToStringHyphenated());
476 result.Parameters.Add("?avatarID", item.avatarID.ToStringHyphenated());
477 result.Parameters.Add("?inventoryName", item.inventoryName);
478 result.Parameters.Add("?inventoryDescription", item.inventoryDescription);
479 result.Parameters.Add("?inventoryNextPermissions", item.inventoryNextPermissions.ToString());
480 result.Parameters.Add("?inventoryCurrentPermissions", item.inventoryCurrentPermissions.ToString());
481 result.Parameters.Add("?invType", item.invType);
482 result.Parameters.Add("?creatorID", item.creatorsID.ToStringHyphenated());
483 result.Parameters.Add("?inventoryBasePermissions", item.inventoryBasePermissions);
484 result.Parameters.Add("?inventoryEveryOnePermissions", item.inventoryEveryOnePermissions);
485 result.ExecuteNonQuery();
486 result.Dispose();
487 }
488 catch (MySqlException e)
489 {
490 MainLog.Instance.Error(e.ToString());
311 } 491 }
312 } 492 }
313 493
@@ -324,9 +504,19 @@ namespace OpenSim.Framework.Data.MySQL
324 /// 504 ///
325 /// </summary> 505 /// </summary>
326 /// <param name="item"></param> 506 /// <param name="item"></param>
327 public void deleteInventoryItem(InventoryItemBase item) 507 public void deleteInventoryItem(LLUUID itemID)
328 { 508 {
329 509 try
510 {
511 MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryitems WHERE inventoryID=?uuid", database.Connection);
512 cmd.Parameters.Add("?uuid", itemID.ToStringHyphenated());
513 cmd.ExecuteNonQuery();
514 }
515 catch (MySqlException e)
516 {
517 database.Reconnect();
518 MainLog.Instance.Error(e.ToString());
519 }
330 } 520 }
331 521
332 /// <summary> 522 /// <summary>
@@ -335,9 +525,24 @@ namespace OpenSim.Framework.Data.MySQL
335 /// <param name="folder">Folder to create</param> 525 /// <param name="folder">Folder to create</param>
336 public void addInventoryFolder(InventoryFolderBase folder) 526 public void addInventoryFolder(InventoryFolderBase folder)
337 { 527 {
338 lock (database) 528 string sql = "REPLACE INTO inventoryfolders (folderID, agentID, parentFolderID, folderName, type, version) VALUES ";
529 sql += "(?folderID, ?agentID, ?parentFolderID, ?folderName, ?type, ?version)";
530
531 MySqlCommand cmd = new MySqlCommand(sql, database.Connection);
532 cmd.Parameters.Add("?folderID", folder.folderID.ToStringHyphenated());
533 cmd.Parameters.Add("?agentID", folder.agentID.ToStringHyphenated());
534 cmd.Parameters.Add("?parentFolderID", folder.parentID.ToStringHyphenated());
535 cmd.Parameters.Add("?folderName", folder.name);
536 cmd.Parameters.Add("?type", (short)folder.type);
537 cmd.Parameters.Add("?version", folder.version);
538
539 try
540 {
541 cmd.ExecuteNonQuery();
542 }
543 catch (Exception e)
339 { 544 {
340 database.insertFolder(folder); 545 MainLog.Instance.Error(e.ToString());
341 } 546 }
342 } 547 }
343 548
@@ -352,11 +557,86 @@ namespace OpenSim.Framework.Data.MySQL
352 557
353 558
354 /// <summary> 559 /// <summary>
560 /// Append a list of all the child folders of a parent folder
561 /// </summary>
562 /// <param name="folders">list where folders will be appended</param>
563 /// <param name="parentID">ID of parent</param>
564 protected void getInventoryFolders(ref List<InventoryFolderBase> folders, LLUUID parentID)
565 {
566 List<InventoryFolderBase> subfolderList = getInventoryFolders(parentID);
567
568 foreach (InventoryFolderBase f in subfolderList)
569 folders.Add(f);
570 }
571
572 /// <summary>
573 /// Returns all child folders in the hierarchy from the parent folder and down
574 /// </summary>
575 /// <param name="parentID">The folder to get subfolders for</param>
576 /// <returns>A list of inventory folders</returns>
577 protected List<InventoryFolderBase> getFolderHierarchy(LLUUID parentID)
578 {
579 List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
580 getInventoryFolders(ref folders, parentID);
581
582 for (int i = 0; i < folders.Count; i++)
583 getInventoryFolders(ref folders, folders[i].folderID);
584
585 return folders;
586 }
587
588 protected void deleteOneFolder(LLUUID folderID)
589 {
590 try
591 {
592 MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryfolders WHERE folderID=?uuid", database.Connection);
593 cmd.Parameters.Add("?uuid", folderID.ToStringHyphenated());
594 cmd.ExecuteNonQuery();
595 }
596 catch (MySqlException e)
597 {
598 database.Reconnect();
599 MainLog.Instance.Error(e.ToString());
600 }
601 }
602
603 protected void deleteItemsInFolder(LLUUID folderID)
604 {
605 try
606 {
607 MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryitems WHERE parentFolderID=?uuid", database.Connection);
608 cmd.Parameters.Add("?uuid", folderID.ToStringHyphenated());
609 cmd.ExecuteNonQuery();
610 }
611 catch (MySqlException e)
612 {
613 database.Reconnect();
614 MainLog.Instance.Error(e.ToString());
615 }
616 }
617
618
619 /// <summary>
355 /// Delete an inventory folder 620 /// Delete an inventory folder
356 /// </summary> 621 /// </summary>
357 /// <param name="folderId">Id of folder to delete</param> 622 /// <param name="folderId">Id of folder to delete</param>
358 public void deleteInventoryFolder(LLUUID folderID) 623 public void deleteInventoryFolder(LLUUID folderID)
359 { 624 {
625 lock (database)
626 {
627 List<InventoryFolderBase> subFolders = getFolderHierarchy(folderID);
628
629 //Delete all sub-folders
630 foreach (InventoryFolderBase f in subFolders)
631 {
632 deleteOneFolder(f.folderID);
633 deleteItemsInFolder(f.folderID);
634 }
635
636 //Delete the actual row
637 deleteOneFolder(folderID);
638 deleteItemsInFolder(folderID);
639 }
360 } 640 }
361 } 641 }
362} 642}