* Restrict asset and inventory name descriptions so as not to overflow MSSQL field lengths
* Thanks StrawberryFride
trunk
Justin Clarke Casey 2009-07-24 19:10:32 +00:00
parent 169a353cca
commit a3f4330c87
2 changed files with 36 additions and 6 deletions

View File

@ -60,7 +60,7 @@ namespace OpenSim.Data.MSSQL
// [Obsolete("Cannot be default-initialized!")]
override public void Initialise()
{
m_log.Info("[MSSQLUserData]: " + Name + " cannot be default-initialized!");
m_log.Info("[MSSQLAssetData]: " + Name + " cannot be default-initialized!");
throw new PluginNotInitialisedException(Name);
}
@ -165,12 +165,24 @@ namespace OpenSim.Data.MSSQL
VALUES
(@id, @name, @description, @assetType, @local,
@temporary, @create_time, @access_time, @data)";
string assetName = asset.Name;
if (asset.Name.Length > 64)
{
assetName = asset.Name.Substring(0, 64);
m_log.Warn("[ASSET DB]: Name field truncated from " + asset.Name.Length.ToString() + " to " + assetName.Length.ToString() + " characters");
}
string assetDescription = asset.Description;
if (asset.Description.Length > 64)
{
assetDescription = asset.Description.Substring(0, 64);
m_log.Warn("[ASSET DB]: Description field truncated from " + asset.Description.Length.ToString() + " to " + assetDescription.Length.ToString() + " characters");
}
using (AutoClosingSqlCommand command = m_database.Query(sql))
{
int now = (int)((System.DateTime.Now.Ticks - m_ticksToEpoch) / 10000000);
command.Parameters.Add(m_database.CreateParameter("id", asset.FullID));
command.Parameters.Add(m_database.CreateParameter("name", asset.Name));
command.Parameters.Add(m_database.CreateParameter("description", asset.Description));
command.Parameters.Add(m_database.CreateParameter("name", assetName));
command.Parameters.Add(m_database.CreateParameter("description", assetDescription));
command.Parameters.Add(m_database.CreateParameter("assetType", asset.Type));
command.Parameters.Add(m_database.CreateParameter("local", asset.Local));
command.Parameters.Add(m_database.CreateParameter("temporary", asset.Temporary));
@ -178,7 +190,14 @@ namespace OpenSim.Data.MSSQL
command.Parameters.Add(m_database.CreateParameter("create_time", now));
command.Parameters.Add(m_database.CreateParameter("data", asset.Data));
command.ExecuteNonQuery();
try
{
command.ExecuteNonQuery();
}
catch(Exception e)
{
m_log.Error("[ASSET DB]: Error inserting item :" + e.Message);
}
}
}

View File

@ -412,7 +412,18 @@ namespace OpenSim.Data.MSSQL
@inventoryNextPermissions, @inventoryCurrentPermissions, @invType, @creatorID,
@inventoryBasePermissions, @inventoryEveryOnePermissions, @inventoryGroupPermissions, @salePrice, @saleType,
@creationDate, @groupID, @groupOwned, @flags)";
string itemName = item.Name;
if (item.Name.Length > 64)
{
itemName = item.Name.Substring(0, 64);
m_log.Warn("[INVENTORY DB]: Name field truncated from " + item.Name.Length.ToString() + " to " + itemName.Length.ToString() + " characters");
}
string itemDesc = item.Description;
if (item.Description.Length > 128)
{
itemDesc = item.Description.Substring(0, 128);
m_log.Warn("[INVENTORY DB]: Description field truncated from " + item.Description.Length.ToString() + " to " + itemDesc.Length.ToString() + " characters");
}
using (AutoClosingSqlCommand command = database.Query(sql))
{
command.Parameters.Add(database.CreateParameter("inventoryID", item.ID));
@ -420,7 +431,7 @@ namespace OpenSim.Data.MSSQL
command.Parameters.Add(database.CreateParameter("assetType", item.AssetType));
command.Parameters.Add(database.CreateParameter("parentFolderID", item.Folder));
command.Parameters.Add(database.CreateParameter("avatarID", item.Owner));
command.Parameters.Add(database.CreateParameter("inventoryName", item.Name));
command.Parameters.Add(database.CreateParameter("inventoryName", itemName));
command.Parameters.Add(database.CreateParameter("inventoryDescription", item.Description));
command.Parameters.Add(database.CreateParameter("inventoryNextPermissions", item.NextPermissions));
command.Parameters.Add(database.CreateParameter("inventoryCurrentPermissions", item.CurrentPermissions));