From 4c25008850f92bcc79502c71a0e4d34c883d27d0 Mon Sep 17 00:00:00 2001 From: MW Date: Mon, 8 Oct 2007 10:30:15 +0000 Subject: [PATCH] Applied patch 485, inventory patch from tleiades (thanks again). --- .../Communications/InventoryServiceBase.cs | 4 +- OpenSim/Framework/Data.MySQL/MySQLGridData.cs | 10 +- .../Data.MySQL/MySQLInventoryData.cs | 414 +++++++++++++++--- OpenSim/Framework/Data.MySQL/MySQLManager.cs | 164 +------ OpenSim/Framework/Data.MySQL/MySQLUserData.cs | 9 +- .../Data.SQLite/Properties/AssemblyInfo.cs | 2 +- .../Data.SQLite/SQLiteInventoryStore.cs | 29 +- .../General/Types/InventoryItemBase.cs | 5 +- prebuild.xml | 3 + share/sql/mysql-inventoryfolders.sql | 9 - share/sql/mysql-inventoryitems.sql | 14 - 11 files changed, 409 insertions(+), 254 deletions(-) diff --git a/OpenSim/Framework/Communications/InventoryServiceBase.cs b/OpenSim/Framework/Communications/InventoryServiceBase.cs index 7536429bbd..366b110941 100644 --- a/OpenSim/Framework/Communications/InventoryServiceBase.cs +++ b/OpenSim/Framework/Communications/InventoryServiceBase.cs @@ -128,7 +128,7 @@ namespace OpenSim.Framework.Communications { foreach (KeyValuePair plugin in m_plugins) { - plugin.Value.deleteInventoryItem(item); + plugin.Value.deleteInventoryItem(item.inventoryID); } } @@ -208,4 +208,4 @@ namespace OpenSim.Framework.Communications public abstract void AddNewInventoryItem(LLUUID userID, InventoryItemBase item); public abstract void DeleteInventoryItem(LLUUID userID, InventoryItemBase item); } -} \ No newline at end of file +} diff --git a/OpenSim/Framework/Data.MySQL/MySQLGridData.cs b/OpenSim/Framework/Data.MySQL/MySQLGridData.cs index 452434a5e1..5709bf07ed 100644 --- a/OpenSim/Framework/Data.MySQL/MySQLGridData.cs +++ b/OpenSim/Framework/Data.MySQL/MySQLGridData.cs @@ -32,6 +32,8 @@ using System.Security.Cryptography; using System.Text; using libsecondlife; +using OpenSim.Framework.Console; + namespace OpenSim.Framework.Data.MySQL { /// @@ -127,7 +129,7 @@ namespace OpenSim.Framework.Data.MySQL catch (Exception e) { database.Reconnect(); - Console.WriteLine(e.ToString()); + MainLog.Instance.Error(e.ToString()); return null; } } @@ -159,7 +161,7 @@ namespace OpenSim.Framework.Data.MySQL catch (Exception e) { database.Reconnect(); - Console.WriteLine(e.ToString()); + MainLog.Instance.Error(e.ToString()); return null; } } @@ -191,7 +193,7 @@ namespace OpenSim.Framework.Data.MySQL catch (Exception e) { database.Reconnect(); - Console.WriteLine(e.ToString()); + MainLog.Instance.Error(e.ToString()); return null; } } @@ -277,7 +279,7 @@ namespace OpenSim.Framework.Data.MySQL catch (Exception e) { database.Reconnect(); - Console.WriteLine(e.ToString()); + MainLog.Instance.Error(e.ToString()); return null; } } diff --git a/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs b/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs index 478e8b59d8..804fd5f8ce 100644 --- a/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs +++ b/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs @@ -26,22 +26,26 @@ * */ using System; -using System.Collections.Generic; +using System.IO; using System.Data; +using System.Reflection; +using System.Collections.Generic; using libsecondlife; using OpenSim.Framework.Types; +using OpenSim.Framework.Console; +using MySql.Data.MySqlClient; namespace OpenSim.Framework.Data.MySQL { /// /// A MySQL interface for the inventory server /// - class MySQLInventoryData : IInventoryData + public class MySQLInventoryData : IInventoryData { /// /// The database manager /// - public MySQLManager database; + private MySQLManager database; /// /// Loads and initialises this database plugin @@ -57,8 +61,101 @@ namespace OpenSim.Framework.Data.MySQL string settingPort = GridDataMySqlFile.ParseFileReadValue("port"); database = new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword, settingPooling, settingPort); + TestTables(database.Connection); } - + + #region Test and initialization code + /// + /// Extract a named string resource from the embedded resources + /// + /// name of embedded resource + /// string contained within the embedded resource + private string getResourceString(string name) + { + Assembly assem = this.GetType().Assembly; + string[] names = assem.GetManifestResourceNames(); + + foreach(string s in names) + if(s.EndsWith(name)) + using (Stream resource = assem.GetManifestResourceStream(s)) + { + using (StreamReader resourceReader = new StreamReader(resource)) + { + string resourceString = resourceReader.ReadToEnd(); + return resourceString; + } + } + throw new Exception(string.Format("Resource '{0}' was not found", name)); + } + + private void ExecuteResourceSql(MySqlConnection conn, string name) + { + MySqlCommand cmd = new MySqlCommand(getResourceString(name), conn); + cmd.ExecuteNonQuery(); + } + + private void UpgradeFoldersTable(MySqlConnection conn, string oldVersion) + { + // null as the version, indicates that the table didn't exist + if (oldVersion == null) + { + ExecuteResourceSql(conn, "CreateFoldersTable.sql"); + return; + } + + // if the table is already at the current version, then we can exit immediately + if (oldVersion == "Rev. 2") + return; + + ExecuteResourceSql(conn, "UpgradeFoldersTableToVersion2.sql"); + } + + private void UpgradeItemsTable(MySqlConnection conn, string oldVersion) + { + // null as the version, indicates that the table didn't exist + if (oldVersion == null) + { + ExecuteResourceSql(conn, "CreateItemsTable.sql"); + return; + } + + // if the table is already at the current version, then we can exit immediately + if (oldVersion == "Rev. 2") + return; + + ExecuteResourceSql(conn, "UpgradeItemsTableToVersion2.sql"); + } + + private void TestTables(MySqlConnection conn) + { + + Dictionary tableList = new Dictionary(); + + tableList["inventoryfolders"] = null; + tableList["inventoryitems"] = null; + + MySqlCommand tablesCmd = new MySqlCommand("SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='opensim'", conn); + MySqlDataReader tables = tablesCmd.ExecuteReader(); + while (tables.Read()) + { + try + { + string tableName = (string)tables["TABLE_NAME"]; + string comment = (string)tables["TABLE_COMMENT"]; + tableList[tableName] = comment; + } + catch (Exception e) + { + MainLog.Instance.Error(e.ToString()); + } + } + tables.Close(); + + UpgradeFoldersTable(conn, tableList["inventoryfolders"]); + UpgradeItemsTable(conn, tableList["inventoryitems"]); + } + #endregion + /// /// The name of this DB provider /// @@ -82,7 +179,12 @@ namespace OpenSim.Framework.Data.MySQL /// A string containing the DB provider public string getVersion() { - return "0.1"; + System.Reflection.Module module = this.GetType().Module; + string dllName = module.Assembly.ManifestModule.Name; + Version dllVersion = module.Assembly.GetName().Version; + + + return string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, dllVersion.Revision); } /// @@ -96,13 +198,14 @@ namespace OpenSim.Framework.Data.MySQL { lock (database) { - Dictionary param = new Dictionary(); - param["?uuid"] = folderID.ToStringHyphenated(); + List items = new List(); - IDbCommand result = database.Query("SELECT * FROM inventoryitems WHERE parentFolderID = ?uuid", param); - IDataReader reader = result.ExecuteReader(); + MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE parentFolderID = ?uuid", database.Connection); + result.Parameters.Add("?uuid", folderID.ToStringHyphenated()); + MySqlDataReader reader = result.ExecuteReader(); - List items = database.readInventoryItems(reader); + while(reader.Read()) + items.Add(readInventoryItem(reader)); reader.Close(); result.Dispose(); @@ -113,7 +216,7 @@ namespace OpenSim.Framework.Data.MySQL catch (Exception e) { database.Reconnect(); - Console.WriteLine(e.ToString()); + MainLog.Instance.Error(e.ToString()); return null; } } @@ -129,14 +232,15 @@ namespace OpenSim.Framework.Data.MySQL { lock (database) { - Dictionary param = new Dictionary(); - param["?uuid"] = user.ToStringHyphenated(); - param["?zero"] = LLUUID.Zero.ToStringHyphenated(); + MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", database.Connection); + result.Parameters.Add("?uuid", user.ToStringHyphenated()); + result.Parameters.Add("?zero", LLUUID.Zero.ToStringHyphenated()); + MySqlDataReader reader = result.ExecuteReader(); - IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", param); - IDataReader reader = result.ExecuteReader(); + List items = new List(); + while(reader.Read()) + items.Add(readInventoryFolder(reader)); - List items = database.readInventoryFolders(reader); reader.Close(); result.Dispose(); @@ -147,7 +251,7 @@ namespace OpenSim.Framework.Data.MySQL catch (Exception e) { database.Reconnect(); - Console.WriteLine(e.ToString()); + MainLog.Instance.Error(e.ToString()); return null; } } @@ -167,10 +271,16 @@ namespace OpenSim.Framework.Data.MySQL param["?uuid"] = user.ToStringHyphenated(); param["?zero"] = LLUUID.Zero.ToStringHyphenated(); - IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", param); - IDataReader reader = result.ExecuteReader(); + MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", database.Connection); + result.Parameters.Add("?uuid", user.ToStringHyphenated()); + result.Parameters.Add("?zero", LLUUID.Zero.ToStringHyphenated()); + + MySqlDataReader reader = result.ExecuteReader(); + + List items = new List(); + while(reader.Read()) + items.Add(readInventoryFolder(reader)); - List items = database.readInventoryFolders(reader); InventoryFolderBase rootFolder = items[0]; //should only be one folder with parent set to zero (the root one). reader.Close(); result.Dispose(); @@ -181,7 +291,7 @@ namespace OpenSim.Framework.Data.MySQL catch (Exception e) { database.Reconnect(); - Console.WriteLine(e.ToString()); + MainLog.Instance.Error(e.ToString()); return null; } } @@ -197,13 +307,14 @@ namespace OpenSim.Framework.Data.MySQL { lock (database) { - Dictionary param = new Dictionary(); - param["?uuid"] = parentID.ToStringHyphenated(); + MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?uuid", database.Connection); + result.Parameters.Add("?uuid", parentID.ToStringHyphenated()); + MySqlDataReader reader = result.ExecuteReader(); - IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = ?uuid", param); - IDataReader reader = result.ExecuteReader(); - - List items = database.readInventoryFolders(reader); + List items = new List(); + + while(reader.Read()) + items.Add(readInventoryFolder(reader)); reader.Close(); result.Dispose(); @@ -214,87 +325,134 @@ namespace OpenSim.Framework.Data.MySQL catch (Exception e) { database.Reconnect(); - Console.WriteLine(e.ToString()); + MainLog.Instance.Error(e.ToString()); return null; } } + /// + /// Reads a one item from an SQL result + /// + /// The SQL Result + /// the item read + public InventoryItemBase readInventoryItem(MySqlDataReader reader) + { + try + { + InventoryItemBase item = new InventoryItemBase(); + + item.inventoryID = new LLUUID((string)reader["inventoryID"]); + item.assetID = new LLUUID((string)reader["assetID"]); + item.assetType = (int)reader["assetType"]; + item.parentFolderID = new LLUUID((string)reader["parentFolderID"]); + item.avatarID = new LLUUID((string)reader["avatarID"]); + item.inventoryName = (string)reader["inventoryName"]; + item.inventoryDescription = (string)reader["inventoryDescription"]; + item.inventoryNextPermissions = (uint)reader["inventoryNextPermissions"]; + item.inventoryCurrentPermissions = (uint)reader["inventoryCurrentPermissions"]; + item.invType = (int)reader["invType"]; + item.creatorsID = new LLUUID((string)reader["creatorID"]); + item.inventoryBasePermissions = (uint)reader["inventoryBasePermissions"]; + item.inventoryEveryOnePermissions = (uint)reader["inventoryEveryOnePermissions"]; + return item; + } + catch (MySqlException e) + { + MainLog.Instance.Error(e.ToString()); + } + + return null; + } + /// /// Returns a specified inventory item /// /// The item to return /// An inventory item - public InventoryItemBase getInventoryItem(LLUUID item) + public InventoryItemBase getInventoryItem(LLUUID itemID) { try { lock (database) { Dictionary param = new Dictionary(); - param["?uuid"] = item.ToStringHyphenated(); - IDbCommand result = database.Query("SELECT * FROM inventoryitems WHERE inventoryID = ?uuid", param); - IDataReader reader = result.ExecuteReader(); + MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE inventoryID = ?uuid", database.Connection); + result.Parameters.Add("?uuid", itemID.ToStringHyphenated()); + MySqlDataReader reader = result.ExecuteReader(); - List items = database.readInventoryItems(reader); + InventoryItemBase item = null; + if(reader.Read()) + item = readInventoryItem(reader); reader.Close(); result.Dispose(); - if (items.Count > 0) - { - return items[0]; - } - else - { - return null; - } + return item; } } catch (Exception e) { database.Reconnect(); - Console.WriteLine(e.ToString()); - return null; + MainLog.Instance.Error(e.ToString()); } + return null; } + /// + /// Reads a list of inventory folders returned by a query. + /// + /// A MySQL Data Reader + /// A List containing inventory folders + protected InventoryFolderBase readInventoryFolder(MySqlDataReader reader) + { + try + { + InventoryFolderBase folder = new InventoryFolderBase(); + folder.agentID = new LLUUID((string)reader["agentID"]); + folder.parentID = new LLUUID((string)reader["parentFolderID"]); + folder.folderID = new LLUUID((string)reader["folderID"]); + folder.name = (string)reader["folderName"]; + folder.type = (short)reader["type"]; + folder.version = (ushort)((int)reader["version"]); + return folder; + } + catch (Exception e) + { + MainLog.Instance.Error(e.ToString()); + } + + return null; + } + + /// /// Returns a specified inventory folder /// /// The folder to return /// A folder class - public InventoryFolderBase getInventoryFolder(LLUUID folder) + public InventoryFolderBase getInventoryFolder(LLUUID folderID) { try { lock (database) { - Dictionary param = new Dictionary(); - param["?uuid"] = folder.ToStringHyphenated(); - - IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", param); - IDataReader reader = result.ExecuteReader(); - - List items = database.readInventoryFolders(reader); + MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", database.Connection); + result.Parameters.Add("?uuid", folderID.ToStringHyphenated()); + MySqlDataReader reader = result.ExecuteReader(); + reader.Read(); + InventoryFolderBase folder = readInventoryFolder(reader); reader.Close(); result.Dispose(); - if (items.Count > 0) - { - return items[0]; - } - else - { - return null; - } + return folder; } } catch (Exception e) { database.Reconnect(); - Console.WriteLine(e.ToString()); + MainLog.Instance.Error(e.ToString()); return null; } } @@ -305,9 +463,31 @@ namespace OpenSim.Framework.Data.MySQL /// The inventory item public void addInventoryItem(InventoryItemBase item) { - lock (database) + string sql = "REPLACE INTO inventoryitems (inventoryID, assetID, assetType, parentFolderID, avatarID, inventoryName, inventoryDescription, inventoryNextPermissions, inventoryCurrentPermissions, invType, creatorID, inventoryBasePermissions, inventoryEveryOnePermissions) VALUES "; + sql += "(?inventoryID, ?assetID, ?assetType, ?parentFolderID, ?avatarID, ?inventoryName, ?inventoryDescription, ?inventoryNextPermissions, ?inventoryCurrentPermissions, ?invType, ?creatorID, ?inventoryBasePermissions, ?inventoryEveryOnePermissions)"; + + try { - database.insertItem(item); + MySqlCommand result = new MySqlCommand(sql, database.Connection); + result.Parameters.Add("?inventoryID", item.inventoryID.ToStringHyphenated()); + result.Parameters.Add("?assetID", item.assetID.ToStringHyphenated()); + result.Parameters.Add("?assetType", item.assetType.ToString()); + result.Parameters.Add("?parentFolderID", item.parentFolderID.ToStringHyphenated()); + result.Parameters.Add("?avatarID", item.avatarID.ToStringHyphenated()); + result.Parameters.Add("?inventoryName", item.inventoryName); + result.Parameters.Add("?inventoryDescription", item.inventoryDescription); + result.Parameters.Add("?inventoryNextPermissions", item.inventoryNextPermissions.ToString()); + result.Parameters.Add("?inventoryCurrentPermissions", item.inventoryCurrentPermissions.ToString()); + result.Parameters.Add("?invType", item.invType); + result.Parameters.Add("?creatorID", item.creatorsID.ToStringHyphenated()); + result.Parameters.Add("?inventoryBasePermissions", item.inventoryBasePermissions); + result.Parameters.Add("?inventoryEveryOnePermissions", item.inventoryEveryOnePermissions); + result.ExecuteNonQuery(); + result.Dispose(); + } + catch (MySqlException e) + { + MainLog.Instance.Error(e.ToString()); } } @@ -324,9 +504,19 @@ namespace OpenSim.Framework.Data.MySQL /// /// /// - public void deleteInventoryItem(InventoryItemBase item) + public void deleteInventoryItem(LLUUID itemID) { - + try + { + MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryitems WHERE inventoryID=?uuid", database.Connection); + cmd.Parameters.Add("?uuid", itemID.ToStringHyphenated()); + cmd.ExecuteNonQuery(); + } + catch (MySqlException e) + { + database.Reconnect(); + MainLog.Instance.Error(e.ToString()); + } } /// @@ -335,9 +525,24 @@ namespace OpenSim.Framework.Data.MySQL /// Folder to create public void addInventoryFolder(InventoryFolderBase folder) { - lock (database) + string sql = "REPLACE INTO inventoryfolders (folderID, agentID, parentFolderID, folderName, type, version) VALUES "; + sql += "(?folderID, ?agentID, ?parentFolderID, ?folderName, ?type, ?version)"; + + MySqlCommand cmd = new MySqlCommand(sql, database.Connection); + cmd.Parameters.Add("?folderID", folder.folderID.ToStringHyphenated()); + cmd.Parameters.Add("?agentID", folder.agentID.ToStringHyphenated()); + cmd.Parameters.Add("?parentFolderID", folder.parentID.ToStringHyphenated()); + cmd.Parameters.Add("?folderName", folder.name); + cmd.Parameters.Add("?type", (short)folder.type); + cmd.Parameters.Add("?version", folder.version); + + try { - database.insertFolder(folder); + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + MainLog.Instance.Error(e.ToString()); } } @@ -351,12 +556,87 @@ namespace OpenSim.Framework.Data.MySQL } + /// + /// Append a list of all the child folders of a parent folder + /// + /// list where folders will be appended + /// ID of parent + protected void getInventoryFolders(ref List folders, LLUUID parentID) + { + List subfolderList = getInventoryFolders(parentID); + + foreach (InventoryFolderBase f in subfolderList) + folders.Add(f); + } + + /// + /// Returns all child folders in the hierarchy from the parent folder and down + /// + /// The folder to get subfolders for + /// A list of inventory folders + protected List getFolderHierarchy(LLUUID parentID) + { + List folders = new List(); + getInventoryFolders(ref folders, parentID); + + for (int i = 0; i < folders.Count; i++) + getInventoryFolders(ref folders, folders[i].folderID); + + return folders; + } + + protected void deleteOneFolder(LLUUID folderID) + { + try + { + MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryfolders WHERE folderID=?uuid", database.Connection); + cmd.Parameters.Add("?uuid", folderID.ToStringHyphenated()); + cmd.ExecuteNonQuery(); + } + catch (MySqlException e) + { + database.Reconnect(); + MainLog.Instance.Error(e.ToString()); + } + } + + protected void deleteItemsInFolder(LLUUID folderID) + { + try + { + MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryitems WHERE parentFolderID=?uuid", database.Connection); + cmd.Parameters.Add("?uuid", folderID.ToStringHyphenated()); + cmd.ExecuteNonQuery(); + } + catch (MySqlException e) + { + database.Reconnect(); + MainLog.Instance.Error(e.ToString()); + } + } + + /// /// Delete an inventory folder /// /// Id of folder to delete public void deleteInventoryFolder(LLUUID folderID) { + lock (database) + { + List subFolders = getFolderHierarchy(folderID); + + //Delete all sub-folders + foreach (InventoryFolderBase f in subFolders) + { + deleteOneFolder(f.folderID); + deleteItemsInFolder(f.folderID); + } + + //Delete the actual row + deleteOneFolder(folderID); + deleteItemsInFolder(folderID); + } } } } diff --git a/OpenSim/Framework/Data.MySQL/MySQLManager.cs b/OpenSim/Framework/Data.MySQL/MySQLManager.cs index a83ee45a45..ea174b2dca 100644 --- a/OpenSim/Framework/Data.MySQL/MySQLManager.cs +++ b/OpenSim/Framework/Data.MySQL/MySQLManager.cs @@ -31,6 +31,7 @@ using System.Data; using libsecondlife; using MySql.Data.MySqlClient; using OpenSim.Framework.Types; +using OpenSim.Framework.Console; namespace OpenSim.Framework.Data.MySQL { @@ -42,7 +43,7 @@ namespace OpenSim.Framework.Data.MySQL /// /// The database connection object /// - IDbConnection dbcon; + MySqlConnection dbcon; /// /// Connection string for ADO.net /// @@ -65,7 +66,7 @@ namespace OpenSim.Framework.Data.MySQL dbcon.Open(); - Console.WriteLine("MySQL connection established"); + MainLog.Instance.Verbose("MySQL connection established"); } catch (Exception e) { @@ -73,6 +74,14 @@ namespace OpenSim.Framework.Data.MySQL } } + /// + /// Get the connection being used + /// + public MySqlConnection Connection + { + get { return dbcon; } + } + /// /// Shuts down the database connection /// @@ -99,7 +108,7 @@ namespace OpenSim.Framework.Data.MySQL } catch (Exception e) { - Console.WriteLine("Unable to reconnect to database " + e.ToString()); + MainLog.Instance.Error("Unable to reconnect to database " + e.ToString()); } } } @@ -142,7 +151,7 @@ namespace OpenSim.Framework.Data.MySQL } catch (Exception e) { - Console.WriteLine("Unable to reconnect to database " + e.ToString()); + MainLog.Instance.Error("Unable to reconnect to database " + e.ToString()); } // Run the query again @@ -160,7 +169,7 @@ namespace OpenSim.Framework.Data.MySQL catch (Exception e) { // Return null if it fails. - Console.WriteLine("Failed during Query generation: " + e.ToString()); + MainLog.Instance.Error("Failed during Query generation: " + e.ToString()); return null; } } @@ -352,72 +361,7 @@ namespace OpenSim.Framework.Data.MySQL return retval; } - /// - /// Reads a list of inventory folders returned by a query. - /// - /// A MySQL Data Reader - /// A List containing inventory folders - public List readInventoryFolders(IDataReader reader) - { - List rows = new List(); - while(reader.Read()) - { - try - { - InventoryFolderBase folder = new InventoryFolderBase(); - - folder.agentID = new LLUUID((string)reader["agentID"]); - folder.parentID = new LLUUID((string)reader["parentFolderID"]); - folder.folderID = new LLUUID((string)reader["folderID"]); - folder.name = (string)reader["folderName"]; - - rows.Add(folder); - } - catch (Exception e) - { - Console.WriteLine(e.ToString()); - } - } - - return rows; - } - - /// - /// Reads a collection of items from an SQL result - /// - /// The SQL Result - /// A List containing Inventory Items - public List readInventoryItems(IDataReader reader) - { - List rows = new List(); - - while (reader.Read()) - { - try - { - InventoryItemBase item = new InventoryItemBase(); - - item.assetID = new LLUUID((string)reader["assetID"]); - item.avatarID = new LLUUID((string)reader["avatarID"]); - item.inventoryCurrentPermissions = Convert.ToUInt32(reader["inventoryCurrentPermissions"].ToString()); - item.inventoryDescription = (string)reader["inventoryDescription"]; - item.inventoryID = new LLUUID((string)reader["inventoryID"]); - item.inventoryName = (string)reader["inventoryName"]; - item.inventoryNextPermissions = Convert.ToUInt32(reader["inventoryNextPermissions"].ToString()); - item.parentFolderID = new LLUUID((string)reader["parentFolderID"]); - item.assetType = Convert.ToInt32(reader["type"].ToString()); - - rows.Add(item); - } - catch (Exception e) - { - Console.WriteLine(e.ToString()); - } - } - - return rows; - } /// /// Inserts a new row into the log database @@ -455,87 +399,13 @@ namespace OpenSim.Framework.Data.MySQL } catch (Exception e) { - Console.WriteLine(e.ToString()); + MainLog.Instance.Error(e.ToString()); return false; } return returnval; } - /// - /// Inserts a new item into the database - /// - /// The item - /// Success? - public bool insertItem(InventoryItemBase item) - { - string sql = "REPLACE INTO inventoryitems (inventoryID, assetID, type, parentFolderID, avatarID, inventoryName, inventoryDescription, inventoryNextPermissions, inventoryCurrentPermissions) VALUES "; - sql += "(?inventoryID, ?assetID, ?type, ?parentFolderID, ?avatarID, ?inventoryName, ?inventoryDescription, ?inventoryNextPermissions, ?inventoryCurrentPermissions)"; - - Dictionary parameters = new Dictionary(); - parameters["?inventoryID"] = item.inventoryID.ToStringHyphenated(); - parameters["?assetID"] = item.assetID.ToStringHyphenated(); - parameters["?type"] = item.assetType.ToString(); - parameters["?parentFolderID"] = item.parentFolderID.ToStringHyphenated(); - parameters["?avatarID"] = item.avatarID.ToStringHyphenated(); - parameters["?inventoryName"] = item.inventoryName; - parameters["?inventoryDescription"] = item.inventoryDescription; - parameters["?inventoryNextPermissions"] = item.inventoryNextPermissions.ToString(); - parameters["?inventoryCurrentPermissions"] = item.inventoryCurrentPermissions.ToString(); - - bool returnval = false; - - try - { - IDbCommand result = Query(sql, parameters); - - if (result.ExecuteNonQuery() == 1) - returnval = true; - - result.Dispose(); - } - catch (Exception e) - { - Console.WriteLine(e.ToString()); - return false; - } - - return returnval; - } - - /// - /// Inserts a new folder into the database - /// - /// The folder - /// Success? - public bool insertFolder(InventoryFolderBase folder) - { - string sql = "REPLACE INTO inventoryfolders (folderID, agentID, parentFolderID, folderName) VALUES "; - sql += "(?folderID, ?agentID, ?parentFolderID, ?folderName)"; - - Dictionary parameters = new Dictionary(); - parameters["?folderID"] = folder.folderID.ToStringHyphenated(); - parameters["?agentID"] = folder.agentID.ToStringHyphenated(); - parameters["?parentFolderID"] = folder.parentID.ToStringHyphenated(); - parameters["?folderName"] = folder.name; - - bool returnval = false; - try - { - IDbCommand result = Query(sql, parameters); - - if (result.ExecuteNonQuery() == 1) - returnval = true; - - result.Dispose(); - } - catch (Exception e) - { - Console.WriteLine(e.ToString()); - return false; - } - return returnval; - } /// /// Creates a new user and inserts it into the database @@ -614,7 +484,7 @@ namespace OpenSim.Framework.Data.MySQL } catch (Exception e) { - Console.WriteLine(e.ToString()); + MainLog.Instance.Error(e.ToString()); return false; } @@ -683,7 +553,7 @@ namespace OpenSim.Framework.Data.MySQL } catch (Exception e) { - Console.WriteLine(e.ToString()); + MainLog.Instance.Error(e.ToString()); return false; } diff --git a/OpenSim/Framework/Data.MySQL/MySQLUserData.cs b/OpenSim/Framework/Data.MySQL/MySQLUserData.cs index 301550fa71..915f54b935 100644 --- a/OpenSim/Framework/Data.MySQL/MySQLUserData.cs +++ b/OpenSim/Framework/Data.MySQL/MySQLUserData.cs @@ -30,6 +30,7 @@ using System.Collections.Generic; using System.Data; using libsecondlife; using OpenSim.Framework.Types; +using OpenSim.Framework.Console; namespace OpenSim.Framework.Data.MySQL { @@ -101,7 +102,7 @@ namespace OpenSim.Framework.Data.MySQL catch (Exception e) { database.Reconnect(); - Console.WriteLine(e.ToString()); + MainLog.Instance.Error(e.ToString()); return null; } } @@ -134,7 +135,7 @@ namespace OpenSim.Framework.Data.MySQL catch (Exception e) { database.Reconnect(); - Console.WriteLine(e.ToString()); + MainLog.Instance.Error(e.ToString()); return null; } } @@ -189,7 +190,7 @@ namespace OpenSim.Framework.Data.MySQL catch (Exception e) { database.Reconnect(); - Console.WriteLine(e.ToString()); + MainLog.Instance.Error(e.ToString()); return null; } } @@ -212,7 +213,7 @@ namespace OpenSim.Framework.Data.MySQL catch (Exception e) { database.Reconnect(); - Console.WriteLine(e.ToString()); + MainLog.Instance.Error(e.ToString()); } } diff --git a/OpenSim/Framework/Data.SQLite/Properties/AssemblyInfo.cs b/OpenSim/Framework/Data.SQLite/Properties/AssemblyInfo.cs index 8136bc175d..75bb53dbd9 100644 --- a/OpenSim/Framework/Data.SQLite/Properties/AssemblyInfo.cs +++ b/OpenSim/Framework/Data.SQLite/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyVersion("0.4.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/OpenSim/Framework/Data.SQLite/SQLiteInventoryStore.cs b/OpenSim/Framework/Data.SQLite/SQLiteInventoryStore.cs index 4c9c467009..1688b709fd 100644 --- a/OpenSim/Framework/Data.SQLite/SQLiteInventoryStore.cs +++ b/OpenSim/Framework/Data.SQLite/SQLiteInventoryStore.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using System.Reflection; using OpenSim.Framework.Console; using OpenSim.Framework.Types; @@ -166,7 +167,12 @@ namespace OpenSim.Framework.Data.SQLite /// A string containing the plugin version public string getVersion() { - return "0.1"; + System.Reflection.Module module = this.GetType().Module; + string dllName = module.Assembly.ManifestModule.Name; + Version dllVersion = module.Assembly.GetName().Version; + + + return string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, dllVersion.Revision); } /// @@ -337,11 +343,11 @@ namespace OpenSim.Framework.Data.SQLite /// /// /// - public void deleteInventoryItem(InventoryItemBase item) + public void deleteInventoryItem(LLUUID itemID) { DataTable inventoryItemTable = ds.Tables["inventoryitems"]; - DataRow inventoryRow = inventoryItemTable.Rows.Find(item.inventoryID); + DataRow inventoryRow = inventoryItemTable.Rows.Find(itemID); if (inventoryRow != null) { inventoryRow.Delete(); @@ -350,6 +356,20 @@ namespace OpenSim.Framework.Data.SQLite this.invItemsDa.Update(ds, "inventoryitems"); } + + /// + /// Delete all items in the specified folder + /// + /// id of the folder, whose item content should be deleted + //!TODO, this is horribly inefficient, but I don't want to ruin the overall structure of this implementatio + private void deleteItemsInFolder(LLUUID folderId) + { + List items = getInventoryInFolder(folderId); + + foreach(InventoryItemBase i in items) + deleteInventoryItem(i.inventoryID); + } + /// /// Adds a new folder specified by folder /// @@ -389,6 +409,7 @@ namespace OpenSim.Framework.Data.SQLite inventoryRow = inventoryFolderTable.Rows.Find(f.folderID); if (inventoryRow != null) { + deleteItemsInFolder(f.folderID); inventoryRow.Delete(); } } @@ -397,6 +418,7 @@ namespace OpenSim.Framework.Data.SQLite inventoryRow = inventoryFolderTable.Rows.Find(folderID); if (inventoryRow != null) { + deleteItemsInFolder(folderID); inventoryRow.Delete(); } @@ -554,3 +576,4 @@ namespace OpenSim.Framework.Data.SQLite } + diff --git a/OpenSim/Framework/General/Types/InventoryItemBase.cs b/OpenSim/Framework/General/Types/InventoryItemBase.cs index 7f59bcc734..fed7e50c88 100644 --- a/OpenSim/Framework/General/Types/InventoryItemBase.cs +++ b/OpenSim/Framework/General/Types/InventoryItemBase.cs @@ -205,7 +205,7 @@ namespace OpenSim.Framework.Types /// /// /// - void deleteInventoryItem(InventoryItemBase item); + void deleteInventoryItem(LLUUID item); /// /// Adds a new folder specified by folder @@ -224,6 +224,5 @@ namespace OpenSim.Framework.Types /// /// The id of the folder void deleteInventoryFolder(LLUUID folder); - } -} \ No newline at end of file +} diff --git a/prebuild.xml b/prebuild.xml index 35dec6685b..8bd52a9ab2 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -696,8 +696,10 @@ + + @@ -1044,3 +1046,4 @@ + diff --git a/share/sql/mysql-inventoryfolders.sql b/share/sql/mysql-inventoryfolders.sql index 87047025bd..e69de29bb2 100644 --- a/share/sql/mysql-inventoryfolders.sql +++ b/share/sql/mysql-inventoryfolders.sql @@ -1,9 +0,0 @@ -CREATE TABLE `inventoryfolders` ( - `folderID` varchar(36) NOT NULL default '', - `agentID` varchar(36) default NULL, - `parentFolderID` varchar(36) default NULL, - `folderName` varchar(64) default NULL, - PRIMARY KEY (`folderID`), - KEY `owner` (`agentID`), - KEY `parent` (`parentFolderID`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/share/sql/mysql-inventoryitems.sql b/share/sql/mysql-inventoryitems.sql index 5e03b8d8f4..e69de29bb2 100644 --- a/share/sql/mysql-inventoryitems.sql +++ b/share/sql/mysql-inventoryitems.sql @@ -1,14 +0,0 @@ -CREATE TABLE `inventoryitems` ( - `inventoryID` varchar(36) NOT NULL default '', - `assetID` varchar(36) default NULL, - `type` int(11) default NULL, - `parentFolderID` varchar(36) default NULL, - `avatarID` varchar(36) default NULL, - `inventoryName` varchar(64) default NULL, - `inventoryDescription` varchar(64) default NULL, - `inventoryNextPermissions` int(10) unsigned default NULL, - `inventoryCurrentPermissions` int(10) unsigned default NULL, - PRIMARY KEY (`inventoryID`), - KEY `owner` (`avatarID`), - KEY `folder` (`parentFolderID`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8;