SQLiteXInventoryData.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Data;
  29. using System.Reflection;
  30. using System.Collections.Generic;
  31. #if CSharpSqlite
  32. using Community.CsharpSqlite.Sqlite;
  33. #else
  34. using Mono.Data.Sqlite;
  35. #endif
  36. using log4net;
  37. using OpenMetaverse;
  38. using OpenSim.Framework;
  39. namespace OpenSim.Data.SQLite
  40. {
  41. /// <summary>
  42. /// A MySQL Interface for the Asset Server
  43. /// </summary>
  44. public class SQLiteXInventoryData : IXInventoryData
  45. {
  46. // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  47. private SQLiteGenericTableHandler<XInventoryFolder> m_Folders;
  48. private SqliteItemHandler m_Items;
  49. public SQLiteXInventoryData(string conn, string realm)
  50. {
  51. m_Folders = new SQLiteGenericTableHandler<XInventoryFolder>(
  52. conn, "inventoryfolders", "XInventoryStore");
  53. m_Items = new SqliteItemHandler(
  54. conn, "inventoryitems", String.Empty);
  55. }
  56. public XInventoryFolder[] GetFolders(string[] fields, string[] vals)
  57. {
  58. return m_Folders.Get(fields, vals);
  59. }
  60. public XInventoryItem[] GetItems(string[] fields, string[] vals)
  61. {
  62. return m_Items.Get(fields, vals);
  63. }
  64. public bool StoreFolder(XInventoryFolder folder)
  65. {
  66. if (folder.folderName.Length > 64)
  67. folder.folderName = folder.folderName.Substring(0, 64);
  68. return m_Folders.Store(folder);
  69. }
  70. public bool StoreItem(XInventoryItem item)
  71. {
  72. if (item.inventoryName.Length > 64)
  73. item.inventoryName = item.inventoryName.Substring(0, 64);
  74. if (item.inventoryDescription.Length > 128)
  75. item.inventoryDescription = item.inventoryDescription.Substring(0, 128);
  76. return m_Items.Store(item);
  77. }
  78. public bool DeleteFolders(string field, string val)
  79. {
  80. return m_Folders.Delete(field, val);
  81. }
  82. public bool DeleteFolders(string[] fields, string[] vals)
  83. {
  84. return m_Folders.Delete(fields, vals);
  85. }
  86. public bool DeleteItems(string field, string val)
  87. {
  88. return m_Items.Delete(field, val);
  89. }
  90. public bool DeleteItems(string[] fields, string[] vals)
  91. {
  92. return m_Items.Delete(fields, vals);
  93. }
  94. public bool MoveItem(string id, string newParent)
  95. {
  96. return m_Items.MoveItem(id, newParent);
  97. }
  98. public XInventoryItem[] GetActiveGestures(UUID principalID)
  99. {
  100. return m_Items.GetActiveGestures(principalID);
  101. }
  102. public int GetAssetPermissions(UUID principalID, UUID assetID)
  103. {
  104. return m_Items.GetAssetPermissions(principalID, assetID);
  105. }
  106. }
  107. public class SqliteItemHandler : SQLiteGenericTableHandler<XInventoryItem>
  108. {
  109. public SqliteItemHandler(string c, string t, string m) :
  110. base(c, t, m)
  111. {
  112. }
  113. public bool MoveItem(string id, string newParent)
  114. {
  115. SqliteCommand cmd = new SqliteCommand();
  116. cmd.CommandText = String.Format("update {0} set parentFolderID = :ParentFolderID where inventoryID = :InventoryID", m_Realm);
  117. cmd.Parameters.Add(new SqliteParameter(":ParentFolderID", newParent));
  118. cmd.Parameters.Add(new SqliteParameter(":InventoryID", id));
  119. return ExecuteNonQuery(cmd, m_Connection) == 0 ? false : true;
  120. }
  121. public XInventoryItem[] GetActiveGestures(UUID principalID)
  122. {
  123. SqliteCommand cmd = new SqliteCommand();
  124. cmd.CommandText = String.Format("select * from inventoryitems where avatarId = :uuid and assetType = :type and flags = 1", m_Realm);
  125. cmd.Parameters.Add(new SqliteParameter(":uuid", principalID.ToString()));
  126. cmd.Parameters.Add(new SqliteParameter(":type", (int)AssetType.Gesture));
  127. return DoQuery(cmd);
  128. }
  129. public int GetAssetPermissions(UUID principalID, UUID assetID)
  130. {
  131. SqliteCommand cmd = new SqliteCommand();
  132. cmd.CommandText = String.Format("select inventoryCurrentPermissions from inventoryitems where avatarID = :PrincipalID and assetID = :AssetID", m_Realm);
  133. cmd.Parameters.Add(new SqliteParameter(":PrincipalID", principalID.ToString()));
  134. cmd.Parameters.Add(new SqliteParameter(":AssetID", assetID.ToString()));
  135. IDataReader reader = ExecuteReader(cmd, m_Connection);
  136. int perms = 0;
  137. while (reader.Read())
  138. {
  139. perms |= Convert.ToInt32(reader["inventoryCurrentPermissions"]);
  140. }
  141. reader.Close();
  142. //CloseCommand(cmd);
  143. return perms;
  144. }
  145. }
  146. }