2007-07-16 15:40:11 +00:00
|
|
|
/*
|
2008-03-18 05:16:43 +00:00
|
|
|
* Copyright (c) Contributors, http://opensimulator.org/
|
|
|
|
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* * Neither the name of the OpenSim Project nor the
|
|
|
|
* names of its contributors may be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2007-07-16 15:40:11 +00:00
|
|
|
using System;
|
2007-10-08 10:30:15 +00:00
|
|
|
using System.Collections.Generic;
|
2007-07-16 15:40:11 +00:00
|
|
|
using libsecondlife;
|
2007-10-08 10:30:15 +00:00
|
|
|
using MySql.Data.MySqlClient;
|
2008-04-02 16:00:40 +00:00
|
|
|
using OpenSim.Framework;
|
2007-10-30 09:05:31 +00:00
|
|
|
using OpenSim.Framework.Console;
|
2007-07-16 15:40:11 +00:00
|
|
|
|
2008-04-02 15:36:01 +00:00
|
|
|
namespace OpenSim.Data.MySQL
|
2007-07-16 15:40:11 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// A MySQL interface for the inventory server
|
|
|
|
/// </summary>
|
2007-10-08 10:30:15 +00:00
|
|
|
public class MySQLInventoryData : IInventoryData
|
2007-07-16 15:40:11 +00:00
|
|
|
{
|
2008-02-12 22:24:12 +00:00
|
|
|
private static readonly log4net.ILog m_log
|
|
|
|
= log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
2008-02-05 19:44:27 +00:00
|
|
|
|
2007-07-16 15:40:11 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The database manager
|
|
|
|
/// </summary>
|
2007-10-08 10:30:15 +00:00
|
|
|
private MySQLManager database;
|
2007-07-16 15:40:11 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Loads and initialises this database plugin
|
|
|
|
/// </summary>
|
|
|
|
public void Initialise()
|
|
|
|
{
|
|
|
|
IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini");
|
|
|
|
string settingHostname = GridDataMySqlFile.ParseFileReadValue("hostname");
|
|
|
|
string settingDatabase = GridDataMySqlFile.ParseFileReadValue("database");
|
|
|
|
string settingUsername = GridDataMySqlFile.ParseFileReadValue("username");
|
|
|
|
string settingPassword = GridDataMySqlFile.ParseFileReadValue("password");
|
|
|
|
string settingPooling = GridDataMySqlFile.ParseFileReadValue("pooling");
|
|
|
|
string settingPort = GridDataMySqlFile.ParseFileReadValue("port");
|
|
|
|
|
2007-10-30 09:05:31 +00:00
|
|
|
database =
|
|
|
|
new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword, settingPooling,
|
|
|
|
settingPort);
|
2007-12-10 22:12:52 +00:00
|
|
|
TestTables(database.Connection);
|
2007-07-16 15:40:11 +00:00
|
|
|
}
|
2007-10-08 10:30:15 +00:00
|
|
|
|
|
|
|
#region Test and initialization code
|
|
|
|
|
2007-10-13 07:26:21 +00:00
|
|
|
private void UpgradeFoldersTable(string oldVersion)
|
2007-10-08 10:30:15 +00:00
|
|
|
{
|
|
|
|
// null as the version, indicates that the table didn't exist
|
|
|
|
if (oldVersion == null)
|
|
|
|
{
|
2007-10-13 07:26:21 +00:00
|
|
|
database.ExecuteResourceSql("CreateFoldersTable.sql");
|
2007-10-08 10:30:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the table is already at the current version, then we can exit immediately
|
2007-12-10 22:12:52 +00:00
|
|
|
// if (oldVersion == "Rev. 2")
|
|
|
|
// return;
|
2007-10-08 10:30:15 +00:00
|
|
|
|
2007-12-10 22:12:52 +00:00
|
|
|
// database.ExecuteResourceSql("UpgradeFoldersTableToVersion2.sql");
|
2007-10-08 10:30:15 +00:00
|
|
|
}
|
|
|
|
|
2007-10-13 07:26:21 +00:00
|
|
|
private void UpgradeItemsTable(string oldVersion)
|
2007-10-08 10:30:15 +00:00
|
|
|
{
|
|
|
|
// null as the version, indicates that the table didn't exist
|
|
|
|
if (oldVersion == null)
|
|
|
|
{
|
2007-10-13 07:26:21 +00:00
|
|
|
database.ExecuteResourceSql("CreateItemsTable.sql");
|
2007-10-08 10:30:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the table is already at the current version, then we can exit immediately
|
2007-12-10 22:12:52 +00:00
|
|
|
// if (oldVersion == "Rev. 2")
|
|
|
|
// return;
|
2007-10-08 10:30:15 +00:00
|
|
|
|
2007-12-10 22:12:52 +00:00
|
|
|
// database.ExecuteResourceSql("UpgradeItemsTableToVersion2.sql");
|
2007-10-08 10:30:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void TestTables(MySqlConnection conn)
|
|
|
|
{
|
|
|
|
Dictionary<string, string> tableList = new Dictionary<string, string>();
|
|
|
|
|
|
|
|
tableList["inventoryfolders"] = null;
|
|
|
|
tableList["inventoryitems"] = null;
|
|
|
|
|
2007-10-13 07:26:21 +00:00
|
|
|
database.GetTableVersion(tableList);
|
2008-02-05 19:44:27 +00:00
|
|
|
m_log.Info("[MYSQL]: Inventory Folder Version: " + tableList["inventoryfolders"]);
|
|
|
|
m_log.Info("[MYSQL]: Inventory Items Version: " + tableList["inventoryitems"]);
|
2007-10-08 10:30:15 +00:00
|
|
|
|
2007-10-13 07:26:21 +00:00
|
|
|
UpgradeFoldersTable(tableList["inventoryfolders"]);
|
|
|
|
UpgradeItemsTable(tableList["inventoryitems"]);
|
2007-10-08 10:30:15 +00:00
|
|
|
}
|
2007-10-30 09:05:31 +00:00
|
|
|
|
2007-10-08 10:30:15 +00:00
|
|
|
#endregion
|
|
|
|
|
2007-07-16 15:40:11 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The name of this DB provider
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>Name of DB provider</returns>
|
|
|
|
public string getName()
|
|
|
|
{
|
|
|
|
return "MySQL Inventory Data Interface";
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Closes this DB provider
|
|
|
|
/// </summary>
|
|
|
|
public void Close()
|
|
|
|
{
|
|
|
|
// Do nothing.
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns the version of this DB provider
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>A string containing the DB provider</returns>
|
|
|
|
public string getVersion()
|
|
|
|
{
|
2007-10-13 07:26:21 +00:00
|
|
|
return database.getVersion();
|
2007-07-16 15:40:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a list of items in a specified folder
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="folderID">The folder to search</param>
|
|
|
|
/// <returns>A list containing inventory items</returns>
|
|
|
|
public List<InventoryItemBase> getInventoryInFolder(LLUUID folderID)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
lock (database)
|
|
|
|
{
|
2007-10-08 10:30:15 +00:00
|
|
|
List<InventoryItemBase> items = new List<InventoryItemBase>();
|
2007-07-16 15:40:11 +00:00
|
|
|
|
2007-10-30 09:05:31 +00:00
|
|
|
MySqlCommand result =
|
|
|
|
new MySqlCommand("SELECT * FROM inventoryitems WHERE parentFolderID = ?uuid",
|
|
|
|
database.Connection);
|
2007-12-20 05:43:02 +00:00
|
|
|
result.Parameters.AddWithValue("?uuid", folderID.ToString());
|
2007-10-08 10:30:15 +00:00
|
|
|
MySqlDataReader reader = result.ExecuteReader();
|
2007-07-16 15:40:11 +00:00
|
|
|
|
2007-10-30 09:05:31 +00:00
|
|
|
while (reader.Read())
|
2007-10-08 10:30:15 +00:00
|
|
|
items.Add(readInventoryItem(reader));
|
2007-07-16 15:40:11 +00:00
|
|
|
|
|
|
|
reader.Close();
|
|
|
|
result.Dispose();
|
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
database.Reconnect();
|
2008-02-05 19:44:27 +00:00
|
|
|
m_log.Error(e.ToString());
|
2007-07-16 15:40:11 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a list of the root folders within a users inventory
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="user">The user whos inventory is to be searched</param>
|
|
|
|
/// <returns>A list of folder objects</returns>
|
|
|
|
public List<InventoryFolderBase> getUserRootFolders(LLUUID user)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
lock (database)
|
|
|
|
{
|
2007-10-30 09:05:31 +00:00
|
|
|
MySqlCommand result =
|
|
|
|
new MySqlCommand(
|
|
|
|
"SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid",
|
|
|
|
database.Connection);
|
2007-12-20 05:43:02 +00:00
|
|
|
result.Parameters.AddWithValue("?uuid", user.ToString());
|
|
|
|
result.Parameters.AddWithValue("?zero", LLUUID.Zero.ToString());
|
2007-10-08 10:30:15 +00:00
|
|
|
MySqlDataReader reader = result.ExecuteReader();
|
2007-07-16 15:40:11 +00:00
|
|
|
|
2007-10-08 10:30:15 +00:00
|
|
|
List<InventoryFolderBase> items = new List<InventoryFolderBase>();
|
2007-10-30 09:05:31 +00:00
|
|
|
while (reader.Read())
|
2007-10-08 10:30:15 +00:00
|
|
|
items.Add(readInventoryFolder(reader));
|
2007-07-16 15:40:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
reader.Close();
|
|
|
|
result.Dispose();
|
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
database.Reconnect();
|
2008-02-05 19:44:27 +00:00
|
|
|
m_log.Error(e.ToString());
|
2007-07-16 15:40:11 +00:00
|
|
|
return null;
|
2007-07-22 11:44:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-08 14:27:12 +00:00
|
|
|
// see InventoryItemBase.getUserRootFolder
|
2007-09-27 14:57:43 +00:00
|
|
|
public InventoryFolderBase getUserRootFolder(LLUUID user)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
lock (database)
|
|
|
|
{
|
2007-10-30 09:05:31 +00:00
|
|
|
MySqlCommand result =
|
|
|
|
new MySqlCommand(
|
|
|
|
"SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid",
|
|
|
|
database.Connection);
|
2007-12-20 05:43:02 +00:00
|
|
|
result.Parameters.AddWithValue("?uuid", user.ToString());
|
|
|
|
result.Parameters.AddWithValue("?zero", LLUUID.Zero.ToString());
|
2007-10-08 10:30:15 +00:00
|
|
|
|
|
|
|
MySqlDataReader reader = result.ExecuteReader();
|
|
|
|
|
|
|
|
List<InventoryFolderBase> items = new List<InventoryFolderBase>();
|
2007-10-30 09:05:31 +00:00
|
|
|
while (reader.Read())
|
2007-10-08 10:30:15 +00:00
|
|
|
items.Add(readInventoryFolder(reader));
|
2007-12-27 21:41:48 +00:00
|
|
|
|
2007-12-08 14:27:12 +00:00
|
|
|
InventoryFolderBase rootFolder = null;
|
|
|
|
|
|
|
|
// There should only ever be one root folder for a user. However, if there's more
|
|
|
|
// than one we'll simply use the first one rather than failing. It would be even
|
|
|
|
// nicer to print some message to this effect, but this feels like it's too low a
|
|
|
|
// to put such a message out, and it's too minor right now to spare the time to
|
|
|
|
// suitably refactor.
|
|
|
|
if (items.Count > 0)
|
|
|
|
{
|
|
|
|
rootFolder = items[0];
|
|
|
|
}
|
2007-09-27 14:57:43 +00:00
|
|
|
|
|
|
|
reader.Close();
|
|
|
|
result.Dispose();
|
|
|
|
|
|
|
|
return rootFolder;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
database.Reconnect();
|
2008-02-05 19:44:27 +00:00
|
|
|
m_log.Error(e.ToString());
|
2007-09-27 14:57:43 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-16 15:40:11 +00:00
|
|
|
/// <summary>
|
2007-12-08 14:27:12 +00:00
|
|
|
/// Return a list of folders in a users inventory contained within the specified folder.
|
|
|
|
/// This method is only used in tests - in normal operation the user always have one,
|
|
|
|
/// and only one, root folder.
|
2007-07-16 15:40:11 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="parentID">The folder to search</param>
|
|
|
|
/// <returns>A list of inventory folders</returns>
|
|
|
|
public List<InventoryFolderBase> getInventoryFolders(LLUUID parentID)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
lock (database)
|
|
|
|
{
|
2007-10-30 09:05:31 +00:00
|
|
|
MySqlCommand result =
|
|
|
|
new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?uuid",
|
|
|
|
database.Connection);
|
2007-12-20 05:43:02 +00:00
|
|
|
result.Parameters.AddWithValue("?uuid", parentID.ToString());
|
2007-10-08 10:30:15 +00:00
|
|
|
MySqlDataReader reader = result.ExecuteReader();
|
2007-07-16 15:40:11 +00:00
|
|
|
|
2007-10-08 10:30:15 +00:00
|
|
|
List<InventoryFolderBase> items = new List<InventoryFolderBase>();
|
2007-10-30 09:05:31 +00:00
|
|
|
|
|
|
|
while (reader.Read())
|
2007-10-08 10:30:15 +00:00
|
|
|
items.Add(readInventoryFolder(reader));
|
2007-07-16 15:40:11 +00:00
|
|
|
|
|
|
|
reader.Close();
|
|
|
|
result.Dispose();
|
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
database.Reconnect();
|
2008-02-05 19:44:27 +00:00
|
|
|
m_log.Error(e.ToString());
|
2007-07-16 15:40:11 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-08 10:30:15 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Reads a one item from an SQL result
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="reader">The SQL Result</param>
|
|
|
|
/// <returns>the item read</returns>
|
2007-12-23 02:14:29 +00:00
|
|
|
private InventoryItemBase readInventoryItem(MySqlDataReader reader)
|
2007-10-08 10:30:15 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
InventoryItemBase item = new InventoryItemBase();
|
|
|
|
|
2008-04-07 23:15:35 +00:00
|
|
|
item.ID = new LLUUID((string) reader["inventoryID"]);
|
|
|
|
item.AssetID = new LLUUID((string) reader["assetID"]);
|
|
|
|
item.AssetType = (int) reader["assetType"];
|
|
|
|
item.Folder = new LLUUID((string) reader["parentFolderID"]);
|
|
|
|
item.Owner = new LLUUID((string) reader["avatarID"]);
|
|
|
|
item.Name = (string) reader["inventoryName"];
|
|
|
|
item.Description = (string) reader["inventoryDescription"];
|
|
|
|
item.NextPermissions = (uint) reader["inventoryNextPermissions"];
|
|
|
|
item.CurrentPermissions = (uint) reader["inventoryCurrentPermissions"];
|
|
|
|
item.InvType = (int) reader["invType"];
|
|
|
|
item.Creator = new LLUUID((string) reader["creatorID"]);
|
|
|
|
item.BasePermissions = (uint) reader["inventoryBasePermissions"];
|
|
|
|
item.EveryOnePermissions = (uint) reader["inventoryEveryOnePermissions"];
|
2007-10-08 10:30:15 +00:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
catch (MySqlException e)
|
|
|
|
{
|
2008-02-05 19:44:27 +00:00
|
|
|
m_log.Error(e.ToString());
|
2007-10-08 10:30:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2007-07-16 15:40:11 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Returns a specified inventory item
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="item">The item to return</param>
|
|
|
|
/// <returns>An inventory item</returns>
|
2007-10-08 10:30:15 +00:00
|
|
|
public InventoryItemBase getInventoryItem(LLUUID itemID)
|
2007-07-16 15:40:11 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
lock (database)
|
|
|
|
{
|
|
|
|
Dictionary<string, string> param = new Dictionary<string, string>();
|
|
|
|
|
2007-10-30 09:05:31 +00:00
|
|
|
MySqlCommand result =
|
|
|
|
new MySqlCommand("SELECT * FROM inventoryitems WHERE inventoryID = ?uuid", database.Connection);
|
2007-12-20 05:43:02 +00:00
|
|
|
result.Parameters.AddWithValue("?uuid", itemID.ToString());
|
2007-10-08 10:30:15 +00:00
|
|
|
MySqlDataReader reader = result.ExecuteReader();
|
2007-07-16 15:40:11 +00:00
|
|
|
|
2007-10-08 10:30:15 +00:00
|
|
|
InventoryItemBase item = null;
|
2007-10-30 09:05:31 +00:00
|
|
|
if (reader.Read())
|
2007-10-08 10:30:15 +00:00
|
|
|
item = readInventoryItem(reader);
|
2007-07-16 15:40:11 +00:00
|
|
|
|
|
|
|
reader.Close();
|
|
|
|
result.Dispose();
|
|
|
|
|
2007-10-08 10:30:15 +00:00
|
|
|
return item;
|
2007-07-16 15:40:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
database.Reconnect();
|
2008-02-05 19:44:27 +00:00
|
|
|
m_log.Error(e.ToString());
|
2007-07-16 15:40:11 +00:00
|
|
|
}
|
2007-10-08 10:30:15 +00:00
|
|
|
return null;
|
2007-07-16 15:40:11 +00:00
|
|
|
}
|
|
|
|
|
2007-10-08 10:30:15 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Reads a list of inventory folders returned by a query.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="reader">A MySQL Data Reader</param>
|
|
|
|
/// <returns>A List containing inventory folders</returns>
|
|
|
|
protected InventoryFolderBase readInventoryFolder(MySqlDataReader reader)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
InventoryFolderBase folder = new InventoryFolderBase();
|
2008-04-08 23:26:31 +00:00
|
|
|
folder.Owner = new LLUUID((string) reader["agentID"]);
|
2008-04-07 23:27:05 +00:00
|
|
|
folder.ParentID = new LLUUID((string) reader["parentFolderID"]);
|
|
|
|
folder.ID = new LLUUID((string) reader["folderID"]);
|
|
|
|
folder.Name = (string) reader["folderName"];
|
|
|
|
folder.Type = (short) reader["type"];
|
|
|
|
folder.Version = (ushort) ((int) reader["version"]);
|
2007-10-08 10:30:15 +00:00
|
|
|
return folder;
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2008-02-05 19:44:27 +00:00
|
|
|
m_log.Error(e.ToString());
|
2007-10-08 10:30:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-16 15:40:11 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Returns a specified inventory folder
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="folder">The folder to return</param>
|
|
|
|
/// <returns>A folder class</returns>
|
2007-10-08 10:30:15 +00:00
|
|
|
public InventoryFolderBase getInventoryFolder(LLUUID folderID)
|
2007-07-16 15:40:11 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
lock (database)
|
|
|
|
{
|
2007-10-30 09:05:31 +00:00
|
|
|
MySqlCommand result =
|
|
|
|
new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", database.Connection);
|
2007-12-20 05:43:02 +00:00
|
|
|
result.Parameters.AddWithValue("?uuid", folderID.ToString());
|
2007-10-08 10:30:15 +00:00
|
|
|
MySqlDataReader reader = result.ExecuteReader();
|
2007-07-16 15:40:11 +00:00
|
|
|
|
2007-10-08 10:30:15 +00:00
|
|
|
reader.Read();
|
|
|
|
InventoryFolderBase folder = readInventoryFolder(reader);
|
2007-07-16 15:40:11 +00:00
|
|
|
reader.Close();
|
|
|
|
result.Dispose();
|
|
|
|
|
2007-10-08 10:30:15 +00:00
|
|
|
return folder;
|
2007-07-16 15:40:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
database.Reconnect();
|
2008-02-05 19:44:27 +00:00
|
|
|
m_log.Error(e.ToString());
|
2007-07-16 15:40:11 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Adds a specified item to the database
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="item">The inventory item</param>
|
|
|
|
public void addInventoryItem(InventoryItemBase item)
|
|
|
|
{
|
2007-10-30 09:05:31 +00:00
|
|
|
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)";
|
2007-10-08 10:30:15 +00:00
|
|
|
|
|
|
|
try
|
2007-07-16 15:40:11 +00:00
|
|
|
{
|
2007-10-08 10:30:15 +00:00
|
|
|
MySqlCommand result = new MySqlCommand(sql, database.Connection);
|
2008-04-07 23:15:35 +00:00
|
|
|
result.Parameters.AddWithValue("?inventoryID", item.ID.ToString());
|
|
|
|
result.Parameters.AddWithValue("?assetID", item.AssetID.ToString());
|
|
|
|
result.Parameters.AddWithValue("?assetType", item.AssetType.ToString());
|
|
|
|
result.Parameters.AddWithValue("?parentFolderID", item.Folder.ToString());
|
|
|
|
result.Parameters.AddWithValue("?avatarID", item.Owner.ToString());
|
|
|
|
result.Parameters.AddWithValue("?inventoryName", item.Name);
|
|
|
|
result.Parameters.AddWithValue("?inventoryDescription", item.Description);
|
|
|
|
result.Parameters.AddWithValue("?inventoryNextPermissions", item.NextPermissions.ToString());
|
2007-10-30 09:05:31 +00:00
|
|
|
result.Parameters.AddWithValue("?inventoryCurrentPermissions",
|
2008-04-07 23:15:35 +00:00
|
|
|
item.CurrentPermissions.ToString());
|
|
|
|
result.Parameters.AddWithValue("?invType", item.InvType);
|
|
|
|
result.Parameters.AddWithValue("?creatorID", item.Creator.ToString());
|
|
|
|
result.Parameters.AddWithValue("?inventoryBasePermissions", item.BasePermissions);
|
|
|
|
result.Parameters.AddWithValue("?inventoryEveryOnePermissions", item.EveryOnePermissions);
|
2007-10-08 10:30:15 +00:00
|
|
|
result.ExecuteNonQuery();
|
|
|
|
result.Dispose();
|
|
|
|
}
|
|
|
|
catch (MySqlException e)
|
|
|
|
{
|
2008-02-05 19:44:27 +00:00
|
|
|
m_log.Error(e.ToString());
|
2007-07-16 15:40:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Updates the specified inventory item
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="item">Inventory item to update</param>
|
|
|
|
public void updateInventoryItem(InventoryItemBase item)
|
|
|
|
{
|
|
|
|
addInventoryItem(item);
|
|
|
|
}
|
|
|
|
|
2007-08-16 16:31:32 +00:00
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="item"></param>
|
2007-10-08 10:30:15 +00:00
|
|
|
public void deleteInventoryItem(LLUUID itemID)
|
2007-08-16 16:31:32 +00:00
|
|
|
{
|
2007-10-08 10:30:15 +00:00
|
|
|
try
|
|
|
|
{
|
2007-10-30 09:05:31 +00:00
|
|
|
MySqlCommand cmd =
|
|
|
|
new MySqlCommand("DELETE FROM inventoryitems WHERE inventoryID=?uuid", database.Connection);
|
2007-12-20 05:43:02 +00:00
|
|
|
cmd.Parameters.AddWithValue("?uuid", itemID.ToString());
|
2007-10-08 10:30:15 +00:00
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
}
|
|
|
|
catch (MySqlException e)
|
|
|
|
{
|
|
|
|
database.Reconnect();
|
2008-02-05 19:44:27 +00:00
|
|
|
m_log.Error(e.ToString());
|
2007-10-08 10:30:15 +00:00
|
|
|
}
|
2007-08-16 16:31:32 +00:00
|
|
|
}
|
|
|
|
|
2007-07-16 15:40:11 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Creates a new inventory folder
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="folder">Folder to create</param>
|
|
|
|
public void addInventoryFolder(InventoryFolderBase folder)
|
|
|
|
{
|
2007-10-30 09:05:31 +00:00
|
|
|
string sql =
|
|
|
|
"REPLACE INTO inventoryfolders (folderID, agentID, parentFolderID, folderName, type, version) VALUES ";
|
2007-10-08 10:30:15 +00:00
|
|
|
sql += "(?folderID, ?agentID, ?parentFolderID, ?folderName, ?type, ?version)";
|
|
|
|
|
|
|
|
MySqlCommand cmd = new MySqlCommand(sql, database.Connection);
|
2008-04-07 23:27:05 +00:00
|
|
|
cmd.Parameters.AddWithValue("?folderID", folder.ID.ToString());
|
2008-04-08 23:26:31 +00:00
|
|
|
cmd.Parameters.AddWithValue("?agentID", folder.Owner.ToString());
|
2008-04-07 23:27:05 +00:00
|
|
|
cmd.Parameters.AddWithValue("?parentFolderID", folder.ParentID.ToString());
|
|
|
|
cmd.Parameters.AddWithValue("?folderName", folder.Name);
|
|
|
|
cmd.Parameters.AddWithValue("?type", (short) folder.Type);
|
|
|
|
cmd.Parameters.AddWithValue("?version", folder.Version);
|
2007-10-30 09:05:31 +00:00
|
|
|
|
2007-10-08 10:30:15 +00:00
|
|
|
try
|
|
|
|
{
|
2008-02-12 22:24:12 +00:00
|
|
|
lock (database)
|
|
|
|
{
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
}
|
2007-10-08 10:30:15 +00:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
2007-07-16 15:40:11 +00:00
|
|
|
{
|
2008-02-05 19:44:27 +00:00
|
|
|
m_log.Error(e.ToString());
|
2007-07-16 15:40:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Updates an inventory folder
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="folder">Folder to update</param>
|
|
|
|
public void updateInventoryFolder(InventoryFolderBase folder)
|
|
|
|
{
|
|
|
|
addInventoryFolder(folder);
|
|
|
|
}
|
2007-10-06 08:23:51 +00:00
|
|
|
|
2007-12-15 04:57:14 +00:00
|
|
|
/// Creates a new inventory folder
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="folder">Folder to create</param>
|
|
|
|
public void moveInventoryFolder(InventoryFolderBase folder)
|
|
|
|
{
|
|
|
|
string sql =
|
|
|
|
"UPDATE inventoryfolders SET parentFolderID=?parentFolderID WHERE folderID=?folderID";
|
|
|
|
|
|
|
|
MySqlCommand cmd = new MySqlCommand(sql, database.Connection);
|
2008-04-07 23:27:05 +00:00
|
|
|
cmd.Parameters.AddWithValue("?folderID", folder.ID.ToString());
|
|
|
|
cmd.Parameters.AddWithValue("?parentFolderID", folder.ParentID.ToString());
|
2007-12-15 04:57:14 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2008-02-12 22:24:12 +00:00
|
|
|
lock (database)
|
|
|
|
{
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
}
|
2007-12-15 04:57:14 +00:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2008-02-05 19:44:27 +00:00
|
|
|
m_log.Error(e.ToString());
|
2007-12-15 04:57:14 +00:00
|
|
|
}
|
|
|
|
}
|
2007-10-06 08:23:51 +00:00
|
|
|
|
2007-10-08 10:30:15 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Append a list of all the child folders of a parent folder
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="folders">list where folders will be appended</param>
|
|
|
|
/// <param name="parentID">ID of parent</param>
|
|
|
|
protected void getInventoryFolders(ref List<InventoryFolderBase> folders, LLUUID parentID)
|
|
|
|
{
|
|
|
|
List<InventoryFolderBase> subfolderList = getInventoryFolders(parentID);
|
|
|
|
|
|
|
|
foreach (InventoryFolderBase f in subfolderList)
|
|
|
|
folders.Add(f);
|
|
|
|
}
|
2007-10-30 09:05:31 +00:00
|
|
|
|
2008-03-28 19:35:01 +00:00
|
|
|
// See IInventoryData
|
|
|
|
public List<InventoryFolderBase> getFolderHierarchy(LLUUID parentID)
|
2007-10-08 10:30:15 +00:00
|
|
|
{
|
|
|
|
List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
|
|
|
|
getInventoryFolders(ref folders, parentID);
|
|
|
|
|
|
|
|
for (int i = 0; i < folders.Count; i++)
|
2008-04-07 23:27:05 +00:00
|
|
|
getInventoryFolders(ref folders, folders[i].ID);
|
2007-10-08 10:30:15 +00:00
|
|
|
|
|
|
|
return folders;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void deleteOneFolder(LLUUID folderID)
|
|
|
|
{
|
|
|
|
try
|
2008-02-12 22:24:12 +00:00
|
|
|
{
|
2007-10-30 09:05:31 +00:00
|
|
|
MySqlCommand cmd =
|
|
|
|
new MySqlCommand("DELETE FROM inventoryfolders WHERE folderID=?uuid", database.Connection);
|
2007-12-20 05:43:02 +00:00
|
|
|
cmd.Parameters.AddWithValue("?uuid", folderID.ToString());
|
2008-02-12 22:24:12 +00:00
|
|
|
|
|
|
|
lock (database)
|
|
|
|
{
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
}
|
2007-10-08 10:30:15 +00:00
|
|
|
}
|
|
|
|
catch (MySqlException e)
|
|
|
|
{
|
|
|
|
database.Reconnect();
|
2008-02-05 19:44:27 +00:00
|
|
|
m_log.Error(e.ToString());
|
2007-10-08 10:30:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void deleteItemsInFolder(LLUUID folderID)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2007-10-30 09:05:31 +00:00
|
|
|
MySqlCommand cmd =
|
|
|
|
new MySqlCommand("DELETE FROM inventoryitems WHERE parentFolderID=?uuid", database.Connection);
|
2007-12-20 05:43:02 +00:00
|
|
|
cmd.Parameters.AddWithValue("?uuid", folderID.ToString());
|
2008-02-12 22:24:12 +00:00
|
|
|
|
|
|
|
lock (database)
|
|
|
|
{
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
}
|
2007-10-08 10:30:15 +00:00
|
|
|
}
|
|
|
|
catch (MySqlException e)
|
|
|
|
{
|
|
|
|
database.Reconnect();
|
2008-02-05 19:44:27 +00:00
|
|
|
m_log.Error(e.ToString());
|
2007-10-08 10:30:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-06 08:23:51 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Delete an inventory folder
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="folderId">Id of folder to delete</param>
|
|
|
|
public void deleteInventoryFolder(LLUUID folderID)
|
|
|
|
{
|
2008-02-12 22:24:12 +00:00
|
|
|
List<InventoryFolderBase> subFolders = getFolderHierarchy(folderID);
|
2007-10-08 10:30:15 +00:00
|
|
|
|
2008-02-12 22:24:12 +00:00
|
|
|
//Delete all sub-folders
|
|
|
|
foreach (InventoryFolderBase f in subFolders)
|
|
|
|
{
|
2008-04-07 23:27:05 +00:00
|
|
|
deleteOneFolder(f.ID);
|
|
|
|
deleteItemsInFolder(f.ID);
|
2007-10-08 10:30:15 +00:00
|
|
|
}
|
2008-02-12 22:24:12 +00:00
|
|
|
|
|
|
|
//Delete the actual row
|
|
|
|
deleteOneFolder(folderID);
|
|
|
|
deleteItemsInFolder(folderID);
|
2007-10-06 08:23:51 +00:00
|
|
|
}
|
2007-07-16 15:40:11 +00:00
|
|
|
}
|
2008-03-18 05:16:43 +00:00
|
|
|
}
|