SQLiteLocalStorage.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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. */
  28. // SQLite Support
  29. // A bad idea, but the IRC people told me to!
  30. using System;
  31. using System.Data;
  32. using System.Data.SQLite;
  33. using libsecondlife;
  34. using OpenSim.Framework.Console;
  35. using OpenSim.Framework.Interfaces;
  36. using OpenSim.Framework.Types;
  37. namespace OpenSim.Region.Storage.LocalStorageSQLite
  38. {
  39. public class SQLiteLocalStorage : ILocalStorage
  40. {
  41. IDbConnection db;
  42. public SQLiteLocalStorage()
  43. {
  44. try
  45. {
  46. string connectionstring = "URI=file:localsim.sdb";
  47. db = (IDbConnection)new SQLiteConnection(connectionstring);
  48. db.Open();
  49. }
  50. catch (Exception e)
  51. {
  52. db.Close();
  53. MainLog.Instance.Warn("SQLiteLocalStorage :Constructor - Exception occured");
  54. MainLog.Instance.Warn(e.ToString());
  55. }
  56. }
  57. public void Initialise(string file)
  58. {
  59. // Blank
  60. }
  61. public void StorePrim(PrimData prim)
  62. {
  63. IDbCommand cmd = db.CreateCommand();
  64. //SECURITY WARNING:
  65. // These parameters wont produce SQL injections since they are all integer based, however.
  66. // if inserting strings such as name or description, you will need to use appropriate
  67. // measures to prevent SQL injection (although the value of SQL injection in this is limited).
  68. string sql = "REPLACE INTO prim (OwnerID,PCode,PathBegin,PathEnd,PathScaleX,PathScaleY,PathShearX,PathShearY,PathSkew,ProfileBegin,ProfileEnd,Scale,PathCurve,ProfileCurve,ParentID,ProfileHollow,PathRadiusOffset,PathRevolutions,PathTaperX,PathTaperY,PathTwist,PathTwistBegin,Texture,CreationDate,OwnerMask,NextOwnerMask,GroupMask,EveryoneMask,BaseMask,Position,Rotation,LocalID,FullID) ";
  69. sql += "VALUES (";
  70. sql += "\"" + prim.OwnerID.ToStringHyphenated() + "\","; // KILL ME NOW!
  71. sql += "\"" + prim.PCode.ToString() + "\",";
  72. sql += "\"" + prim.PathBegin.ToString() + "\",";
  73. sql += "\"" + prim.PathEnd.ToString() + "\",";
  74. sql += "\"" + prim.PathScaleX.ToString() + "\",";
  75. sql += "\"" + prim.PathScaleY.ToString() + "\",";
  76. sql += "\"" + prim.PathShearX.ToString() + "\",";
  77. sql += "\"" + prim.PathShearY.ToString() + "\",";
  78. sql += "\"" + prim.PathSkew.ToString() + "\",";
  79. sql += "\"" + prim.ProfileBegin.ToString() + "\",";
  80. sql += "\"" + prim.ProfileEnd.ToString() + "\",";
  81. sql += "\"" + prim.Scale.ToString() + "\",";
  82. sql += "\"" + prim.PathCurve.ToString() + "\",";
  83. sql += "\"" + prim.ProfileCurve.ToString() + "\",";
  84. sql += "\"" + prim.ParentID.ToString() + "\",";
  85. sql += "\"" + prim.ProfileHollow.ToString() + "\",";
  86. sql += "\"" + prim.PathRadiusOffset.ToString() + "\",";
  87. sql += "\"" + prim.PathRevolutions.ToString() + "\",";
  88. sql += "\"" + prim.PathTaperX.ToString() + "\",";
  89. sql += "\"" + prim.PathTaperY.ToString() + "\",";
  90. sql += "\"" + prim.PathTwist.ToString() + "\",";
  91. sql += "\"" + prim.PathTwistBegin.ToString() + "\",";
  92. sql += "\"" + prim.TextureEntry.ToString() + "\",";
  93. sql += "\"" + prim.CreationDate.ToString() + "\",";
  94. sql += "\"" + prim.OwnerMask.ToString() + "\",";
  95. sql += "\"" + prim.NextOwnerMask.ToString() + "\",";
  96. sql += "\"" + prim.GroupMask.ToString() + "\",";
  97. sql += "\"" + prim.EveryoneMask.ToString() + "\",";
  98. sql += "\"" + prim.BaseMask.ToString() + "\",";
  99. sql += "\"" + prim.Position.ToString() + "\",";
  100. sql += "\"" + prim.Rotation.ToString() + "\",";
  101. sql += "\"" + prim.LocalID.ToString() + "\",";
  102. sql += "\"" + prim.FullID.ToString() + "\")";
  103. cmd.CommandText = sql;
  104. try
  105. {
  106. cmd.ExecuteNonQuery();
  107. }
  108. catch (Exception e)
  109. {
  110. MainLog.Instance.Warn("SQLiteLocalStorage :StorePrim - Exception occured");
  111. MainLog.Instance.Warn(e.ToString());
  112. }
  113. cmd.Dispose();
  114. cmd = null;
  115. }
  116. public void RemovePrim(LLUUID primID)
  117. {
  118. IDbCommand cmd = db.CreateCommand();
  119. //SECURITY WARNING:
  120. // These parameters wont produce SQL injections since they are all integer based, however.
  121. // if inserting strings such as name or description, you will need to use appropriate
  122. // measures to prevent SQL injection (although the value of SQL injection in this is limited).
  123. string sql = "DELETE FROM prim WHERE FullID = \"" + primID.ToStringHyphenated() + "\"";
  124. cmd.CommandText = sql;
  125. try
  126. {
  127. cmd.ExecuteNonQuery();
  128. }
  129. catch (Exception e)
  130. {
  131. MainLog.Instance.Warn("SQLiteLocalStorage :RemovePrim - Exception occured");
  132. MainLog.Instance.Warn(e.ToString());
  133. }
  134. cmd.Dispose();
  135. cmd = null;
  136. }
  137. public void LoadPrimitives(ILocalStorageReceiver receiver)
  138. {
  139. }
  140. public float[] LoadWorld()
  141. {
  142. return new float[65536];
  143. }
  144. public void SaveMap(float[] heightmap)
  145. {
  146. }
  147. public void SaveParcels(ParcelData[] parcel_manager)
  148. {
  149. }
  150. public void SaveParcel(ParcelData parcel)
  151. {
  152. }
  153. public void RemoveParcel(ParcelData parcel)
  154. {
  155. }
  156. public void RemoveAllParcels()
  157. {
  158. }
  159. public void LoadParcels(ILocalStorageParcelReceiver recv)
  160. {
  161. recv.NoParcelDataFromStorage();
  162. }
  163. public void ShutDown()
  164. {
  165. db.Close();
  166. db = null;
  167. }
  168. }
  169. }