aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MSSQL/MSSQLInventoryData.cs
diff options
context:
space:
mode:
authorMelanie Thielker2008-09-14 13:23:02 +0000
committerMelanie Thielker2008-09-14 13:23:02 +0000
commit281955949910eb257b5f7e42e54535ba7812418e (patch)
tree8c62c0006f2567983a686e811513c8c009061aac /OpenSim/Data/MSSQL/MSSQLInventoryData.cs
parent* Converted a number of methods within the login processes from private to pr... (diff)
downloadopensim-SC_OLD-281955949910eb257b5f7e42e54535ba7812418e.zip
opensim-SC_OLD-281955949910eb257b5f7e42e54535ba7812418e.tar.gz
opensim-SC_OLD-281955949910eb257b5f7e42e54535ba7812418e.tar.bz2
opensim-SC_OLD-281955949910eb257b5f7e42e54535ba7812418e.tar.xz
Mantis #2124
Thank you, RuudL, for a patch that brings MSSQL up to the same implementation level as MySQL.
Diffstat (limited to 'OpenSim/Data/MSSQL/MSSQLInventoryData.cs')
-rw-r--r--OpenSim/Data/MSSQL/MSSQLInventoryData.cs818
1 files changed, 425 insertions, 393 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLInventoryData.cs b/OpenSim/Data/MSSQL/MSSQLInventoryData.cs
index e7df7c1..03600e2 100644
--- a/OpenSim/Data/MSSQL/MSSQLInventoryData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLInventoryData.cs
@@ -41,49 +41,53 @@ namespace OpenSim.Data.MSSQL
41 /// </summary> 41 /// </summary>
42 public class MSSQLInventoryData : IInventoryDataPlugin 42 public class MSSQLInventoryData : IInventoryDataPlugin
43 { 43 {
44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 44 private const string _migrationStore = "InventoryStore";
45 45
46 #region Helper converters to preserve unsigned bitfield-type data in DB roundtrips via signed int32s 46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 private static int ConvertUint32BitFieldToInt32(uint bitField)
48 {
49 return BitConverter.ToInt32(BitConverter.GetBytes(bitField), 0);
50 }
51 private static uint ConvertInt32BitFieldToUint32(int bitField)
52 {
53 return BitConverter.ToUInt32(BitConverter.GetBytes(bitField), 0);
54 }
55 #endregion
56 47
57 /// <summary> 48 /// <summary>
58 /// The database manager 49 /// The database manager
59 /// </summary> 50 /// </summary>
60 private MSSQLManager database; 51 private MSSQLManager database;
61 52
62 public void Initialise() 53 #region IPlugin members
63 { 54
55 public void Initialise()
56 {
64 m_log.Info("[MSSQLInventoryData]: " + Name + " cannot be default-initialized!"); 57 m_log.Info("[MSSQLInventoryData]: " + Name + " cannot be default-initialized!");
65 throw new PluginNotInitialisedException (Name); 58 throw new PluginNotInitialisedException(Name);
66 } 59 }
67 60
68 /// <summary> 61 /// <summary>
69 /// Loads and initialises the MSSQL inventory storage interface 62 /// Loads and initialises the MSSQL inventory storage interface
70 /// </summary> 63 /// </summary>
71 /// <param name="connect">connect string</param> 64 /// <param name="connectionString">connect string</param>
72 /// <remarks>use mssql_connection.ini</remarks> 65 /// <remarks>use mssql_connection.ini</remarks>
73 public void Initialise(string connect) 66 public void Initialise(string connectionString)
74 { 67 {
75 // TODO: actually use the provided connect string 68 if (string.IsNullOrEmpty(connectionString))
76 IniFile gridDataMSSqlFile = new IniFile("mssql_connection.ini"); 69 {
77 string settingDataSource = gridDataMSSqlFile.ParseFileReadValue("data_source"); 70 database = new MSSQLManager(connectionString);
78 string settingInitialCatalog = gridDataMSSqlFile.ParseFileReadValue("initial_catalog"); 71 }
79 string settingPersistSecurityInfo = gridDataMSSqlFile.ParseFileReadValue("persist_security_info"); 72 else
80 string settingUserId = gridDataMSSqlFile.ParseFileReadValue("user_id"); 73 {
81 string settingPassword = gridDataMSSqlFile.ParseFileReadValue("password"); 74 IniFile gridDataMSSqlFile = new IniFile("mssql_connection.ini");
82 75 string settingDataSource = gridDataMSSqlFile.ParseFileReadValue("data_source");
83 database = 76 string settingInitialCatalog = gridDataMSSqlFile.ParseFileReadValue("initial_catalog");
84 new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, 77 string settingPersistSecurityInfo = gridDataMSSqlFile.ParseFileReadValue("persist_security_info");
85 settingPassword); 78 string settingUserId = gridDataMSSqlFile.ParseFileReadValue("user_id");
79 string settingPassword = gridDataMSSqlFile.ParseFileReadValue("password");
80
81 database =
82 new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId,
83 settingPassword);
84 }
85
86 //TODO remove this at one point
86 TestTables(); 87 TestTables();
88
89 //New migrations check of store
90 database.CheckMigration(_migrationStore);
87 } 91 }
88 92
89 #region Test and initialization code 93 #region Test and initialization code
@@ -132,6 +136,37 @@ namespace OpenSim.Data.MSSQL
132 136
133 UpgradeFoldersTable(tableList["inventoryfolders"]); 137 UpgradeFoldersTable(tableList["inventoryfolders"]);
134 UpgradeItemsTable(tableList["inventoryitems"]); 138 UpgradeItemsTable(tableList["inventoryitems"]);
139
140 using (AutoClosingSqlCommand cmd = database.Query("select * from migrations where name = '" + _migrationStore + "'"))
141 {
142 //Special for Migrations to create backword compatible
143 try
144 {
145 bool insert = true;
146 using (SqlDataReader reader = cmd.ExecuteReader())
147 {
148 if (reader.Read()) insert = false;
149 }
150 if (insert)
151 {
152 cmd.CommandText = "insert into migrations(name, version) values('" + _migrationStore + "', 1)";
153 cmd.ExecuteNonQuery();
154 }
155 }
156 catch
157 {
158 //No migrations table
159 //HACK create one and add data
160 cmd.CommandText = "create table migrations(name varchar(100), version int)";
161 cmd.ExecuteNonQuery();
162
163 cmd.CommandText = "insert into migrations(name, version) values('migrations', 1)";
164 cmd.ExecuteNonQuery();
165
166 cmd.CommandText = "insert into migrations(name, version) values('" + _migrationStore + "', 1)";
167 cmd.ExecuteNonQuery();
168 }
169 }
135 } 170 }
136 171
137 #endregion 172 #endregion
@@ -150,7 +185,7 @@ namespace OpenSim.Data.MSSQL
150 /// </summary> 185 /// </summary>
151 public void Dispose() 186 public void Dispose()
152 { 187 {
153 // Do nothing. 188 database = null;
154 } 189 }
155 190
156 /// <summary> 191 /// <summary>
@@ -162,39 +197,9 @@ namespace OpenSim.Data.MSSQL
162 get { return database.getVersion(); } 197 get { return database.getVersion(); }
163 } 198 }
164 199
165 /// <summary> 200 #endregion
166 /// Returns a list of items in a specified folder
167 /// </summary>
168 /// <param name="folderID">The folder to search</param>
169 /// <returns>A list containing inventory items</returns>
170 public List<InventoryItemBase> getInventoryInFolder(UUID folderID)
171 {
172 try
173 {
174 List<InventoryItemBase> items = new List<InventoryItemBase>();
175
176 Dictionary<string, string> param = new Dictionary<string, string>();
177 param["parentFolderID"] = folderID.ToString();
178
179 using (IDbCommand result =
180 database.Query("SELECT * FROM inventoryitems WHERE parentFolderID = @parentFolderID", param))
181 using (IDataReader reader = result.ExecuteReader())
182 {
183
184 while (reader.Read())
185 items.Add(readInventoryItem(reader));
186
187 reader.Close();
188 }
189 201
190 return items; 202 #region Folder methods
191 }
192 catch (Exception e)
193 {
194 m_log.Error(e.ToString());
195 return null;
196 }
197 }
198 203
199 /// <summary> 204 /// <summary>
200 /// Returns a list of the root folders within a users inventory 205 /// Returns a list of the root folders within a users inventory
@@ -203,31 +208,7 @@ namespace OpenSim.Data.MSSQL
203 /// <returns>A list of folder objects</returns> 208 /// <returns>A list of folder objects</returns>
204 public List<InventoryFolderBase> getUserRootFolders(UUID user) 209 public List<InventoryFolderBase> getUserRootFolders(UUID user)
205 { 210 {
206 try 211 return getInventoryFolders(UUID.Zero, user);
207 {
208 Dictionary<string, string> param = new Dictionary<string, string>();
209 param["uuid"] = user.ToString();
210 param["zero"] = UUID.Zero.ToString();
211
212 using (IDbCommand result =
213 database.Query(
214 "SELECT * FROM inventoryfolders WHERE parentFolderID = @zero AND agentID = @uuid", param))
215 using (IDataReader reader = result.ExecuteReader())
216 {
217
218 List<InventoryFolderBase> items = new List<InventoryFolderBase>();
219 while (reader.Read())
220 items.Add(readInventoryFolder(reader));
221
222 return items;
223 }
224
225 }
226 catch (Exception e)
227 {
228 m_log.Error(e.ToString());
229 return null;
230 }
231 } 212 }
232 213
233 /// <summary> 214 /// <summary>
@@ -237,43 +218,21 @@ namespace OpenSim.Data.MSSQL
237 /// <returns></returns> 218 /// <returns></returns>
238 public InventoryFolderBase getUserRootFolder(UUID user) 219 public InventoryFolderBase getUserRootFolder(UUID user)
239 { 220 {
240 try 221 List<InventoryFolderBase> items = getUserRootFolders(user);
241 {
242 Dictionary<string, string> param = new Dictionary<string, string>();
243 param["uuid"] = user.ToString();
244 param["zero"] = UUID.Zero.ToString();
245
246 using (IDbCommand result =
247 database.Query(
248 "SELECT * FROM inventoryfolders WHERE parentFolderID = @zero AND agentID = @uuid", param))
249 using (IDataReader reader = result.ExecuteReader())
250 {
251
252 List<InventoryFolderBase> items = new List<InventoryFolderBase>();
253 while (reader.Read())
254 items.Add(readInventoryFolder(reader));
255
256 InventoryFolderBase rootFolder = null;
257 222
258 // There should only ever be one root folder for a user. However, if there's more 223 InventoryFolderBase rootFolder = null;
259 // than one we'll simply use the first one rather than failing. It would be even
260 // nicer to print some message to this effect, but this feels like it's too low a
261 // to put such a message out, and it's too minor right now to spare the time to
262 // suitably refactor.
263 if (items.Count > 0)
264 {
265 rootFolder = items[0];
266 }
267
268 return rootFolder;
269 }
270 224
271 } 225 // There should only ever be one root folder for a user. However, if there's more
272 catch (Exception e) 226 // than one we'll simply use the first one rather than failing. It would be even
227 // nicer to print some message to this effect, but this feels like it's too low a
228 // to put such a message out, and it's too minor right now to spare the time to
229 // suitably refactor.
230 if (items.Count > 0)
273 { 231 {
274 m_log.Error(e.ToString()); 232 rootFolder = items[0];
275 return null;
276 } 233 }
234
235 return rootFolder;
277 } 236 }
278 237
279 /// <summary> 238 /// <summary>
@@ -283,156 +242,235 @@ namespace OpenSim.Data.MSSQL
283 /// <returns>A list of inventory folders</returns> 242 /// <returns>A list of inventory folders</returns>
284 public List<InventoryFolderBase> getInventoryFolders(UUID parentID) 243 public List<InventoryFolderBase> getInventoryFolders(UUID parentID)
285 { 244 {
286 try 245 return getInventoryFolders(parentID, UUID.Zero);
246 }
247
248 /// <summary>
249 /// Returns a specified inventory folder
250 /// </summary>
251 /// <param name="folderID">The folder to return</param>
252 /// <returns>A folder class</returns>
253 public InventoryFolderBase getInventoryFolder(UUID folderID)
254 {
255 using (AutoClosingSqlCommand command = database.Query("SELECT * FROM inventoryfolders WHERE folderID = @folderID"))
287 { 256 {
288 Dictionary<string, string> param = new Dictionary<string, string>(); 257 command.Parameters.Add(database.CreateParameter("folderID", folderID));
289 param["parentFolderID"] = parentID.ToString();
290 258
291 using (IDbCommand result = 259 using (IDataReader reader = command.ExecuteReader())
292 database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = @parentFolderID", param))
293 using (IDataReader reader = result.ExecuteReader())
294 { 260 {
295 List<InventoryFolderBase> items = new List<InventoryFolderBase>(); 261 if (reader.Read())
296 262 {
297 while (reader.Read()) 263 return readInventoryFolder(reader);
298 items.Add(readInventoryFolder(reader)); 264 }
299
300 return items;
301 } 265 }
302 } 266 }
303 catch (Exception e) 267 m_log.InfoFormat("[INVENTORY DB] : FOund no inventory folder with ID : {0}", folderID);
304 { 268 return null;
305 m_log.Error(e.ToString());
306 return null;
307 }
308 } 269 }
309 270
310 /// <summary> 271 /// <summary>
311 /// Reads a one item from an SQL result 272 /// Returns all child folders in the hierarchy from the parent folder and down.
273 /// Does not return the parent folder itself.
312 /// </summary> 274 /// </summary>
313 /// <param name="reader">The SQL Result</param> 275 /// <param name="parentID">The folder to get subfolders for</param>
314 /// <returns>the item read</returns> 276 /// <returns>A list of inventory folders</returns>
315 private static InventoryItemBase readInventoryItem(IDataReader reader) 277 public List<InventoryFolderBase> getFolderHierarchy(UUID parentID)
316 { 278 {
317 try 279 //Note maybe change this to use a Dataset that loading in all folders of a user and then go throw it that way.
318 { 280 //Note this is changed so it opens only one connection to the database and not everytime it wants to get data.
319 InventoryItemBase item = new InventoryItemBase();
320 281
321 item.ID = new UUID((string) reader["inventoryID"]); 282 List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
322 item.AssetID = new UUID((string) reader["assetID"]);
323 item.AssetType = (int) reader["assetType"];
324 item.Folder = new UUID((string) reader["parentFolderID"]);
325 item.Owner = new UUID((string) reader["avatarID"]);
326 item.Name = (string) reader["inventoryName"];
327 item.Description = (string) reader["inventoryDescription"];
328 item.NextPermissions = ConvertInt32BitFieldToUint32((int)reader["inventoryNextPermissions"]);
329 item.CurrentPermissions = ConvertInt32BitFieldToUint32((int)reader["inventoryCurrentPermissions"]);
330 item.InvType = (int) reader["invType"];
331 item.Creator = new UUID((string) reader["creatorID"]);
332 item.BasePermissions = ConvertInt32BitFieldToUint32((int)reader["inventoryBasePermissions"]);
333 item.EveryOnePermissions = ConvertInt32BitFieldToUint32((int)reader["inventoryEveryOnePermissions"]);
334 item.SalePrice = (int) reader["salePrice"];
335 item.SaleType = Convert.ToByte(reader["saleType"]);
336 item.CreationDate = (int) reader["creationDate"];
337 item.GroupID = new UUID(reader["groupID"].ToString());
338 item.GroupOwned = Convert.ToBoolean(reader["groupOwned"]);
339 item.Flags = ConvertInt32BitFieldToUint32((int)reader["flags"]);
340 283
341 return item; 284 using (AutoClosingSqlCommand command = database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = @parentID"))
342 }
343 catch (SqlException e)
344 { 285 {
345 m_log.Error(e.ToString()); 286 command.Parameters.Add(database.CreateParameter("@parentID", parentID));
346 }
347 287
348 return null; 288 folders.AddRange(getInventoryFolders(command));
289
290 List<InventoryFolderBase> tempFolders = new List<InventoryFolderBase>();
291
292 foreach (InventoryFolderBase folderBase in folders)
293 {
294 tempFolders.AddRange(getFolderHierarchy(folderBase.ID, command));
295 }
296 if (tempFolders.Count > 0)
297 {
298 folders.AddRange(tempFolders);
299 }
300 }
301 return folders;
349 } 302 }
350 303
351 /// <summary> 304 /// <summary>
352 /// Returns a specified inventory item 305 /// Creates a new inventory folder
353 /// </summary> 306 /// </summary>
354 /// <param name="item">The item to return</param> 307 /// <param name="folder">Folder to create</param>
355 /// <returns>An inventory item</returns> 308 public void addInventoryFolder(InventoryFolderBase folder)
356 public InventoryItemBase getInventoryItem(UUID itemID)
357 { 309 {
358 try 310 string sql =
359 { 311 "INSERT INTO inventoryfolders ([folderID], [agentID], [parentFolderID], [folderName], [type], [version]) VALUES ";
360 Dictionary<string, string> param = new Dictionary<string, string>(); 312 sql += "(@folderID, @agentID, @parentFolderID, @folderName, @type, @version);";
361 param["inventoryID"] = itemID.ToString();
362 313
363 using (IDbCommand result =
364 database.Query("SELECT * FROM inventoryitems WHERE inventoryID = @inventoryID", param))
365 using (IDataReader reader = result.ExecuteReader())
366 {
367 314
368 InventoryItemBase item = null; 315 using (AutoClosingSqlCommand command = database.Query(sql))
369 if (reader.Read()) 316 {
370 item = readInventoryItem(reader); 317 command.Parameters.Add(database.CreateParameter("folderID", folder.ID));
318 command.Parameters.Add(database.CreateParameter("agentID", folder.Owner));
319 command.Parameters.Add(database.CreateParameter("parentFolderID", folder.ParentID));
320 command.Parameters.Add(database.CreateParameter("folderName", folder.Name));
321 command.Parameters.Add(database.CreateParameter("type", folder.Type));
322 command.Parameters.Add(database.CreateParameter("version", folder.Version));
371 323
372 return item; 324 try
325 {
326 //IDbCommand result = database.Query(sql, param);
327 command.ExecuteNonQuery();
328 }
329 catch (Exception e)
330 {
331 m_log.ErrorFormat("[ASSET DB] Error : {0}", e.Message);
373 } 332 }
374 } 333 }
375 catch (Exception e)
376 {
377 m_log.Error(e.ToString());
378 }
379 return null;
380 } 334 }
381 335
382 /// <summary> 336 /// <summary>
383 /// Reads a list of inventory folders returned by a query. 337 /// Updates an inventory folder
384 /// </summary> 338 /// </summary>
385 /// <param name="reader">A MSSQL Data Reader</param> 339 /// <param name="folder">Folder to update</param>
386 /// <returns>A List containing inventory folders</returns> 340 public void updateInventoryFolder(InventoryFolderBase folder)
387 protected static InventoryFolderBase readInventoryFolder(IDataReader reader)
388 { 341 {
389 try 342 using (AutoClosingSqlCommand command = database.Query("UPDATE inventoryfolders set folderID = @folderID, " +
343 "agentID = @agentID, " +
344 "parentFolderID = @parentFolderID," +
345 "folderName = @folderName," +
346 "type = @type," +
347 "version = @version where " +
348 "folderID = @keyFolderID;"))
390 { 349 {
391 InventoryFolderBase folder = new InventoryFolderBase(); 350 command.Parameters.Add(database.CreateParameter("folderID", folder.ID));
392 folder.Owner = new UUID((string) reader["agentID"]); 351 command.Parameters.Add(database.CreateParameter("agentID", folder.Owner));
393 folder.ParentID = new UUID((string) reader["parentFolderID"]); 352 command.Parameters.Add(database.CreateParameter("parentFolderID", folder.ParentID));
394 folder.ID = new UUID((string) reader["folderID"]); 353 command.Parameters.Add(database.CreateParameter("folderName", folder.Name));
395 folder.Name = (string) reader["folderName"]; 354 command.Parameters.Add(database.CreateParameter("type", folder.Type));
396 folder.Type = (short) reader["type"]; 355 command.Parameters.Add(database.CreateParameter("version", folder.Version));
397 folder.Version = Convert.ToUInt16(reader["version"]); 356 command.Parameters.Add(database.CreateParameter("@keyFolderID", folder.ID));
398 return folder; 357 try
358 {
359 command.ExecuteNonQuery();
360 }
361 catch (Exception e)
362 {
363 m_log.ErrorFormat("[ASSET DB] Error : {0}", e.Message);
364 }
399 } 365 }
400 catch (Exception e) 366 }
367
368 /// <summary>
369 /// Updates an inventory folder
370 /// </summary>
371 /// <param name="folder">Folder to update</param>
372 public void moveInventoryFolder(InventoryFolderBase folder)
373 {
374 using (IDbCommand command = database.Query("UPDATE inventoryfolders set " +
375 "parentFolderID = @parentFolderID where " +
376 "folderID = @folderID;"))
401 { 377 {
402 m_log.Error(e.ToString()); 378 command.Parameters.Add(database.CreateParameter("parentFolderID", folder.ParentID));
403 } 379 command.Parameters.Add(database.CreateParameter("@folderID", folder.ID));
404 380
405 return null; 381 try
382 {
383 command.ExecuteNonQuery();
384 }
385 catch (Exception e)
386 {
387 m_log.ErrorFormat("[ASSET DB] Error : {0}", e.Message);
388 }
389 }
406 } 390 }
407 391
408 /// <summary> 392 /// <summary>
409 /// Returns a specified inventory folder 393 /// Delete an inventory folder
410 /// </summary> 394 /// </summary>
411 /// <param name="folder">The folder to return</param> 395 /// <param name="folderID">Id of folder to delete</param>
412 /// <returns>A folder class</returns> 396 public void deleteInventoryFolder(UUID folderID)
413 public InventoryFolderBase getInventoryFolder(UUID folderID)
414 { 397 {
415 try 398 using (SqlConnection connection = database.DatabaseConnection())
416 { 399 {
417 Dictionary<string, string> param = new Dictionary<string, string>(); 400 List<InventoryFolderBase> subFolders;
418 param["uuid"] = folderID.ToString(); 401 using (SqlCommand command = new SqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = @parentID", connection))
402 {
403 command.Parameters.Add(database.CreateParameter("@parentID", string.Empty));
419 404
420 using (IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE folderID = @uuid", param)) 405 AutoClosingSqlCommand autoCommand = new AutoClosingSqlCommand(command);
421 using (IDataReader reader = result.ExecuteReader()) 406
407 subFolders = getFolderHierarchy(folderID, autoCommand);
408 }
409
410 //Delete all sub-folders
411 foreach (InventoryFolderBase f in subFolders)
422 { 412 {
413 DeleteOneFolder(f.ID, connection);
414 DeleteItemsInFolder(f.ID, connection);
415 }
423 416
424 reader.Read(); 417 //Delete the actual row
418 DeleteOneFolder(folderID, connection);
419 DeleteItemsInFolder(folderID, connection);
420
421 connection.Close();
422 }
423 }
424
425 #endregion
425 426
426 InventoryFolderBase folder = readInventoryFolder(reader); 427 #region Item Methods
428
429 /// <summary>
430 /// Returns a list of items in a specified folder
431 /// </summary>
432 /// <param name="folderID">The folder to search</param>
433 /// <returns>A list containing inventory items</returns>
434 public List<InventoryItemBase> getInventoryInFolder(UUID folderID)
435 {
436 using (AutoClosingSqlCommand command = database.Query("SELECT * FROM inventoryitems WHERE parentFolderID = @parentFolderID"))
437 {
438 command.Parameters.Add(database.CreateParameter("parentFolderID", folderID));
439
440 List<InventoryItemBase> items = new List<InventoryItemBase>();
427 441
428 return folder; 442 using (SqlDataReader reader = command.ExecuteReader())
443 {
444 while (reader.Read())
445 {
446 items.Add(readInventoryItem(reader));
447 }
429 } 448 }
449 return items;
430 } 450 }
431 catch (Exception e) 451 }
452
453 /// <summary>
454 /// Returns a specified inventory item
455 /// </summary>
456 /// <param name="itemID">The item ID</param>
457 /// <returns>An inventory item</returns>
458 public InventoryItemBase getInventoryItem(UUID itemID)
459 {
460 using (AutoClosingSqlCommand result = database.Query("SELECT * FROM inventoryitems WHERE inventoryID = @inventoryID"))
432 { 461 {
433 m_log.Error(e.ToString()); 462 result.Parameters.Add(database.CreateParameter("inventoryID", itemID));
434 return null; 463
464 using (IDataReader reader = result.ExecuteReader())
465 {
466 if (reader.Read())
467 {
468 return readInventoryItem(reader);
469 }
470 }
435 } 471 }
472 m_log.InfoFormat("[INVENTORY DB] : Found no inventory item with ID : {0}", itemID);
473 return null;
436 } 474 }
437 475
438 /// <summary> 476 /// <summary>
@@ -448,46 +486,44 @@ namespace OpenSim.Data.MSSQL
448 } 486 }
449 487
450 string sql = "INSERT INTO inventoryitems"; 488 string sql = "INSERT INTO inventoryitems";
451 sql += 489 sql += "([inventoryID], [assetID], [assetType], [parentFolderID], [avatarID], [inventoryName]"
452 "([inventoryID], [assetID], [assetType], [parentFolderID], [avatarID], [inventoryName]"
453 + ", [inventoryDescription], [inventoryNextPermissions], [inventoryCurrentPermissions]" 490 + ", [inventoryDescription], [inventoryNextPermissions], [inventoryCurrentPermissions]"
454 + ", [invType], [creatorID], [inventoryBasePermissions], [inventoryEveryOnePermissions]" 491 + ", [invType], [creatorID], [inventoryBasePermissions], [inventoryEveryOnePermissions]"
455 + ", [salePrice], [saleType], [creationDate], [groupID], [groupOwned], [flags]) VALUES "; 492 + ", [salePrice], [saleType], [creationDate], [groupID], [groupOwned], [flags]) VALUES ";
456 sql += 493 sql += "(@inventoryID, @assetID, @assetType, @parentFolderID, @avatarID, @inventoryName, @inventoryDescription"
457 "(@inventoryID, @assetID, @assetType, @parentFolderID, @avatarID, @inventoryName, @inventoryDescription"
458 + ", @inventoryNextPermissions, @inventoryCurrentPermissions, @invType, @creatorID" 494 + ", @inventoryNextPermissions, @inventoryCurrentPermissions, @invType, @creatorID"
459 + ", @inventoryBasePermissions, @inventoryEveryOnePermissions, @salePrice, @saleType" 495 + ", @inventoryBasePermissions, @inventoryEveryOnePermissions, @salePrice, @saleType"
460 + ", @creationDate, @groupID, @groupOwned, @flags);"; 496 + ", @creationDate, @groupID, @groupOwned, @flags);";
461 497
462 using (AutoClosingSqlCommand command = database.Query(sql)) 498 using (AutoClosingSqlCommand command = database.Query(sql))
463 { 499 {
464 command.Parameters.AddWithValue("inventoryID", item.ID.ToString()); 500 command.Parameters.Add(database.CreateParameter("inventoryID", item.ID));
465 command.Parameters.AddWithValue("assetID", item.AssetID.ToString()); 501 command.Parameters.Add(database.CreateParameter("assetID", item.AssetID));
466 command.Parameters.AddWithValue("assetType", item.AssetType.ToString()); 502 command.Parameters.Add(database.CreateParameter("assetType", item.AssetType));
467 command.Parameters.AddWithValue("parentFolderID", item.Folder.ToString()); 503 command.Parameters.Add(database.CreateParameter("parentFolderID", item.Folder));
468 command.Parameters.AddWithValue("avatarID", item.Owner.ToString()); 504 command.Parameters.Add(database.CreateParameter("avatarID", item.Owner));
469 command.Parameters.AddWithValue("inventoryName", item.Name); 505 command.Parameters.Add(database.CreateParameter("inventoryName", item.Name));
470 command.Parameters.AddWithValue("inventoryDescription", item.Description); 506 command.Parameters.Add(database.CreateParameter("inventoryDescription", item.Description));
471 command.Parameters.AddWithValue("inventoryNextPermissions", ConvertUint32BitFieldToInt32(item.NextPermissions)); 507 command.Parameters.Add(database.CreateParameter("inventoryNextPermissions", item.NextPermissions));
472 command.Parameters.AddWithValue("inventoryCurrentPermissions", ConvertUint32BitFieldToInt32(item.CurrentPermissions)); 508 command.Parameters.Add(database.CreateParameter("inventoryCurrentPermissions", item.CurrentPermissions));
473 command.Parameters.AddWithValue("invType", item.InvType); 509 command.Parameters.Add(database.CreateParameter("invType", item.InvType));
474 command.Parameters.AddWithValue("creatorID", item.Creator.ToString()); 510 command.Parameters.Add(database.CreateParameter("creatorID", item.Creator));
475 command.Parameters.AddWithValue("inventoryBasePermissions", ConvertUint32BitFieldToInt32(item.BasePermissions)); 511 command.Parameters.Add(database.CreateParameter("inventoryBasePermissions", item.BasePermissions));
476 command.Parameters.AddWithValue("inventoryEveryOnePermissions", ConvertUint32BitFieldToInt32(item.EveryOnePermissions)); 512 command.Parameters.Add(database.CreateParameter("inventoryEveryOnePermissions", item.EveryOnePermissions));
477 command.Parameters.AddWithValue("salePrice", item.SalePrice); 513 command.Parameters.Add(database.CreateParameter("salePrice", item.SalePrice));
478 command.Parameters.AddWithValue("saleType", item.SaleType); 514 command.Parameters.Add(database.CreateParameter("saleType", item.SaleType));
479 command.Parameters.AddWithValue("creationDate", item.CreationDate); 515 command.Parameters.Add(database.CreateParameter("creationDate", item.CreationDate));
480 command.Parameters.AddWithValue("groupID", item.GroupID.ToString()); 516 command.Parameters.Add(database.CreateParameter("groupID", item.GroupID));
481 command.Parameters.AddWithValue("groupOwned", item.GroupOwned); 517 command.Parameters.Add(database.CreateParameter("groupOwned", item.GroupOwned));
482 command.Parameters.AddWithValue("flags", ConvertUint32BitFieldToInt32(item.Flags)); 518 command.Parameters.Add(database.CreateParameter("flags", item.Flags));
483 519
484 try 520 try
485 { 521 {
486 command.ExecuteNonQuery(); 522 command.ExecuteNonQuery();
487 } 523 }
488 catch (SqlException e) 524 catch (Exception e)
489 { 525 {
490 m_log.Error(e.ToString()); 526 m_log.Error("[INVENTORY DB] Error inserting item :" + e.Message);
491 } 527 }
492 } 528 }
493 529
@@ -520,26 +556,26 @@ namespace OpenSim.Data.MSSQL
520 "flags = @flags where " + 556 "flags = @flags where " +
521 "inventoryID = @keyInventoryID;")) 557 "inventoryID = @keyInventoryID;"))
522 { 558 {
523 command.Parameters.AddWithValue("inventoryID", item.ID.ToString()); 559 command.Parameters.Add(database.CreateParameter("inventoryID", item.ID));
524 command.Parameters.AddWithValue("assetID", item.AssetID.ToString()); 560 command.Parameters.Add(database.CreateParameter("assetID", item.AssetID));
525 command.Parameters.AddWithValue("assetType", item.AssetType.ToString()); 561 command.Parameters.Add(database.CreateParameter("assetType", item.AssetType));
526 command.Parameters.AddWithValue("parentFolderID", item.Folder.ToString()); 562 command.Parameters.Add(database.CreateParameter("parentFolderID", item.Folder));
527 command.Parameters.AddWithValue("avatarID", item.Owner.ToString()); 563 command.Parameters.Add(database.CreateParameter("avatarID", item.Owner));
528 command.Parameters.AddWithValue("inventoryName", item.Name); 564 command.Parameters.Add(database.CreateParameter("inventoryName", item.Name));
529 command.Parameters.AddWithValue("inventoryDescription", item.Description); 565 command.Parameters.Add(database.CreateParameter("inventoryDescription", item.Description));
530 command.Parameters.AddWithValue("inventoryNextPermissions", ConvertUint32BitFieldToInt32(item.NextPermissions)); 566 command.Parameters.Add(database.CreateParameter("inventoryNextPermissions", item.NextPermissions));
531 command.Parameters.AddWithValue("inventoryCurrentPermissions", ConvertUint32BitFieldToInt32(item.CurrentPermissions)); 567 command.Parameters.Add(database.CreateParameter("inventoryCurrentPermissions", item.CurrentPermissions));
532 command.Parameters.AddWithValue("invType", item.InvType); 568 command.Parameters.Add(database.CreateParameter("invType", item.InvType));
533 command.Parameters.AddWithValue("creatorID", item.Creator.ToString()); 569 command.Parameters.Add(database.CreateParameter("creatorID", item.Creator));
534 command.Parameters.AddWithValue("inventoryBasePermissions", ConvertUint32BitFieldToInt32(item.BasePermissions)); 570 command.Parameters.Add(database.CreateParameter("inventoryBasePermissions", item.BasePermissions));
535 command.Parameters.AddWithValue("inventoryEveryOnePermissions", ConvertUint32BitFieldToInt32(item.EveryOnePermissions)); 571 command.Parameters.Add(database.CreateParameter("inventoryEveryOnePermissions", item.EveryOnePermissions));
536 command.Parameters.AddWithValue("salePrice", item.SalePrice); 572 command.Parameters.Add(database.CreateParameter("salePrice", item.SalePrice));
537 command.Parameters.AddWithValue("saleType", item.SaleType); 573 command.Parameters.Add(database.CreateParameter("saleType", item.SaleType));
538 command.Parameters.AddWithValue("creationDate", item.CreationDate); 574 command.Parameters.Add(database.CreateParameter("creationDate", item.CreationDate));
539 command.Parameters.AddWithValue("groupID", item.GroupID.ToString()); 575 command.Parameters.Add(database.CreateParameter("groupID", item.GroupID));
540 command.Parameters.AddWithValue("groupOwned", item.GroupOwned); 576 command.Parameters.Add(database.CreateParameter("groupOwned", item.GroupOwned));
541 command.Parameters.AddWithValue("flags", ConvertUint32BitFieldToInt32(item.Flags)); 577 command.Parameters.Add(database.CreateParameter("flags", item.Flags));
542 command.Parameters.AddWithValue("@keyInventoryID", item.ID.ToString()); 578 command.Parameters.Add(database.CreateParameter("@keyInventoryID", item.ID));
543 579
544 try 580 try
545 { 581 {
@@ -547,225 +583,221 @@ namespace OpenSim.Data.MSSQL
547 } 583 }
548 catch (Exception e) 584 catch (Exception e)
549 { 585 {
550 m_log.Error(e.ToString()); 586 m_log.Error("[INVENTORY DB] Error updating item :" + e.Message);
551 } 587 }
552 } 588 }
553 } 589 }
554 590
591 // See IInventoryDataPlugin
592
555 /// <summary> 593 /// <summary>
556 /// Delete an item in inventory database 594 /// Delete an item in inventory database
557 /// </summary> 595 /// </summary>
558 /// <param name="item">the item UUID</param> 596 /// <param name="itemID">the item UUID</param>
559 public void deleteInventoryItem(UUID itemID) 597 public void deleteInventoryItem(UUID itemID)
560 { 598 {
561 try 599 using (AutoClosingSqlCommand command = database.Query("DELETE FROM inventoryitems WHERE inventoryID=@inventoryID"))
562 { 600 {
563 Dictionary<string, string> param = new Dictionary<string, string>(); 601 command.Parameters.Add(database.CreateParameter("inventoryID", itemID));
564 param["uuid"] = itemID.ToString(); 602 try
603 {
565 604
566 using (IDbCommand cmd = database.Query("DELETE FROM inventoryitems WHERE inventoryID=@uuid", param)) 605 command.ExecuteNonQuery();
606 }
607 catch (Exception e)
567 { 608 {
568 cmd.ExecuteNonQuery(); 609 m_log.Error("[INVENTORY DB] Error deleting item :" + e.Message);
569 } 610 }
570 } 611 }
571 catch (SqlException e)
572 {
573 m_log.Error(e.ToString());
574 }
575 } 612 }
576 613
614 #endregion
615
616 #region Private methods
617
577 /// <summary> 618 /// <summary>
578 /// Creates a new inventory folder 619 /// Delete an item in inventory database
579 /// </summary> 620 /// </summary>
580 /// <param name="folder">Folder to create</param> 621 /// <param name="folderID">the item ID</param>
581 public void addInventoryFolder(InventoryFolderBase folder) 622 /// <param name="connection">connection to the database</param>
623 private void DeleteItemsInFolder(UUID folderID, SqlConnection connection)
582 { 624 {
583 string sql = 625 using (SqlCommand command = new SqlCommand("DELETE FROM inventoryitems WHERE folderID=@folderID", connection))
584 "INSERT INTO inventoryfolders ([folderID], [agentID], [parentFolderID], [folderName], [type], [version]) VALUES ";
585 sql += "(@folderID, @agentID, @parentFolderID, @folderName, @type, @version);";
586
587
588 using (AutoClosingSqlCommand command = database.Query(sql))
589 { 626 {
590 command.Parameters.AddWithValue("folderID", folder.ID.ToString()); 627 command.Parameters.Add(database.CreateParameter("folderID", folderID));
591 command.Parameters.AddWithValue("agentID", folder.Owner.ToString());
592 command.Parameters.AddWithValue("parentFolderID", folder.ParentID.ToString());
593 command.Parameters.AddWithValue("folderName", folder.Name);
594 command.Parameters.AddWithValue("type", folder.Type);
595 command.Parameters.AddWithValue("version", Convert.ToInt32(folder.Version));
596 628
597 try 629 try
598 { 630 {
599 //IDbCommand result = database.Query(sql, param);
600 command.ExecuteNonQuery(); 631 command.ExecuteNonQuery();
601 } 632 }
602 catch (Exception e) 633 catch (Exception e)
603 { 634 {
604 m_log.Error(e.ToString()); 635 m_log.Error("[INVENTORY DB] Error deleting item :" + e.Message);
605 } 636 }
606 } 637 }
607 } 638 }
608 639
609 /// <summary> 640 /// <summary>
610 /// Updates an inventory folder 641 /// Gets the folder hierarchy in a loop.
611 /// </summary> 642 /// </summary>
612 /// <param name="folder">Folder to update</param> 643 /// <param name="parentID">parent ID.</param>
613 public void updateInventoryFolder(InventoryFolderBase folder) 644 /// <param name="command">SQL command/connection to database</param>
645 /// <returns></returns>
646 private static List<InventoryFolderBase> getFolderHierarchy(UUID parentID, AutoClosingSqlCommand command)
614 { 647 {
615 using (IDbCommand command = database.Query("UPDATE inventoryfolders set folderID = @folderID, " + 648 command.Parameters["@parentID"].Value = parentID.ToString();
616 "agentID = @agentID, " + 649
617 "parentFolderID = @parentFolderID," + 650 List<InventoryFolderBase> folders = getInventoryFolders(command);
618 "folderName = @folderName," + 651
619 "type = @type," + 652 if (folders.Count > 0)
620 "version = @version where " +
621 "folderID = @keyFolderID;"))
622 { 653 {
623 SqlParameter param1 = new SqlParameter("@folderID", folder.ID.ToString()); 654 List<InventoryFolderBase> tempFolders = new List<InventoryFolderBase>();
624 SqlParameter param2 = new SqlParameter("@agentID", folder.Owner.ToString());
625 SqlParameter param3 = new SqlParameter("@parentFolderID", folder.ParentID.ToString());
626 SqlParameter param4 = new SqlParameter("@folderName", folder.Name);
627 SqlParameter param5 = new SqlParameter("@type", folder.Type);
628 SqlParameter param6 = new SqlParameter("@version", Convert.ToInt32(folder.Version));
629 SqlParameter param7 = new SqlParameter("@keyFolderID", folder.ID.ToString());
630 command.Parameters.Add(param1);
631 command.Parameters.Add(param2);
632 command.Parameters.Add(param3);
633 command.Parameters.Add(param4);
634 command.Parameters.Add(param5);
635 command.Parameters.Add(param6);
636 command.Parameters.Add(param7);
637 655
638 try 656 foreach (InventoryFolderBase folderBase in folders)
639 { 657 {
640 command.ExecuteNonQuery(); 658 tempFolders.AddRange(getFolderHierarchy(folderBase.ID, command));
641 } 659 }
642 catch (Exception e) 660
661 if (tempFolders.Count > 0)
643 { 662 {
644 m_log.Error(e.ToString()); 663 folders.AddRange(tempFolders);
645 } 664 }
646 } 665 }
666 return folders;
647 } 667 }
648 668
649 /// <summary> 669 /// <summary>
650 /// Updates an inventory folder 670 /// Gets the inventory folders.
651 /// </summary> 671 /// </summary>
652 /// <param name="folder">Folder to update</param> 672 /// <param name="parentID">parentID, use UUID.Zero to get root</param>
653 public void moveInventoryFolder(InventoryFolderBase folder) 673 /// <param name="user">user id, use UUID.Zero, if you want all folders from a parentID.</param>
674 /// <returns></returns>
675 private List<InventoryFolderBase> getInventoryFolders(UUID parentID, UUID user)
654 { 676 {
655 using (IDbCommand command = database.Query("UPDATE inventoryfolders set folderID = @folderID, " + 677 using (AutoClosingSqlCommand command = database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = @parentID AND agentID LIKE @uuid"))
656 "parentFolderID = @parentFolderID," +
657 "folderID = @keyFolderID;"))
658 { 678 {
659 SqlParameter param1 = new SqlParameter("@folderID", folder.ID.ToString()); 679 if (user == UUID.Zero)
660 SqlParameter param2 = new SqlParameter("@parentFolderID", folder.ParentID.ToString());
661 SqlParameter param3 = new SqlParameter("@keyFolderID", folder.ID.ToString());
662 command.Parameters.Add(param1);
663 command.Parameters.Add(param2);
664 command.Parameters.Add(param3);
665
666 try
667 { 680 {
668 command.ExecuteNonQuery(); 681 command.Parameters.Add(database.CreateParameter("uuid", "%"));
669 } 682 }
670 catch (Exception e) 683 else
671 { 684 {
672 m_log.Error(e.ToString()); 685 command.Parameters.Add(database.CreateParameter("uuid", user));
673 } 686 }
687 command.Parameters.Add(database.CreateParameter("parentID", parentID));
688
689 return getInventoryFolders(command);
674 } 690 }
675 } 691 }
676 692
677 /// <summary> 693 /// <summary>
678 /// Append a list of all the child folders of a parent folder 694 /// Gets the inventory folders.
679 /// </summary> 695 /// </summary>
680 /// <param name="folders">list where folders will be appended</param> 696 /// <param name="command">SQLcommand.</param>
681 /// <param name="parentID">ID of parent</param> 697 /// <returns></returns>
682 protected void getInventoryFolders(ref List<InventoryFolderBase> folders, UUID parentID) 698 private static List<InventoryFolderBase> getInventoryFolders(AutoClosingSqlCommand command)
683 {
684 List<InventoryFolderBase> subfolderList = getInventoryFolders(parentID);
685
686 foreach (InventoryFolderBase f in subfolderList)
687 folders.Add(f);
688 }
689
690 // See IInventoryDataPlugin
691 public List<InventoryFolderBase> getFolderHierarchy(UUID parentID)
692 { 699 {
693 List<InventoryFolderBase> folders = new List<InventoryFolderBase>(); 700 using (IDataReader reader = command.ExecuteReader())
694 getInventoryFolders(ref folders, parentID); 701 {
695
696 for (int i = 0; i < folders.Count; i++)
697 getInventoryFolders(ref folders, folders[i].ID);
698 702
699 return folders; 703 List<InventoryFolderBase> items = new List<InventoryFolderBase>();
704 while (reader.Read())
705 {
706 items.Add(readInventoryFolder(reader));
707 }
708 return items;
709 }
700 } 710 }
701 711
702 /// <summary> 712 /// <summary>
703 /// Delete a folder in inventory databasae 713 /// Reads a list of inventory folders returned by a query.
704 /// </summary> 714 /// </summary>
705 /// <param name="folderID">the folder UUID</param> 715 /// <param name="reader">A MSSQL Data Reader</param>
706 protected void deleteOneFolder(UUID folderID) 716 /// <returns>A List containing inventory folders</returns>
717 protected static InventoryFolderBase readInventoryFolder(IDataReader reader)
707 { 718 {
708 try 719 try
709 { 720 {
710 Dictionary<string, string> param = new Dictionary<string, string>(); 721 InventoryFolderBase folder = new InventoryFolderBase();
711 param["folderID"] = folderID.ToString(); 722 folder.Owner = new UUID((string)reader["agentID"]);
723 folder.ParentID = new UUID((string)reader["parentFolderID"]);
724 folder.ID = new UUID((string)reader["folderID"]);
725 folder.Name = (string)reader["folderName"];
726 folder.Type = (short)reader["type"];
727 folder.Version = Convert.ToUInt16(reader["version"]);
712 728
713 using (IDbCommand cmd = database.Query("DELETE FROM inventoryfolders WHERE folderID=@folderID", param)) 729 return folder;
714 {
715 cmd.ExecuteNonQuery();
716 }
717 } 730 }
718 catch (SqlException e) 731 catch (Exception e)
719 { 732 {
720 m_log.Error(e.ToString()); 733 m_log.Error("[INVENTORY DB] Error reading inventory folder :" + e.Message);
721 } 734 }
735
736 return null;
722 } 737 }
723 738
724 /// <summary> 739 /// <summary>
725 /// Delete an item in inventory database 740 /// Reads a one item from an SQL result
726 /// </summary> 741 /// </summary>
727 /// <param name="folderID">the item ID</param> 742 /// <param name="reader">The SQL Result</param>
728 protected void deleteItemsInFolder(UUID folderID) 743 /// <returns>the item read</returns>
744 private static InventoryItemBase readInventoryItem(IDataRecord reader)
729 { 745 {
730 try 746 try
731 { 747 {
732 Dictionary<string, string> param = new Dictionary<string, string>(); 748 InventoryItemBase item = new InventoryItemBase();
733 param["parentFolderID"] = folderID.ToString();
734 749
750 item.ID = new UUID(reader["inventoryID"].ToString());
751 item.AssetID = new UUID(reader["assetID"].ToString());
752 item.AssetType = Convert.ToInt32(reader["assetType"].ToString());
753 item.Folder = new UUID(reader["parentFolderID"].ToString());
754 item.Owner = new UUID(reader["avatarID"].ToString());
755 item.Name = reader["inventoryName"].ToString();
756 item.Description = reader["inventoryDescription"].ToString();
757 item.NextPermissions = Convert.ToUInt32(reader["inventoryNextPermissions"]);
758 item.CurrentPermissions = Convert.ToUInt32(reader["inventoryCurrentPermissions"]);
759 item.InvType = Convert.ToInt32(reader["invType"].ToString());
760 item.Creator = new UUID(reader["creatorID"].ToString());
761 item.BasePermissions = Convert.ToUInt32(reader["inventoryBasePermissions"]);
762 item.EveryOnePermissions = Convert.ToUInt32(reader["inventoryEveryOnePermissions"]);
763 item.SalePrice = Convert.ToInt32(reader["salePrice"]);
764 item.SaleType = Convert.ToByte(reader["saleType"]);
765 item.CreationDate = Convert.ToInt32(reader["creationDate"]);
766 item.GroupID = new UUID(reader["groupID"].ToString());
767 item.GroupOwned = Convert.ToBoolean(reader["groupOwned"]);
768 item.Flags = Convert.ToUInt32(reader["flags"]);
735 769
736 using (IDbCommand cmd = 770 return item;
737 database.Query("DELETE FROM inventoryitems WHERE parentFolderID=@parentFolderID", param))
738 {
739 cmd.ExecuteNonQuery();
740 }
741 } 771 }
742 catch (SqlException e) 772 catch (SqlException e)
743 { 773 {
744 m_log.Error(e.ToString()); 774 m_log.Error("[INVENTORY DB] Error reading inventory item :" + e.Message);
745 } 775 }
776
777 return null;
746 } 778 }
747 779
748 /// <summary> 780 /// <summary>
749 /// Delete an inventory folder 781 /// Delete a folder in inventory databasae
750 /// </summary> 782 /// </summary>
751 /// <param name="folderId">Id of folder to delete</param> 783 /// <param name="folderID">the folder UUID</param>
752 public void deleteInventoryFolder(UUID folderID) 784 /// <param name="connection">connection to database</param>
785 private void DeleteOneFolder(UUID folderID, SqlConnection connection)
753 { 786 {
754 // lock (database) 787 try
755 { 788 {
756 List<InventoryFolderBase> subFolders = getFolderHierarchy(folderID); 789 using (SqlCommand command = new SqlCommand("DELETE FROM inventoryfolders WHERE folderID=@folderID", connection))
757
758 //Delete all sub-folders
759 foreach (InventoryFolderBase f in subFolders)
760 { 790 {
761 deleteOneFolder(f.ID); 791 command.Parameters.Add(database.CreateParameter("folderID", folderID));
762 deleteItemsInFolder(f.ID);
763 }
764 792
765 //Delete the actual row 793 command.ExecuteNonQuery();
766 deleteOneFolder(folderID); 794 }
767 deleteItemsInFolder(folderID); 795 }
796 catch (SqlException e)
797 {
798 m_log.Error("[INVENTORY DB] Error deleting folder :" + e.Message);
768 } 799 }
769 } 800 }
801 #endregion
770 } 802 }
771} 803}