SQLiteLocalStorage.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Copyright (c) OpenSim project, http://sim.opensecondlife.org/
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. * * Redistributions of source code must retain the above copyright
  7. * notice, this list of conditions and the following disclaimer.
  8. * * Redistributions in binary form must reproduce the above copyright
  9. * notice, this list of conditions and the following disclaimer in the
  10. * documentation and/or other materials provided with the distribution.
  11. * * Neither the name of the <organization> nor the
  12. * names of its contributors may be used to endorse or promote products
  13. * derived from this software without specific prior written permission.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
  16. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
  19. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. *
  26. */
  27. // SQLite Support
  28. // A bad idea, but the IRC people told me to!
  29. using System;
  30. using System.Collections.Generic;
  31. using System.Data;
  32. using System.Data.SQLite;
  33. using libsecondlife;
  34. using OpenSim.Framework.Interfaces;
  35. using OpenSim.Framework.Types;
  36. using OpenSim.Framework.Terrain;
  37. namespace OpenSim.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. OpenSim.Framework.Console.MainConsole.Instance.WriteLine("SQLiteLocalStorage :Constructor - Exception occured");
  54. OpenSim.Framework.Console.MainConsole.Instance.WriteLine(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.Texture.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. OpenSim.Framework.Console.MainConsole.Instance.WriteLine("SQLiteLocalStorage :StorePrim - Exception occured");
  111. OpenSim.Framework.Console.MainConsole.Instance.WriteLine(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. OpenSim.Framework.Console.MainConsole.Instance.WriteLine("SQLiteLocalStorage :RemovePrim - Exception occured");
  132. OpenSim.Framework.Console.MainConsole.Instance.WriteLine(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 ShutDown()
  148. {
  149. db.Close();
  150. db = null;
  151. }
  152. }
  153. }