aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/SQLite/SQLiteManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/SQLite/SQLiteManager.cs')
-rw-r--r--OpenSim/Data/SQLite/SQLiteManager.cs225
1 files changed, 0 insertions, 225 deletions
diff --git a/OpenSim/Data/SQLite/SQLiteManager.cs b/OpenSim/Data/SQLite/SQLiteManager.cs
deleted file mode 100644
index b6d4a1c..0000000
--- a/OpenSim/Data/SQLite/SQLiteManager.cs
+++ /dev/null
@@ -1,225 +0,0 @@
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
28using System;
29using System.Collections.Generic;
30using System.Data;
31using System.Data.SQLite;
32using System.Reflection;
33using log4net;
34using OpenMetaverse;
35
36namespace OpenSim.Data.SQLite
37{
38 /// <summary>
39 /// SQLite Manager
40 /// </summary>
41 internal class SQLiteManager : SQLiteUtil
42 {
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44
45 private IDbConnection dbcon;
46
47 /// <summary>
48 /// <list type="bullet">
49 /// <item>Initialises and creates a new SQLite connection and maintains it.</item>
50 /// <item>use default URI if connect string is empty.</item>
51 /// </list>
52 /// </summary>
53 /// <param name="connect">connect string</param>
54 public SQLiteManager(string connect)
55 {
56 try
57 {
58 string connectionString = String.Empty;
59 if (connect != String.Empty)
60 {
61 connectionString = connect;
62 }
63 else
64 {
65 m_log.Warn("[SQLITE] grid db not specified, using default");
66 connectionString = "URI=file:GridServerSqlite.db;";
67 }
68
69 dbcon = new SQLiteConnection(connectionString);
70
71 dbcon.Open();
72 }
73 catch (Exception e)
74 {
75 throw new Exception("Error initialising SQLite Database: " + e.ToString());
76 }
77 }
78
79 /// <summary>
80 /// Shuts down the database connection
81 /// </summary>
82 public void Close()
83 {
84 dbcon.Close();
85 dbcon = null;
86 }
87
88 /// <summary>
89 /// Runs a query with protection against SQL Injection by using parameterised input.
90 /// </summary>
91 /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param>
92 /// <param name="parameters">The parameters - index so that @y is indexed as 'y'</param>
93 /// <returns>A SQLite DB Command</returns>
94 public IDbCommand Query(string sql, Dictionary<string, string> parameters)
95 {
96 SQLiteCommand dbcommand = (SQLiteCommand) dbcon.CreateCommand();
97 dbcommand.CommandText = sql;
98 foreach (KeyValuePair<string, string> param in parameters)
99 {
100 SQLiteParameter paramx = new SQLiteParameter(param.Key, param.Value);
101 dbcommand.Parameters.Add(paramx);
102 }
103
104 return (IDbCommand) dbcommand;
105 }
106
107 /// <summary>
108 /// Reads a region row from a database reader
109 /// </summary>
110 /// <param name="reader">An active database reader</param>
111 /// <returns>A region profile</returns>
112 public RegionProfileData getRow(IDataReader reader)
113 {
114 RegionProfileData retval = new RegionProfileData();
115
116 if (reader.Read())
117 {
118 // Region Main
119 retval.regionHandle = (ulong) reader["regionHandle"];
120 retval.regionName = (string) reader["regionName"];
121 retval.UUID = new UUID((string) reader["uuid"]);
122
123 // Secrets
124 retval.regionRecvKey = (string) reader["regionRecvKey"];
125 retval.regionSecret = (string) reader["regionSecret"];
126 retval.regionSendKey = (string) reader["regionSendKey"];
127
128 // Region Server
129 retval.regionDataURI = (string) reader["regionDataURI"];
130 retval.regionOnline = false; // Needs to be pinged before this can be set.
131 retval.serverIP = (string) reader["serverIP"];
132 retval.serverPort = (uint) reader["serverPort"];
133 retval.serverURI = (string) reader["serverURI"];
134
135 // Location
136 retval.regionLocX = (uint) ((int) reader["locX"]);
137 retval.regionLocY = (uint) ((int) reader["locY"]);
138 retval.regionLocZ = (uint) ((int) reader["locZ"]);
139
140 // Neighbours - 0 = No Override
141 retval.regionEastOverrideHandle = (ulong) reader["eastOverrideHandle"];
142 retval.regionWestOverrideHandle = (ulong) reader["westOverrideHandle"];
143 retval.regionSouthOverrideHandle = (ulong) reader["southOverrideHandle"];
144 retval.regionNorthOverrideHandle = (ulong) reader["northOverrideHandle"];
145
146 // Assets
147 retval.regionAssetURI = (string) reader["regionAssetURI"];
148 retval.regionAssetRecvKey = (string) reader["regionAssetRecvKey"];
149 retval.regionAssetSendKey = (string) reader["regionAssetSendKey"];
150
151 // Userserver
152 retval.regionUserURI = (string) reader["regionUserURI"];
153 retval.regionUserRecvKey = (string) reader["regionUserRecvKey"];
154 retval.regionUserSendKey = (string) reader["regionUserSendKey"];
155 }
156 else
157 {
158 throw new Exception("No rows to return");
159 }
160 return retval;
161 }
162
163 /// <summary>
164 /// Inserts a new region into the database
165 /// </summary>
166 /// <param name="profile">The region to insert</param>
167 /// <returns>Success?</returns>
168 public bool insertRow(RegionProfileData profile)
169 {
170 string sql =
171 "REPLACE INTO regions VALUES (regionHandle, regionName, uuid, regionRecvKey, regionSecret, regionSendKey, regionDataURI, ";
172 sql +=
173 "serverIP, serverPort, serverURI, locX, locY, locZ, eastOverrideHandle, westOverrideHandle, southOverrideHandle, northOverrideHandle, regionAssetURI, regionAssetRecvKey, ";
174 sql += "regionAssetSendKey, regionUserURI, regionUserRecvKey, regionUserSendKey) VALUES ";
175
176 sql += "(@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI, ";
177 sql +=
178 "@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle, @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, ";
179 sql += "@regionAssetSendKey, @regionUserURI, @regionUserRecvKey, @regionUserSendKey);";
180
181 Dictionary<string, string> parameters = new Dictionary<string, string>();
182
183 parameters["regionHandle"] = profile.regionHandle.ToString();
184 parameters["regionName"] = profile.regionName;
185 parameters["uuid"] = profile.UUID.ToString();
186 parameters["regionRecvKey"] = profile.regionRecvKey;
187 parameters["regionSendKey"] = profile.regionSendKey;
188 parameters["regionDataURI"] = profile.regionDataURI;
189 parameters["serverIP"] = profile.serverIP;
190 parameters["serverPort"] = profile.serverPort.ToString();
191 parameters["serverURI"] = profile.serverURI;
192 parameters["locX"] = profile.regionLocX.ToString();
193 parameters["locY"] = profile.regionLocY.ToString();
194 parameters["locZ"] = profile.regionLocZ.ToString();
195 parameters["eastOverrideHandle"] = profile.regionEastOverrideHandle.ToString();
196 parameters["westOverrideHandle"] = profile.regionWestOverrideHandle.ToString();
197 parameters["northOverrideHandle"] = profile.regionNorthOverrideHandle.ToString();
198 parameters["southOverrideHandle"] = profile.regionSouthOverrideHandle.ToString();
199 parameters["regionAssetURI"] = profile.regionAssetURI;
200 parameters["regionAssetRecvKey"] = profile.regionAssetRecvKey;
201 parameters["regionAssetSendKey"] = profile.regionAssetSendKey;
202 parameters["regionUserURI"] = profile.regionUserURI;
203 parameters["regionUserRecvKey"] = profile.regionUserRecvKey;
204 parameters["regionUserSendKey"] = profile.regionUserSendKey;
205
206 bool returnval = false;
207
208 try
209 {
210 IDbCommand result = Query(sql, parameters);
211
212 if (result.ExecuteNonQuery() == 1)
213 returnval = true;
214
215 result.Dispose();
216 }
217 catch (Exception)
218 {
219 return false;
220 }
221
222 return returnval;
223 }
224 }
225}