diff options
author | Sean Dague | 2007-07-16 15:40:11 +0000 |
---|---|---|
committer | Sean Dague | 2007-07-16 15:40:11 +0000 |
commit | 2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6 (patch) | |
tree | e3f80ad51736cf17e856547b1bcf956010927434 /OpenSim/Framework/Data.MSSQL/MSSQLManager.cs | |
parent | *Trunk compiles now (diff) | |
download | opensim-SC_OLD-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.zip opensim-SC_OLD-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.tar.gz opensim-SC_OLD-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.tar.bz2 opensim-SC_OLD-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.tar.xz |
changed to native line ending encoding
Diffstat (limited to 'OpenSim/Framework/Data.MSSQL/MSSQLManager.cs')
-rw-r--r-- | OpenSim/Framework/Data.MSSQL/MSSQLManager.cs | 422 |
1 files changed, 211 insertions, 211 deletions
diff --git a/OpenSim/Framework/Data.MSSQL/MSSQLManager.cs b/OpenSim/Framework/Data.MSSQL/MSSQLManager.cs index 49bf31c..26677a5 100644 --- a/OpenSim/Framework/Data.MSSQL/MSSQLManager.cs +++ b/OpenSim/Framework/Data.MSSQL/MSSQLManager.cs | |||
@@ -1,211 +1,211 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | 2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Data; | 30 | using System.Data; |
31 | using System.Data.SqlClient; | 31 | using System.Data.SqlClient; |
32 | using libsecondlife; | 32 | using libsecondlife; |
33 | 33 | ||
34 | namespace OpenSim.Framework.Data.MSSQL | 34 | namespace OpenSim.Framework.Data.MSSQL |
35 | { | 35 | { |
36 | /// <summary> | 36 | /// <summary> |
37 | /// A management class for the MS SQL Storage Engine | 37 | /// A management class for the MS SQL Storage Engine |
38 | /// </summary> | 38 | /// </summary> |
39 | class MSSqlManager | 39 | class MSSqlManager |
40 | { | 40 | { |
41 | /// <summary> | 41 | /// <summary> |
42 | /// The database connection object | 42 | /// The database connection object |
43 | /// </summary> | 43 | /// </summary> |
44 | IDbConnection dbcon; | 44 | IDbConnection dbcon; |
45 | 45 | ||
46 | /// <summary> | 46 | /// <summary> |
47 | /// Initialises and creates a new Sql connection and maintains it. | 47 | /// Initialises and creates a new Sql connection and maintains it. |
48 | /// </summary> | 48 | /// </summary> |
49 | /// <param name="hostname">The Sql server being connected to</param> | 49 | /// <param name="hostname">The Sql server being connected to</param> |
50 | /// <param name="database">The name of the Sql database being used</param> | 50 | /// <param name="database">The name of the Sql database being used</param> |
51 | /// <param name="username">The username logging into the database</param> | 51 | /// <param name="username">The username logging into the database</param> |
52 | /// <param name="password">The password for the user logging in</param> | 52 | /// <param name="password">The password for the user logging in</param> |
53 | /// <param name="cpooling">Whether to use connection pooling or not, can be one of the following: 'yes', 'true', 'no' or 'false', if unsure use 'false'.</param> | 53 | /// <param name="cpooling">Whether to use connection pooling or not, can be one of the following: 'yes', 'true', 'no' or 'false', if unsure use 'false'.</param> |
54 | public MSSqlManager(string hostname, string database, string username, string password, string cpooling) | 54 | public MSSqlManager(string hostname, string database, string username, string password, string cpooling) |
55 | { | 55 | { |
56 | try | 56 | try |
57 | { | 57 | { |
58 | string connectionString = "Server=" + hostname + ";Database=" + database + ";User ID=" + username + ";Password=" + password + ";Pooling=" + cpooling + ";"; | 58 | string connectionString = "Server=" + hostname + ";Database=" + database + ";User ID=" + username + ";Password=" + password + ";Pooling=" + cpooling + ";"; |
59 | dbcon = new SqlConnection(connectionString); | 59 | dbcon = new SqlConnection(connectionString); |
60 | 60 | ||
61 | dbcon.Open(); | 61 | dbcon.Open(); |
62 | } | 62 | } |
63 | catch (Exception e) | 63 | catch (Exception e) |
64 | { | 64 | { |
65 | throw new Exception("Error initialising Sql Database: " + e.ToString()); | 65 | throw new Exception("Error initialising Sql Database: " + e.ToString()); |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | /// <summary> | 69 | /// <summary> |
70 | /// Shuts down the database connection | 70 | /// Shuts down the database connection |
71 | /// </summary> | 71 | /// </summary> |
72 | public void Close() | 72 | public void Close() |
73 | { | 73 | { |
74 | dbcon.Close(); | 74 | dbcon.Close(); |
75 | dbcon = null; | 75 | dbcon = null; |
76 | } | 76 | } |
77 | 77 | ||
78 | /// <summary> | 78 | /// <summary> |
79 | /// Runs a query with protection against SQL Injection by using parameterised input. | 79 | /// Runs a query with protection against SQL Injection by using parameterised input. |
80 | /// </summary> | 80 | /// </summary> |
81 | /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param> | 81 | /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param> |
82 | /// <param name="parameters">The parameters - index so that @y is indexed as 'y'</param> | 82 | /// <param name="parameters">The parameters - index so that @y is indexed as 'y'</param> |
83 | /// <returns>A Sql DB Command</returns> | 83 | /// <returns>A Sql DB Command</returns> |
84 | public IDbCommand Query(string sql, Dictionary<string, string> parameters) | 84 | public IDbCommand Query(string sql, Dictionary<string, string> parameters) |
85 | { | 85 | { |
86 | SqlCommand dbcommand = (SqlCommand)dbcon.CreateCommand(); | 86 | SqlCommand dbcommand = (SqlCommand)dbcon.CreateCommand(); |
87 | dbcommand.CommandText = sql; | 87 | dbcommand.CommandText = sql; |
88 | foreach (KeyValuePair<string, string> param in parameters) | 88 | foreach (KeyValuePair<string, string> param in parameters) |
89 | { | 89 | { |
90 | dbcommand.Parameters.AddWithValue(param.Key, param.Value); | 90 | dbcommand.Parameters.AddWithValue(param.Key, param.Value); |
91 | } | 91 | } |
92 | 92 | ||
93 | return (IDbCommand)dbcommand; | 93 | return (IDbCommand)dbcommand; |
94 | } | 94 | } |
95 | 95 | ||
96 | /// <summary> | 96 | /// <summary> |
97 | /// Runs a database reader object and returns a region row | 97 | /// Runs a database reader object and returns a region row |
98 | /// </summary> | 98 | /// </summary> |
99 | /// <param name="reader">An active database reader</param> | 99 | /// <param name="reader">An active database reader</param> |
100 | /// <returns>A region row</returns> | 100 | /// <returns>A region row</returns> |
101 | public SimProfileData getRow(IDataReader reader) | 101 | public SimProfileData getRow(IDataReader reader) |
102 | { | 102 | { |
103 | SimProfileData regionprofile = new SimProfileData(); | 103 | SimProfileData regionprofile = new SimProfileData(); |
104 | 104 | ||
105 | if (reader.Read()) | 105 | if (reader.Read()) |
106 | { | 106 | { |
107 | // Region Main | 107 | // Region Main |
108 | regionprofile.regionHandle = (ulong)reader["regionHandle"]; | 108 | regionprofile.regionHandle = (ulong)reader["regionHandle"]; |
109 | regionprofile.regionName = (string)reader["regionName"]; | 109 | regionprofile.regionName = (string)reader["regionName"]; |
110 | regionprofile.UUID = new LLUUID((string)reader["uuid"]); | 110 | regionprofile.UUID = new LLUUID((string)reader["uuid"]); |
111 | 111 | ||
112 | // Secrets | 112 | // Secrets |
113 | regionprofile.regionRecvKey = (string)reader["regionRecvKey"]; | 113 | regionprofile.regionRecvKey = (string)reader["regionRecvKey"]; |
114 | regionprofile.regionSecret = (string)reader["regionSecret"]; | 114 | regionprofile.regionSecret = (string)reader["regionSecret"]; |
115 | regionprofile.regionSendKey = (string)reader["regionSendKey"]; | 115 | regionprofile.regionSendKey = (string)reader["regionSendKey"]; |
116 | 116 | ||
117 | // Region Server | 117 | // Region Server |
118 | regionprofile.regionDataURI = (string)reader["regionDataURI"]; | 118 | regionprofile.regionDataURI = (string)reader["regionDataURI"]; |
119 | regionprofile.regionOnline = false; // Needs to be pinged before this can be set. | 119 | regionprofile.regionOnline = false; // Needs to be pinged before this can be set. |
120 | regionprofile.serverIP = (string)reader["serverIP"]; | 120 | regionprofile.serverIP = (string)reader["serverIP"]; |
121 | regionprofile.serverPort = (uint)reader["serverPort"]; | 121 | regionprofile.serverPort = (uint)reader["serverPort"]; |
122 | regionprofile.serverURI = (string)reader["serverURI"]; | 122 | regionprofile.serverURI = (string)reader["serverURI"]; |
123 | 123 | ||
124 | // Location | 124 | // Location |
125 | regionprofile.regionLocX = (uint)((int)reader["locX"]); | 125 | regionprofile.regionLocX = (uint)((int)reader["locX"]); |
126 | regionprofile.regionLocY = (uint)((int)reader["locY"]); | 126 | regionprofile.regionLocY = (uint)((int)reader["locY"]); |
127 | regionprofile.regionLocZ = (uint)((int)reader["locZ"]); | 127 | regionprofile.regionLocZ = (uint)((int)reader["locZ"]); |
128 | 128 | ||
129 | // Neighbours - 0 = No Override | 129 | // Neighbours - 0 = No Override |
130 | regionprofile.regionEastOverrideHandle = (ulong)reader["eastOverrideHandle"]; | 130 | regionprofile.regionEastOverrideHandle = (ulong)reader["eastOverrideHandle"]; |
131 | regionprofile.regionWestOverrideHandle = (ulong)reader["westOverrideHandle"]; | 131 | regionprofile.regionWestOverrideHandle = (ulong)reader["westOverrideHandle"]; |
132 | regionprofile.regionSouthOverrideHandle = (ulong)reader["southOverrideHandle"]; | 132 | regionprofile.regionSouthOverrideHandle = (ulong)reader["southOverrideHandle"]; |
133 | regionprofile.regionNorthOverrideHandle = (ulong)reader["northOverrideHandle"]; | 133 | regionprofile.regionNorthOverrideHandle = (ulong)reader["northOverrideHandle"]; |
134 | 134 | ||
135 | // Assets | 135 | // Assets |
136 | regionprofile.regionAssetURI = (string)reader["regionAssetURI"]; | 136 | regionprofile.regionAssetURI = (string)reader["regionAssetURI"]; |
137 | regionprofile.regionAssetRecvKey = (string)reader["regionAssetRecvKey"]; | 137 | regionprofile.regionAssetRecvKey = (string)reader["regionAssetRecvKey"]; |
138 | regionprofile.regionAssetSendKey = (string)reader["regionAssetSendKey"]; | 138 | regionprofile.regionAssetSendKey = (string)reader["regionAssetSendKey"]; |
139 | 139 | ||
140 | // Userserver | 140 | // Userserver |
141 | regionprofile.regionUserURI = (string)reader["regionUserURI"]; | 141 | regionprofile.regionUserURI = (string)reader["regionUserURI"]; |
142 | regionprofile.regionUserRecvKey = (string)reader["regionUserRecvKey"]; | 142 | regionprofile.regionUserRecvKey = (string)reader["regionUserRecvKey"]; |
143 | regionprofile.regionUserSendKey = (string)reader["regionUserSendKey"]; | 143 | regionprofile.regionUserSendKey = (string)reader["regionUserSendKey"]; |
144 | } | 144 | } |
145 | else | 145 | else |
146 | { | 146 | { |
147 | throw new Exception("No rows to return"); | 147 | throw new Exception("No rows to return"); |
148 | } | 148 | } |
149 | return regionprofile; | 149 | return regionprofile; |
150 | } | 150 | } |
151 | 151 | ||
152 | /// <summary> | 152 | /// <summary> |
153 | /// Creates a new region in the database | 153 | /// Creates a new region in the database |
154 | /// </summary> | 154 | /// </summary> |
155 | /// <param name="profile">The region profile to insert</param> | 155 | /// <param name="profile">The region profile to insert</param> |
156 | /// <returns>Successful?</returns> | 156 | /// <returns>Successful?</returns> |
157 | public bool insertRow(SimProfileData profile) | 157 | public bool insertRow(SimProfileData profile) |
158 | { | 158 | { |
159 | string sql = "REPLACE INTO regions VALUES (regionHandle, regionName, uuid, regionRecvKey, regionSecret, regionSendKey, regionDataURI, "; | 159 | string sql = "REPLACE INTO regions VALUES (regionHandle, regionName, uuid, regionRecvKey, regionSecret, regionSendKey, regionDataURI, "; |
160 | sql += "serverIP, serverPort, serverURI, locX, locY, locZ, eastOverrideHandle, westOverrideHandle, southOverrideHandle, northOverrideHandle, regionAssetURI, regionAssetRecvKey, "; | 160 | sql += "serverIP, serverPort, serverURI, locX, locY, locZ, eastOverrideHandle, westOverrideHandle, southOverrideHandle, northOverrideHandle, regionAssetURI, regionAssetRecvKey, "; |
161 | sql += "regionAssetSendKey, regionUserURI, regionUserRecvKey, regionUserSendKey) VALUES "; | 161 | sql += "regionAssetSendKey, regionUserURI, regionUserRecvKey, regionUserSendKey) VALUES "; |
162 | 162 | ||
163 | sql += "(@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI, "; | 163 | sql += "(@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI, "; |
164 | sql += "@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle, @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, "; | 164 | sql += "@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle, @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, "; |
165 | sql += "@regionAssetSendKey, @regionUserURI, @regionUserRecvKey, @regionUserSendKey);"; | 165 | sql += "@regionAssetSendKey, @regionUserURI, @regionUserRecvKey, @regionUserSendKey);"; |
166 | 166 | ||
167 | Dictionary<string, string> parameters = new Dictionary<string, string>(); | 167 | Dictionary<string, string> parameters = new Dictionary<string, string>(); |
168 | 168 | ||
169 | parameters["regionHandle"] = profile.regionHandle.ToString(); | 169 | parameters["regionHandle"] = profile.regionHandle.ToString(); |
170 | parameters["regionName"] = profile.regionName; | 170 | parameters["regionName"] = profile.regionName; |
171 | parameters["uuid"] = profile.UUID.ToString(); | 171 | parameters["uuid"] = profile.UUID.ToString(); |
172 | parameters["regionRecvKey"] = profile.regionRecvKey; | 172 | parameters["regionRecvKey"] = profile.regionRecvKey; |
173 | parameters["regionSendKey"] = profile.regionSendKey; | 173 | parameters["regionSendKey"] = profile.regionSendKey; |
174 | parameters["regionDataURI"] = profile.regionDataURI; | 174 | parameters["regionDataURI"] = profile.regionDataURI; |
175 | parameters["serverIP"] = profile.serverIP; | 175 | parameters["serverIP"] = profile.serverIP; |
176 | parameters["serverPort"] = profile.serverPort.ToString(); | 176 | parameters["serverPort"] = profile.serverPort.ToString(); |
177 | parameters["serverURI"] = profile.serverURI; | 177 | parameters["serverURI"] = profile.serverURI; |
178 | parameters["locX"] = profile.regionLocX.ToString(); | 178 | parameters["locX"] = profile.regionLocX.ToString(); |
179 | parameters["locY"] = profile.regionLocY.ToString(); | 179 | parameters["locY"] = profile.regionLocY.ToString(); |
180 | parameters["locZ"] = profile.regionLocZ.ToString(); | 180 | parameters["locZ"] = profile.regionLocZ.ToString(); |
181 | parameters["eastOverrideHandle"] = profile.regionEastOverrideHandle.ToString(); | 181 | parameters["eastOverrideHandle"] = profile.regionEastOverrideHandle.ToString(); |
182 | parameters["westOverrideHandle"] = profile.regionWestOverrideHandle.ToString(); | 182 | parameters["westOverrideHandle"] = profile.regionWestOverrideHandle.ToString(); |
183 | parameters["northOverrideHandle"] = profile.regionNorthOverrideHandle.ToString(); | 183 | parameters["northOverrideHandle"] = profile.regionNorthOverrideHandle.ToString(); |
184 | parameters["southOverrideHandle"] = profile.regionSouthOverrideHandle.ToString(); | 184 | parameters["southOverrideHandle"] = profile.regionSouthOverrideHandle.ToString(); |
185 | parameters["regionAssetURI"] = profile.regionAssetURI; | 185 | parameters["regionAssetURI"] = profile.regionAssetURI; |
186 | parameters["regionAssetRecvKey"] = profile.regionAssetRecvKey; | 186 | parameters["regionAssetRecvKey"] = profile.regionAssetRecvKey; |
187 | parameters["regionAssetSendKey"] = profile.regionAssetSendKey; | 187 | parameters["regionAssetSendKey"] = profile.regionAssetSendKey; |
188 | parameters["regionUserURI"] = profile.regionUserURI; | 188 | parameters["regionUserURI"] = profile.regionUserURI; |
189 | parameters["regionUserRecvKey"] = profile.regionUserRecvKey; | 189 | parameters["regionUserRecvKey"] = profile.regionUserRecvKey; |
190 | parameters["regionUserSendKey"] = profile.regionUserSendKey; | 190 | parameters["regionUserSendKey"] = profile.regionUserSendKey; |
191 | 191 | ||
192 | bool returnval = false; | 192 | bool returnval = false; |
193 | 193 | ||
194 | try | 194 | try |
195 | { | 195 | { |
196 | IDbCommand result = Query(sql, parameters); | 196 | IDbCommand result = Query(sql, parameters); |
197 | 197 | ||
198 | if (result.ExecuteNonQuery() == 1) | 198 | if (result.ExecuteNonQuery() == 1) |
199 | returnval = true; | 199 | returnval = true; |
200 | 200 | ||
201 | result.Dispose(); | 201 | result.Dispose(); |
202 | } | 202 | } |
203 | catch (Exception) | 203 | catch (Exception) |
204 | { | 204 | { |
205 | return false; | 205 | return false; |
206 | } | 206 | } |
207 | 207 | ||
208 | return returnval; | 208 | return returnval; |
209 | } | 209 | } |
210 | } | 210 | } |
211 | } | 211 | } |