aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authormingchen2008-06-06 00:56:51 +0000
committermingchen2008-06-06 00:56:51 +0000
commitde0bd2b5a0bcd2bd3aeb2e30b515c7e36b849252 (patch)
tree166b86d5bedeb8caca136f58eb51cb58b60a689c
parentUpdate svn properties. (diff)
downloadopensim-SC-de0bd2b5a0bcd2bd3aeb2e30b515c7e36b849252.zip
opensim-SC-de0bd2b5a0bcd2bd3aeb2e30b515c7e36b849252.tar.gz
opensim-SC-de0bd2b5a0bcd2bd3aeb2e30b515c7e36b849252.tar.bz2
opensim-SC-de0bd2b5a0bcd2bd3aeb2e30b515c7e36b849252.tar.xz
MSSQL Inventory Fix. Patch by Kyle and Chris from G2
-rw-r--r--OpenSim/Data/MSSQL/MSSQLInventoryData.cs171
1 files changed, 89 insertions, 82 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLInventoryData.cs b/OpenSim/Data/MSSQL/MSSQLInventoryData.cs
index 128fb8f..b92eeab 100644
--- a/OpenSim/Data/MSSQL/MSSQLInventoryData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLInventoryData.cs
@@ -43,6 +43,17 @@ namespace OpenSim.Data.MSSQL
43 { 43 {
44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45 45
46 #region Helper converters to preserve unsigned bitfield-type data in DB roundtrips via signed int32s
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
46 /// <summary> 57 /// <summary>
47 /// The database manager 58 /// The database manager
48 /// </summary> 59 /// </summary>
@@ -306,18 +317,18 @@ namespace OpenSim.Data.MSSQL
306 item.Owner = new LLUUID((string) reader["avatarID"]); 317 item.Owner = new LLUUID((string) reader["avatarID"]);
307 item.Name = (string) reader["inventoryName"]; 318 item.Name = (string) reader["inventoryName"];
308 item.Description = (string) reader["inventoryDescription"]; 319 item.Description = (string) reader["inventoryDescription"];
309 item.NextPermissions = Convert.ToUInt32(reader["inventoryNextPermissions"]); 320 item.NextPermissions = ConvertInt32BitFieldToUint32((int)reader["inventoryNextPermissions"]);
310 item.CurrentPermissions = Convert.ToUInt32(reader["inventoryCurrentPermissions"]); 321 item.CurrentPermissions = ConvertInt32BitFieldToUint32((int)reader["inventoryCurrentPermissions"]);
311 item.InvType = (int) reader["invType"]; 322 item.InvType = (int) reader["invType"];
312 item.Creator = new LLUUID((string) reader["creatorID"]); 323 item.Creator = new LLUUID((string) reader["creatorID"]);
313 item.BasePermissions = Convert.ToUInt32(reader["inventoryBasePermissions"]); 324 item.BasePermissions = ConvertInt32BitFieldToUint32((int)reader["inventoryBasePermissions"]);
314 item.EveryOnePermissions = Convert.ToUInt32(reader["inventoryEveryOnePermissions"]); 325 item.EveryOnePermissions = ConvertInt32BitFieldToUint32((int)reader["inventoryEveryOnePermissions"]);
315 item.SalePrice = (int) reader["salePrice"]; 326 item.SalePrice = (int) reader["salePrice"];
316 item.SaleType = Convert.ToByte(reader["saleType"]); 327 item.SaleType = Convert.ToByte(reader["saleType"]);
317 item.CreationDate = (int) reader["creationDate"]; 328 item.CreationDate = (int) reader["creationDate"];
318 item.GroupID = new LLUUID(reader["groupID"].ToString()); 329 item.GroupID = new LLUUID(reader["groupID"].ToString());
319 item.GroupOwned = Convert.ToBoolean(reader["groupOwned"]); 330 item.GroupOwned = Convert.ToBoolean(reader["groupOwned"]);
320 item.Flags = Convert.ToUInt32(reader["flags"]); 331 item.Flags = ConvertInt32BitFieldToUint32((int)reader["flags"]);
321 332
322 return item; 333 return item;
323 } 334 }
@@ -368,7 +379,7 @@ namespace OpenSim.Data.MSSQL
368 /// <summary> 379 /// <summary>
369 /// Reads a list of inventory folders returned by a query. 380 /// Reads a list of inventory folders returned by a query.
370 /// </summary> 381 /// </summary>
371 /// <param name="reader">A MySQL Data Reader</param> 382 /// <param name="reader">A MSSQL Data Reader</param>
372 /// <returns>A List containing inventory folders</returns> 383 /// <returns>A List containing inventory folders</returns>
373 protected static InventoryFolderBase readInventoryFolder(IDataReader reader) 384 protected static InventoryFolderBase readInventoryFolder(IDataReader reader)
374 { 385 {
@@ -380,7 +391,7 @@ namespace OpenSim.Data.MSSQL
380 folder.ID = new LLUUID((string) reader["folderID"]); 391 folder.ID = new LLUUID((string) reader["folderID"]);
381 folder.Name = (string) reader["folderName"]; 392 folder.Name = (string) reader["folderName"];
382 folder.Type = (short) reader["type"]; 393 folder.Type = (short) reader["type"];
383 folder.Version = (ushort) ((int) reader["version"]); 394 folder.Version = Convert.ToUInt16(reader["version"]);
384 return folder; 395 return folder;
385 } 396 }
386 catch (Exception e) 397 catch (Exception e)
@@ -450,31 +461,29 @@ namespace OpenSim.Data.MSSQL
450 461
451 try 462 try
452 { 463 {
453 Dictionary<string, string> param = new Dictionary<string, string>(); 464 SqlCommand command = new SqlCommand(sql, database.getConnection());
454 param["inventoryID"] = item.ID.ToString(); 465 command.Parameters.AddWithValue("inventoryID", item.ID.ToString());
455 param["assetID"] = item.AssetID.ToString(); 466 command.Parameters.AddWithValue("assetID", item.AssetID.ToString());
456 param["assetType"] = item.AssetType.ToString(); 467 command.Parameters.AddWithValue("assetType", item.AssetType.ToString());
457 param["parentFolderID"] = item.Folder.ToString(); 468 command.Parameters.AddWithValue("parentFolderID", item.Folder.ToString());
458 param["avatarID"] = item.Owner.ToString(); 469 command.Parameters.AddWithValue("avatarID", item.Owner.ToString());
459 param["inventoryName"] = item.Name; 470 command.Parameters.AddWithValue("inventoryName", item.Name);
460 param["inventoryDescription"] = item.Description; 471 command.Parameters.AddWithValue("inventoryDescription", item.Description);
461 param["inventoryNextPermissions"] = item.NextPermissions.ToString(); 472 command.Parameters.AddWithValue("inventoryNextPermissions", ConvertUint32BitFieldToInt32(item.NextPermissions));
462 param["inventoryCurrentPermissions"] = item.CurrentPermissions.ToString(); 473 command.Parameters.AddWithValue("inventoryCurrentPermissions", ConvertUint32BitFieldToInt32(item.CurrentPermissions));
463 param["invType"] = Convert.ToString(item.InvType); 474 command.Parameters.AddWithValue("invType", item.InvType);
464 param["creatorID"] = item.Creator.ToString(); 475 command.Parameters.AddWithValue("creatorID", item.Creator.ToString());
465 param["inventoryBasePermissions"] = Convert.ToString(item.BasePermissions); 476 command.Parameters.AddWithValue("inventoryBasePermissions", ConvertUint32BitFieldToInt32(item.BasePermissions));
466 param["inventoryEveryOnePermissions"] = Convert.ToString(item.EveryOnePermissions); 477 command.Parameters.AddWithValue("inventoryEveryOnePermissions", ConvertUint32BitFieldToInt32(item.EveryOnePermissions));
467 478 command.Parameters.AddWithValue("salePrice", item.SalePrice);
468 param["salePrice"] = Convert.ToString(item.SalePrice); 479 command.Parameters.AddWithValue("saleType", item.SaleType);
469 param["saleType"] = Convert.ToString(item.SaleType); 480 command.Parameters.AddWithValue("creationDate", item.CreationDate);
470 param["creationDate"] = Convert.ToString(item.CreationDate); 481 command.Parameters.AddWithValue("groupID", item.GroupID.ToString());
471 param["groupID"] = item.GroupID.ToString(); 482 command.Parameters.AddWithValue("groupOwned", item.GroupOwned);
472 param["groupOwned"] = Convert.ToString(item.GroupOwned); 483 command.Parameters.AddWithValue("flags", ConvertUint32BitFieldToInt32(item.Flags));
473 param["flags"] = Convert.ToString(item.Flags); 484
474 485 command.ExecuteNonQuery();
475 IDbCommand result = database.Query(sql, param); 486 command.Dispose();
476 result.ExecuteNonQuery();
477 result.Dispose();
478 } 487 }
479 catch (SqlException e) 488 catch (SqlException e)
480 { 489 {
@@ -490,46 +499,44 @@ namespace OpenSim.Data.MSSQL
490 { 499 {
491 SqlCommand command = new SqlCommand("UPDATE inventoryitems set inventoryID = @inventoryID, " + 500 SqlCommand command = new SqlCommand("UPDATE inventoryitems set inventoryID = @inventoryID, " +
492 "assetID = @assetID, " + 501 "assetID = @assetID, " +
493 "assetType = @assetType" + 502 "assetType = @assetType," +
494 "parentFolderID = @parentFolderID" + 503 "parentFolderID = @parentFolderID," +
495 "avatarID = @avatarID" + 504 "avatarID = @avatarID," +
496 "inventoryName = @inventoryName" + 505 "inventoryName = @inventoryName," +
497 "inventoryDescription = @inventoryDescription" + 506 "inventoryDescription = @inventoryDescription," +
498 "inventoryNextPermissions = @inventoryNextPermissions" + 507 "inventoryNextPermissions = @inventoryNextPermissions," +
499 "inventoryCurrentPermissions = @inventoryCurrentPermissions" + 508 "inventoryCurrentPermissions = @inventoryCurrentPermissions," +
500 "invType = @invType" + 509 "invType = @invType," +
501 "creatorID = @creatorID" + 510 "creatorID = @creatorID," +
502 "inventoryBasePermissions = @inventoryBasePermissions" + 511 "inventoryBasePermissions = @inventoryBasePermissions," +
503 "inventoryEveryOnePermissions = @inventoryEveryOnePermissions) where " + 512 "inventoryEveryOnePermissions = @inventoryEveryOnePermissions," +
513 "salePrice = @salePrice," +
514 "saleType = @saleType," +
515 "creationDate = @creationDate," +
516 "groupID = @groupID," +
517 "groupOwned = @groupOwned," +
518 "flags = @flags where " +
504 "inventoryID = @keyInventoryID;", database.getConnection()); 519 "inventoryID = @keyInventoryID;", database.getConnection());
505 SqlParameter param1 = new SqlParameter("@inventoryID", item.ID.ToString()); 520 command.Parameters.AddWithValue("inventoryID", item.ID.ToString());
506 SqlParameter param2 = new SqlParameter("@assetID", item.AssetID); 521 command.Parameters.AddWithValue("assetID", item.AssetID.ToString());
507 SqlParameter param3 = new SqlParameter("@assetType", item.AssetType); 522 command.Parameters.AddWithValue("assetType", item.AssetType.ToString());
508 SqlParameter param4 = new SqlParameter("@parentFolderID", item.Folder); 523 command.Parameters.AddWithValue("parentFolderID", item.Folder.ToString());
509 SqlParameter param5 = new SqlParameter("@avatarID", item.Owner); 524 command.Parameters.AddWithValue("avatarID", item.Owner.ToString());
510 SqlParameter param6 = new SqlParameter("@inventoryName", item.Name); 525 command.Parameters.AddWithValue("inventoryName", item.Name);
511 SqlParameter param7 = new SqlParameter("@inventoryDescription", item.Description); 526 command.Parameters.AddWithValue("inventoryDescription", item.Description);
512 SqlParameter param8 = new SqlParameter("@inventoryNextPermissions", item.NextPermissions); 527 command.Parameters.AddWithValue("inventoryNextPermissions", ConvertUint32BitFieldToInt32(item.NextPermissions));
513 SqlParameter param9 = new SqlParameter("@inventoryCurrentPermissions", item.CurrentPermissions); 528 command.Parameters.AddWithValue("inventoryCurrentPermissions", ConvertUint32BitFieldToInt32(item.CurrentPermissions));
514 SqlParameter param10 = new SqlParameter("@invType", item.InvType); 529 command.Parameters.AddWithValue("invType", item.InvType);
515 SqlParameter param11 = new SqlParameter("@creatorID", item.Creator); 530 command.Parameters.AddWithValue("creatorID", item.Creator.ToString());
516 SqlParameter param12 = new SqlParameter("@inventoryBasePermissions", item.BasePermissions); 531 command.Parameters.AddWithValue("inventoryBasePermissions", ConvertUint32BitFieldToInt32(item.BasePermissions));
517 SqlParameter param13 = new SqlParameter("@inventoryEveryOnePermissions", item.EveryOnePermissions); 532 command.Parameters.AddWithValue("inventoryEveryOnePermissions", ConvertUint32BitFieldToInt32(item.EveryOnePermissions));
518 SqlParameter param14 = new SqlParameter("@keyInventoryID", item.ID.ToString()); 533 command.Parameters.AddWithValue("salePrice", item.SalePrice);
519 command.Parameters.Add(param1); 534 command.Parameters.AddWithValue("saleType", item.SaleType);
520 command.Parameters.Add(param2); 535 command.Parameters.AddWithValue("creationDate", item.CreationDate);
521 command.Parameters.Add(param3); 536 command.Parameters.AddWithValue("groupID", item.GroupID.ToString());
522 command.Parameters.Add(param4); 537 command.Parameters.AddWithValue("groupOwned", item.GroupOwned);
523 command.Parameters.Add(param5); 538 command.Parameters.AddWithValue("flags", ConvertUint32BitFieldToInt32(item.Flags));
524 command.Parameters.Add(param6); 539 command.Parameters.AddWithValue("@keyInventoryID", item.ID.ToString());
525 command.Parameters.Add(param7);
526 command.Parameters.Add(param8);
527 command.Parameters.Add(param9);
528 command.Parameters.Add(param10);
529 command.Parameters.Add(param11);
530 command.Parameters.Add(param12);
531 command.Parameters.Add(param13);
532 command.Parameters.Add(param14);
533 540
534 try 541 try
535 { 542 {
@@ -574,19 +581,19 @@ namespace OpenSim.Data.MSSQL
574 sql += "(@folderID, @agentID, @parentFolderID, @folderName, @type, @version);"; 581 sql += "(@folderID, @agentID, @parentFolderID, @folderName, @type, @version);";
575 582
576 583
577 Dictionary<string, string> param = new Dictionary<string, string>(); 584 SqlCommand command = new SqlCommand(sql, database.getConnection());
578 param["folderID"] = folder.ID.ToString(); 585 command.Parameters.AddWithValue("folderID", folder.ID.ToString());
579 param["agentID"] = folder.Owner.ToString(); 586 command.Parameters.AddWithValue("agentID", folder.Owner.ToString());
580 param["parentFolderID"] = folder.ParentID.ToString(); 587 command.Parameters.AddWithValue("parentFolderID", folder.ParentID.ToString());
581 param["folderName"] = folder.Name; 588 command.Parameters.AddWithValue("folderName", folder.Name);
582 param["type"] = Convert.ToString(folder.Type); 589 command.Parameters.AddWithValue("type", folder.Type);
583 param["version"] = Convert.ToString(folder.Version); 590 command.Parameters.AddWithValue("version", Convert.ToInt32(folder.Version));
584 591
585 try 592 try
586 { 593 {
587 IDbCommand result = database.Query(sql, param); 594 //IDbCommand result = database.Query(sql, param);
588 result.ExecuteNonQuery(); 595 command.ExecuteNonQuery();
589 result.Dispose(); 596 command.Dispose();
590 } 597 }
591 catch (Exception e) 598 catch (Exception e)
592 { 599 {
@@ -612,7 +619,7 @@ namespace OpenSim.Data.MSSQL
612 SqlParameter param3 = new SqlParameter("@parentFolderID", folder.ParentID.ToString()); 619 SqlParameter param3 = new SqlParameter("@parentFolderID", folder.ParentID.ToString());
613 SqlParameter param4 = new SqlParameter("@folderName", folder.Name); 620 SqlParameter param4 = new SqlParameter("@folderName", folder.Name);
614 SqlParameter param5 = new SqlParameter("@type", folder.Type); 621 SqlParameter param5 = new SqlParameter("@type", folder.Type);
615 SqlParameter param6 = new SqlParameter("@version", folder.Version); 622 SqlParameter param6 = new SqlParameter("@version", Convert.ToInt32(folder.Version));
616 SqlParameter param7 = new SqlParameter("@keyFolderID", folder.ID.ToString()); 623 SqlParameter param7 = new SqlParameter("@keyFolderID", folder.ID.ToString());
617 command.Parameters.Add(param1); 624 command.Parameters.Add(param1);
618 command.Parameters.Add(param2); 625 command.Parameters.Add(param2);