aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.Storage/LocalStorageSQLite/SQLiteLocalStorage.cs
diff options
context:
space:
mode:
authorMW2007-04-11 13:32:50 +0000
committerMW2007-04-11 13:32:50 +0000
commit00b7058e000d7871df2ae40075ead1042e8e81ac (patch)
tree2a7e4d5c51b4567b97a7fc06c1c970e6a4ac9d44 /OpenSim.Storage/LocalStorageSQLite/SQLiteLocalStorage.cs
parentsmall improvement to the jvm and test script (diff)
downloadopensim-SC-00b7058e000d7871df2ae40075ead1042e8e81ac.zip
opensim-SC-00b7058e000d7871df2ae40075ead1042e8e81ac.tar.gz
opensim-SC-00b7058e000d7871df2ae40075ead1042e8e81ac.tar.bz2
opensim-SC-00b7058e000d7871df2ae40075ead1042e8e81ac.tar.xz
Attempt to rearrange some of the directories
Diffstat (limited to 'OpenSim.Storage/LocalStorageSQLite/SQLiteLocalStorage.cs')
-rw-r--r--OpenSim.Storage/LocalStorageSQLite/SQLiteLocalStorage.cs171
1 files changed, 171 insertions, 0 deletions
diff --git a/OpenSim.Storage/LocalStorageSQLite/SQLiteLocalStorage.cs b/OpenSim.Storage/LocalStorageSQLite/SQLiteLocalStorage.cs
new file mode 100644
index 0000000..8c9a5e1
--- /dev/null
+++ b/OpenSim.Storage/LocalStorageSQLite/SQLiteLocalStorage.cs
@@ -0,0 +1,171 @@
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
28// SQLite Support
29// A bad idea, but the IRC people told me to!
30
31using System;
32using System.Collections.Generic;
33using System.Data;
34using System.Data.SQLite;
35using libsecondlife;
36using OpenSim.Framework.Interfaces;
37using OpenSim.Framework.Assets;
38using OpenSim.Framework.Terrain;
39
40namespace OpenSim.Storage.LocalStorageSQLite
41{
42 public class SQLiteLocalStorage : ILocalStorage
43 {
44 IDbConnection db;
45
46 public SQLiteLocalStorage()
47 {
48 try
49 {
50 string connectionstring = "URI=file:localsim.sdb";
51 db = (IDbConnection)new SQLiteConnection(connectionstring);
52 db.Open();
53 }
54 catch (Exception e)
55 {
56 db.Close();
57 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("SQLiteLocalStorage :Constructor - Exception occured");
58 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(e.ToString());
59 }
60 }
61
62 public void StorePrim(PrimData prim)
63 {
64 IDbCommand cmd = db.CreateCommand();
65
66 //SECURITY WARNING:
67 // These parameters wont produce SQL injections since they are all integer based, however.
68 // if inserting strings such as name or description, you will need to use appropriate
69 // measures to prevent SQL injection (although the value of SQL injection in this is limited).
70
71 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) ";
72 sql += "VALUES (";
73 sql += "\"" + prim.OwnerID.ToStringHyphenated() + "\","; // KILL ME NOW!
74 sql += "\"" + prim.PCode.ToString() + "\",";
75 sql += "\"" + prim.PathBegin.ToString() + "\",";
76 sql += "\"" + prim.PathEnd.ToString() + "\",";
77 sql += "\"" + prim.PathScaleX.ToString() + "\",";
78 sql += "\"" + prim.PathScaleY.ToString() + "\",";
79 sql += "\"" + prim.PathShearX.ToString() + "\",";
80 sql += "\"" + prim.PathShearY.ToString() + "\",";
81 sql += "\"" + prim.PathSkew.ToString() + "\",";
82 sql += "\"" + prim.ProfileBegin.ToString() + "\",";
83 sql += "\"" + prim.ProfileEnd.ToString() + "\",";
84 sql += "\"" + prim.Scale.ToString() + "\",";
85 sql += "\"" + prim.PathCurve.ToString() + "\",";
86 sql += "\"" + prim.ProfileCurve.ToString() + "\",";
87 sql += "\"" + prim.ParentID.ToString() + "\",";
88 sql += "\"" + prim.ProfileHollow.ToString() + "\",";
89 sql += "\"" + prim.PathRadiusOffset.ToString() + "\",";
90 sql += "\"" + prim.PathRevolutions.ToString() + "\",";
91 sql += "\"" + prim.PathTaperX.ToString() + "\",";
92 sql += "\"" + prim.PathTaperY.ToString() + "\",";
93 sql += "\"" + prim.PathTwist.ToString() + "\",";
94 sql += "\"" + prim.PathTwistBegin.ToString() + "\",";
95 sql += "\"" + prim.Texture.ToString() + "\",";
96 sql += "\"" + prim.CreationDate.ToString() + "\",";
97 sql += "\"" + prim.OwnerMask.ToString() + "\",";
98 sql += "\"" + prim.NextOwnerMask.ToString() + "\",";
99 sql += "\"" + prim.GroupMask.ToString() + "\",";
100 sql += "\"" + prim.EveryoneMask.ToString() + "\",";
101 sql += "\"" + prim.BaseMask.ToString() + "\",";
102 sql += "\"" + prim.Position.ToString() + "\",";
103 sql += "\"" + prim.Rotation.ToString() + "\",";
104 sql += "\"" + prim.LocalID.ToString() + "\",";
105 sql += "\"" + prim.FullID.ToString() + "\")";
106
107 cmd.CommandText = sql;
108
109 try
110 {
111 cmd.ExecuteNonQuery();
112 }
113 catch (Exception e)
114 {
115 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("SQLiteLocalStorage :StorePrim - Exception occured");
116 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(e.ToString());
117 }
118
119 cmd.Dispose();
120 cmd = null;
121 }
122
123 public void RemovePrim(LLUUID primID)
124 {
125 IDbCommand cmd = db.CreateCommand();
126
127 //SECURITY WARNING:
128 // These parameters wont produce SQL injections since they are all integer based, however.
129 // if inserting strings such as name or description, you will need to use appropriate
130 // measures to prevent SQL injection (although the value of SQL injection in this is limited).
131
132 string sql = "DELETE FROM prim WHERE FullID = \"" + primID.ToStringHyphenated() + "\"";
133
134 cmd.CommandText = sql;
135
136 try
137 {
138 cmd.ExecuteNonQuery();
139 }
140 catch (Exception e)
141 {
142 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("SQLiteLocalStorage :RemovePrim - Exception occured");
143 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(e.ToString());
144 }
145
146 cmd.Dispose();
147 cmd = null;
148 }
149
150 public void LoadPrimitives(ILocalStorageReceiver receiver)
151 {
152
153 }
154
155 public float[] LoadWorld()
156 {
157 return new float[65536];
158 }
159
160 public void SaveMap(float[] heightmap)
161 {
162
163 }
164
165 public void ShutDown()
166 {
167 db.Close();
168 db = null;
169 }
170 }
171} \ No newline at end of file