29 using System.Collections.Generic;
32 using System.Reflection;
34 using MySql.Data.MySqlClient;
36 using OpenSim.Framework;
38 namespace OpenSim.Data.MySQL
51 conn,
"inventoryfolders",
"InventoryStore");
53 conn,
"inventoryitems", String.Empty);
58 return m_Folders.Get(fields, vals);
63 return m_Items.Get(fields, vals);
69 folder.folderName = folder.folderName.Substring(0, 64);
71 return m_Folders.Store(folder);
77 item.inventoryName = item.inventoryName.Substring(0, 64);
79 item.inventoryDescription = item.inventoryDescription.Substring(0, 128);
81 return m_Items.Store(item);
86 return m_Folders.Delete(field, val);
91 return m_Folders.Delete(fields, vals);
96 return m_Items.Delete(field, val);
101 return m_Items.Delete(fields, vals);
106 return m_Items.MoveItem(id, newParent);
111 return m_Folders.MoveFolder(id, newParent);
116 return m_Items.GetActiveGestures(principalID);
121 return m_Items.GetAssetPermissions(principalID, assetID);
134 public override bool Delete(
string field,
string val)
136 XInventoryItem[] retrievedItems = Get(
new string[] { field },
new string[] { val });
137 if (retrievedItems.Length == 0)
140 if (!base.Delete(field, val))
149 public override bool Delete(
string[] fields,
string[] vals)
152 if (retrievedItems.Length == 0)
155 if (!base.Delete(fields, vals))
158 HashSet<UUID> deletedItemFolderUUIDs =
new HashSet<UUID>();
160 Array.ForEach<
XInventoryItem>(retrievedItems, i => deletedItemFolderUUIDs.Add(i.parentFolderID));
162 foreach (UUID deletedItemFolderUUID
in deletedItemFolderUUIDs)
163 IncrementFolderVersion(deletedItemFolderUUID);
170 XInventoryItem[] retrievedItems = Get(
new string[] {
"inventoryID" },
new string[] {
id });
171 if (retrievedItems.Length == 0)
174 UUID oldParent = retrievedItems[0].parentFolderID;
176 using (MySqlCommand cmd =
new MySqlCommand())
178 cmd.CommandText = String.Format(
"update {0} set parentFolderID = ?ParentFolderID where inventoryID = ?InventoryID", m_Realm);
179 cmd.Parameters.AddWithValue(
"?ParentFolderID", newParent);
180 cmd.Parameters.AddWithValue(
"?InventoryID", id);
182 if (ExecuteNonQuery(cmd) == 0)
186 IncrementFolderVersion(oldParent);
187 IncrementFolderVersion(newParent);
194 using (MySqlCommand cmd =
new MySqlCommand())
196 cmd.CommandText = String.Format(
"select * from inventoryitems where avatarId = ?uuid and assetType = ?type and flags & 1", m_Realm);
198 cmd.Parameters.AddWithValue(
"?uuid", principalID.ToString());
199 cmd.Parameters.AddWithValue(
"?type", (int)AssetType.Gesture);
207 using (MySqlConnection dbcon =
new MySqlConnection(m_connectionString))
211 using (MySqlCommand cmd =
new MySqlCommand())
213 cmd.Connection = dbcon;
215 cmd.CommandText = String.Format(
"select bit_or(inventoryCurrentPermissions) as inventoryCurrentPermissions from inventoryitems where avatarID = ?PrincipalID and assetID = ?AssetID group by assetID", m_Realm);
216 cmd.Parameters.AddWithValue(
"?PrincipalID", principalID.ToString());
217 cmd.Parameters.AddWithValue(
"?AssetID", assetID.ToString());
219 using (IDataReader reader = cmd.ExecuteReader())
226 perms = Convert.ToInt32(reader[
"inventoryCurrentPermissions"]);
237 if (!base.Store(item))
257 XInventoryFolder[] folders = Get(
new string[] {
"folderID" },
new string[] {
id });
259 if (folders.Length == 0)
262 UUID oldParentFolderUUID = folders[0].parentFolderID;
264 using (MySqlCommand cmd =
new MySqlCommand())
268 "update {0} set parentFolderID = ?ParentFolderID where folderID = ?folderID", m_Realm);
269 cmd.Parameters.AddWithValue(
"?ParentFolderID", newParentFolderID);
270 cmd.Parameters.AddWithValue(
"?folderID", id);
272 if (ExecuteNonQuery(cmd) == 0)
276 IncrementFolderVersion(oldParentFolderUUID);
277 IncrementFolderVersion(newParentFolderID);
284 if (!base.Store(folder))
293 public class MySqlInventoryHandler<T> : MySQLGenericTableHandler<T> where T: class, new()
299 return IncrementFolderVersion(folderID.ToString());
307 using (MySqlConnection dbcon =
new MySqlConnection(m_connectionString))
311 using (MySqlCommand cmd =
new MySqlCommand())
313 cmd.Connection = dbcon;
315 cmd.CommandText = String.Format(
"update inventoryfolders set version=version+1 where folderID = ?folderID");
316 cmd.Parameters.AddWithValue(
"?folderID", folderID);
320 cmd.ExecuteNonQuery();
bool StoreItem(XInventoryItem item)
XInventoryItem[] GetItems(string[] fields, string[] vals)
override bool Store(XInventoryFolder folder)
override bool Store(XInventoryItem item)
bool DeleteItems(string field, string val)
Delete items where field == val
bool DeleteFolders(string[] fields, string[] vals)
Delete folders where field1 == val1, field2 == val2...
bool IncrementFolderVersion(UUID folderID)
XInventoryItem[] GetActiveGestures(UUID principalID)
XInventoryItem[] GetActiveGestures(UUID principalID)
bool StoreFolder(XInventoryFolder folder)
MySQLXInventoryData(string conn, string realm)
bool MoveItem(string id, string newParent)
Move an item to another folder.
string inventoryDescription
override bool Delete(string[] fields, string[] vals)
bool IncrementFolderVersion(string folderID)
A MySQL Interface for the Asset Server
int GetAssetPermissions(UUID principalID, UUID assetID)
MySqlFolderHandler(string c, string t, string m)
bool DeleteItems(string[] fields, string[] vals)
Delete items where field1 == val1, field2 == val2...
bool MoveItem(string id, string newParent)
bool MoveFolder(string id, string newParent)
Move a folder to another folder.
override bool Delete(string field, string val)
bool DeleteFolders(string field, string val)
Delete folders where field == val
MySqlItemHandler(string c, string t, string m)
XInventoryFolder[] GetFolders(string[] fields, string[] vals)
MySqlInventoryHandler(string c, string t, string m)
bool MoveFolder(string id, string newParentFolderID)
int GetAssetPermissions(UUID principalID, UUID assetID)