MSSQL Inventory Fix. Patch by Kyle and Chris from G2

0.6.0-stable
mingchen 2008-06-06 00:56:51 +00:00
parent 2818dd800e
commit de0bd2b5a0
1 changed files with 88 additions and 81 deletions

View File

@ -43,6 +43,17 @@ namespace OpenSim.Data.MSSQL
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
#region Helper converters to preserve unsigned bitfield-type data in DB roundtrips via signed int32s
private static int ConvertUint32BitFieldToInt32(uint bitField)
{
return BitConverter.ToInt32(BitConverter.GetBytes(bitField), 0);
}
private static uint ConvertInt32BitFieldToUint32(int bitField)
{
return BitConverter.ToUInt32(BitConverter.GetBytes(bitField), 0);
}
#endregion
/// <summary> /// <summary>
/// The database manager /// The database manager
/// </summary> /// </summary>
@ -306,18 +317,18 @@ namespace OpenSim.Data.MSSQL
item.Owner = new LLUUID((string) reader["avatarID"]); item.Owner = new LLUUID((string) reader["avatarID"]);
item.Name = (string) reader["inventoryName"]; item.Name = (string) reader["inventoryName"];
item.Description = (string) reader["inventoryDescription"]; item.Description = (string) reader["inventoryDescription"];
item.NextPermissions = Convert.ToUInt32(reader["inventoryNextPermissions"]); item.NextPermissions = ConvertInt32BitFieldToUint32((int)reader["inventoryNextPermissions"]);
item.CurrentPermissions = Convert.ToUInt32(reader["inventoryCurrentPermissions"]); item.CurrentPermissions = ConvertInt32BitFieldToUint32((int)reader["inventoryCurrentPermissions"]);
item.InvType = (int) reader["invType"]; item.InvType = (int) reader["invType"];
item.Creator = new LLUUID((string) reader["creatorID"]); item.Creator = new LLUUID((string) reader["creatorID"]);
item.BasePermissions = Convert.ToUInt32(reader["inventoryBasePermissions"]); item.BasePermissions = ConvertInt32BitFieldToUint32((int)reader["inventoryBasePermissions"]);
item.EveryOnePermissions = Convert.ToUInt32(reader["inventoryEveryOnePermissions"]); item.EveryOnePermissions = ConvertInt32BitFieldToUint32((int)reader["inventoryEveryOnePermissions"]);
item.SalePrice = (int) reader["salePrice"]; item.SalePrice = (int) reader["salePrice"];
item.SaleType = Convert.ToByte(reader["saleType"]); item.SaleType = Convert.ToByte(reader["saleType"]);
item.CreationDate = (int) reader["creationDate"]; item.CreationDate = (int) reader["creationDate"];
item.GroupID = new LLUUID(reader["groupID"].ToString()); item.GroupID = new LLUUID(reader["groupID"].ToString());
item.GroupOwned = Convert.ToBoolean(reader["groupOwned"]); item.GroupOwned = Convert.ToBoolean(reader["groupOwned"]);
item.Flags = Convert.ToUInt32(reader["flags"]); item.Flags = ConvertInt32BitFieldToUint32((int)reader["flags"]);
return item; return item;
} }
@ -368,7 +379,7 @@ namespace OpenSim.Data.MSSQL
/// <summary> /// <summary>
/// Reads a list of inventory folders returned by a query. /// Reads a list of inventory folders returned by a query.
/// </summary> /// </summary>
/// <param name="reader">A MySQL Data Reader</param> /// <param name="reader">A MSSQL Data Reader</param>
/// <returns>A List containing inventory folders</returns> /// <returns>A List containing inventory folders</returns>
protected static InventoryFolderBase readInventoryFolder(IDataReader reader) protected static InventoryFolderBase readInventoryFolder(IDataReader reader)
{ {
@ -380,7 +391,7 @@ namespace OpenSim.Data.MSSQL
folder.ID = new LLUUID((string) reader["folderID"]); folder.ID = new LLUUID((string) reader["folderID"]);
folder.Name = (string) reader["folderName"]; folder.Name = (string) reader["folderName"];
folder.Type = (short) reader["type"]; folder.Type = (short) reader["type"];
folder.Version = (ushort) ((int) reader["version"]); folder.Version = Convert.ToUInt16(reader["version"]);
return folder; return folder;
} }
catch (Exception e) catch (Exception e)
@ -450,31 +461,29 @@ namespace OpenSim.Data.MSSQL
try try
{ {
Dictionary<string, string> param = new Dictionary<string, string>(); SqlCommand command = new SqlCommand(sql, database.getConnection());
param["inventoryID"] = item.ID.ToString(); command.Parameters.AddWithValue("inventoryID", item.ID.ToString());
param["assetID"] = item.AssetID.ToString(); command.Parameters.AddWithValue("assetID", item.AssetID.ToString());
param["assetType"] = item.AssetType.ToString(); command.Parameters.AddWithValue("assetType", item.AssetType.ToString());
param["parentFolderID"] = item.Folder.ToString(); command.Parameters.AddWithValue("parentFolderID", item.Folder.ToString());
param["avatarID"] = item.Owner.ToString(); command.Parameters.AddWithValue("avatarID", item.Owner.ToString());
param["inventoryName"] = item.Name; command.Parameters.AddWithValue("inventoryName", item.Name);
param["inventoryDescription"] = item.Description; command.Parameters.AddWithValue("inventoryDescription", item.Description);
param["inventoryNextPermissions"] = item.NextPermissions.ToString(); command.Parameters.AddWithValue("inventoryNextPermissions", ConvertUint32BitFieldToInt32(item.NextPermissions));
param["inventoryCurrentPermissions"] = item.CurrentPermissions.ToString(); command.Parameters.AddWithValue("inventoryCurrentPermissions", ConvertUint32BitFieldToInt32(item.CurrentPermissions));
param["invType"] = Convert.ToString(item.InvType); command.Parameters.AddWithValue("invType", item.InvType);
param["creatorID"] = item.Creator.ToString(); command.Parameters.AddWithValue("creatorID", item.Creator.ToString());
param["inventoryBasePermissions"] = Convert.ToString(item.BasePermissions); command.Parameters.AddWithValue("inventoryBasePermissions", ConvertUint32BitFieldToInt32(item.BasePermissions));
param["inventoryEveryOnePermissions"] = Convert.ToString(item.EveryOnePermissions); command.Parameters.AddWithValue("inventoryEveryOnePermissions", ConvertUint32BitFieldToInt32(item.EveryOnePermissions));
command.Parameters.AddWithValue("salePrice", item.SalePrice);
command.Parameters.AddWithValue("saleType", item.SaleType);
command.Parameters.AddWithValue("creationDate", item.CreationDate);
command.Parameters.AddWithValue("groupID", item.GroupID.ToString());
command.Parameters.AddWithValue("groupOwned", item.GroupOwned);
command.Parameters.AddWithValue("flags", ConvertUint32BitFieldToInt32(item.Flags));
param["salePrice"] = Convert.ToString(item.SalePrice); command.ExecuteNonQuery();
param["saleType"] = Convert.ToString(item.SaleType); command.Dispose();
param["creationDate"] = Convert.ToString(item.CreationDate);
param["groupID"] = item.GroupID.ToString();
param["groupOwned"] = Convert.ToString(item.GroupOwned);
param["flags"] = Convert.ToString(item.Flags);
IDbCommand result = database.Query(sql, param);
result.ExecuteNonQuery();
result.Dispose();
} }
catch (SqlException e) catch (SqlException e)
{ {
@ -490,46 +499,44 @@ namespace OpenSim.Data.MSSQL
{ {
SqlCommand command = new SqlCommand("UPDATE inventoryitems set inventoryID = @inventoryID, " + SqlCommand command = new SqlCommand("UPDATE inventoryitems set inventoryID = @inventoryID, " +
"assetID = @assetID, " + "assetID = @assetID, " +
"assetType = @assetType" + "assetType = @assetType," +
"parentFolderID = @parentFolderID" + "parentFolderID = @parentFolderID," +
"avatarID = @avatarID" + "avatarID = @avatarID," +
"inventoryName = @inventoryName" + "inventoryName = @inventoryName," +
"inventoryDescription = @inventoryDescription" + "inventoryDescription = @inventoryDescription," +
"inventoryNextPermissions = @inventoryNextPermissions" + "inventoryNextPermissions = @inventoryNextPermissions," +
"inventoryCurrentPermissions = @inventoryCurrentPermissions" + "inventoryCurrentPermissions = @inventoryCurrentPermissions," +
"invType = @invType" + "invType = @invType," +
"creatorID = @creatorID" + "creatorID = @creatorID," +
"inventoryBasePermissions = @inventoryBasePermissions" + "inventoryBasePermissions = @inventoryBasePermissions," +
"inventoryEveryOnePermissions = @inventoryEveryOnePermissions) where " + "inventoryEveryOnePermissions = @inventoryEveryOnePermissions," +
"salePrice = @salePrice," +
"saleType = @saleType," +
"creationDate = @creationDate," +
"groupID = @groupID," +
"groupOwned = @groupOwned," +
"flags = @flags where " +
"inventoryID = @keyInventoryID;", database.getConnection()); "inventoryID = @keyInventoryID;", database.getConnection());
SqlParameter param1 = new SqlParameter("@inventoryID", item.ID.ToString()); command.Parameters.AddWithValue("inventoryID", item.ID.ToString());
SqlParameter param2 = new SqlParameter("@assetID", item.AssetID); command.Parameters.AddWithValue("assetID", item.AssetID.ToString());
SqlParameter param3 = new SqlParameter("@assetType", item.AssetType); command.Parameters.AddWithValue("assetType", item.AssetType.ToString());
SqlParameter param4 = new SqlParameter("@parentFolderID", item.Folder); command.Parameters.AddWithValue("parentFolderID", item.Folder.ToString());
SqlParameter param5 = new SqlParameter("@avatarID", item.Owner); command.Parameters.AddWithValue("avatarID", item.Owner.ToString());
SqlParameter param6 = new SqlParameter("@inventoryName", item.Name); command.Parameters.AddWithValue("inventoryName", item.Name);
SqlParameter param7 = new SqlParameter("@inventoryDescription", item.Description); command.Parameters.AddWithValue("inventoryDescription", item.Description);
SqlParameter param8 = new SqlParameter("@inventoryNextPermissions", item.NextPermissions); command.Parameters.AddWithValue("inventoryNextPermissions", ConvertUint32BitFieldToInt32(item.NextPermissions));
SqlParameter param9 = new SqlParameter("@inventoryCurrentPermissions", item.CurrentPermissions); command.Parameters.AddWithValue("inventoryCurrentPermissions", ConvertUint32BitFieldToInt32(item.CurrentPermissions));
SqlParameter param10 = new SqlParameter("@invType", item.InvType); command.Parameters.AddWithValue("invType", item.InvType);
SqlParameter param11 = new SqlParameter("@creatorID", item.Creator); command.Parameters.AddWithValue("creatorID", item.Creator.ToString());
SqlParameter param12 = new SqlParameter("@inventoryBasePermissions", item.BasePermissions); command.Parameters.AddWithValue("inventoryBasePermissions", ConvertUint32BitFieldToInt32(item.BasePermissions));
SqlParameter param13 = new SqlParameter("@inventoryEveryOnePermissions", item.EveryOnePermissions); command.Parameters.AddWithValue("inventoryEveryOnePermissions", ConvertUint32BitFieldToInt32(item.EveryOnePermissions));
SqlParameter param14 = new SqlParameter("@keyInventoryID", item.ID.ToString()); command.Parameters.AddWithValue("salePrice", item.SalePrice);
command.Parameters.Add(param1); command.Parameters.AddWithValue("saleType", item.SaleType);
command.Parameters.Add(param2); command.Parameters.AddWithValue("creationDate", item.CreationDate);
command.Parameters.Add(param3); command.Parameters.AddWithValue("groupID", item.GroupID.ToString());
command.Parameters.Add(param4); command.Parameters.AddWithValue("groupOwned", item.GroupOwned);
command.Parameters.Add(param5); command.Parameters.AddWithValue("flags", ConvertUint32BitFieldToInt32(item.Flags));
command.Parameters.Add(param6); command.Parameters.AddWithValue("@keyInventoryID", item.ID.ToString());
command.Parameters.Add(param7);
command.Parameters.Add(param8);
command.Parameters.Add(param9);
command.Parameters.Add(param10);
command.Parameters.Add(param11);
command.Parameters.Add(param12);
command.Parameters.Add(param13);
command.Parameters.Add(param14);
try try
{ {
@ -574,19 +581,19 @@ namespace OpenSim.Data.MSSQL
sql += "(@folderID, @agentID, @parentFolderID, @folderName, @type, @version);"; sql += "(@folderID, @agentID, @parentFolderID, @folderName, @type, @version);";
Dictionary<string, string> param = new Dictionary<string, string>(); SqlCommand command = new SqlCommand(sql, database.getConnection());
param["folderID"] = folder.ID.ToString(); command.Parameters.AddWithValue("folderID", folder.ID.ToString());
param["agentID"] = folder.Owner.ToString(); command.Parameters.AddWithValue("agentID", folder.Owner.ToString());
param["parentFolderID"] = folder.ParentID.ToString(); command.Parameters.AddWithValue("parentFolderID", folder.ParentID.ToString());
param["folderName"] = folder.Name; command.Parameters.AddWithValue("folderName", folder.Name);
param["type"] = Convert.ToString(folder.Type); command.Parameters.AddWithValue("type", folder.Type);
param["version"] = Convert.ToString(folder.Version); command.Parameters.AddWithValue("version", Convert.ToInt32(folder.Version));
try try
{ {
IDbCommand result = database.Query(sql, param); //IDbCommand result = database.Query(sql, param);
result.ExecuteNonQuery(); command.ExecuteNonQuery();
result.Dispose(); command.Dispose();
} }
catch (Exception e) catch (Exception e)
{ {
@ -612,7 +619,7 @@ namespace OpenSim.Data.MSSQL
SqlParameter param3 = new SqlParameter("@parentFolderID", folder.ParentID.ToString()); SqlParameter param3 = new SqlParameter("@parentFolderID", folder.ParentID.ToString());
SqlParameter param4 = new SqlParameter("@folderName", folder.Name); SqlParameter param4 = new SqlParameter("@folderName", folder.Name);
SqlParameter param5 = new SqlParameter("@type", folder.Type); SqlParameter param5 = new SqlParameter("@type", folder.Type);
SqlParameter param6 = new SqlParameter("@version", folder.Version); SqlParameter param6 = new SqlParameter("@version", Convert.ToInt32(folder.Version));
SqlParameter param7 = new SqlParameter("@keyFolderID", folder.ID.ToString()); SqlParameter param7 = new SqlParameter("@keyFolderID", folder.ID.ToString());
command.Parameters.Add(param1); command.Parameters.Add(param1);
command.Parameters.Add(param2); command.Parameters.Add(param2);