diff options
Diffstat (limited to 'OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs')
-rw-r--r-- | OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs | 164 |
1 files changed, 135 insertions, 29 deletions
diff --git a/OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs b/OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs index 1516fec..0d294e7 100644 --- a/OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs +++ b/OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs | |||
@@ -28,11 +28,10 @@ | |||
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 OpenSim.Framework; | ||
32 | using System.Security.Cryptography; | 31 | using System.Security.Cryptography; |
33 | using System.Text; | 32 | using System.Text; |
34 | using libsecondlife; | 33 | using libsecondlife; |
35 | 34 | using OpenSim.Framework.Console; | |
36 | 35 | ||
37 | namespace OpenSim.Framework.Data.MSSQL | 36 | namespace OpenSim.Framework.Data.MSSQL |
38 | { | 37 | { |
@@ -44,14 +43,22 @@ namespace OpenSim.Framework.Data.MSSQL | |||
44 | /// <summary> | 43 | /// <summary> |
45 | /// Database manager | 44 | /// Database manager |
46 | /// </summary> | 45 | /// </summary> |
47 | private MSSqlManager database; | 46 | private MSSQLManager database; |
48 | 47 | ||
49 | /// <summary> | 48 | /// <summary> |
50 | /// Initialises the Grid Interface | 49 | /// Initialises the Grid Interface |
51 | /// </summary> | 50 | /// </summary> |
52 | public void Initialise() | 51 | public void Initialise() |
53 | { | 52 | { |
54 | database = new MSSqlManager("localhost", "db", "user", "password", "false"); | 53 | IniFile GridDataMySqlFile = new IniFile("mssql_connection.ini"); |
54 | string settingDataSource = GridDataMySqlFile.ParseFileReadValue("data_source"); | ||
55 | string settingInitialCatalog = GridDataMySqlFile.ParseFileReadValue("initial_catalog"); | ||
56 | string settingPersistSecurityInfo = GridDataMySqlFile.ParseFileReadValue("persist_security_info"); | ||
57 | string settingUserId = GridDataMySqlFile.ParseFileReadValue("user_id"); | ||
58 | string settingPassword = GridDataMySqlFile.ParseFileReadValue("password"); | ||
59 | |||
60 | database = new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, settingPassword); | ||
61 | |||
55 | } | 62 | } |
56 | 63 | ||
57 | /// <summary> | 64 | /// <summary> |
@@ -100,17 +107,115 @@ namespace OpenSim.Framework.Data.MSSQL | |||
100 | /// <returns>Sim profile</returns> | 107 | /// <returns>Sim profile</returns> |
101 | public RegionProfileData GetProfileByHandle(ulong handle) | 108 | public RegionProfileData GetProfileByHandle(ulong handle) |
102 | { | 109 | { |
103 | Dictionary<string, string> param = new Dictionary<string, string>(); | 110 | IDataReader reader = null; |
104 | param["handle"] = handle.ToString(); | 111 | try |
112 | { | ||
113 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
114 | param["handle"] = handle.ToString(); | ||
115 | IDbCommand result = database.Query("SELECT * FROM regions WHERE regionHandle = @handle", param); | ||
116 | reader = result.ExecuteReader(); | ||
105 | 117 | ||
106 | IDbCommand result = database.Query("SELECT * FROM regions WHERE handle = @handle", param); | 118 | RegionProfileData row = database.getRegionRow(reader); |
107 | IDataReader reader = result.ExecuteReader(); | 119 | reader.Close(); |
120 | result.Dispose(); | ||
108 | 121 | ||
109 | RegionProfileData row = database.getRow(reader); | 122 | return row; |
110 | reader.Close(); | ||
111 | result.Dispose(); | ||
112 | 123 | ||
113 | return row; | 124 | } |
125 | catch (Exception) | ||
126 | { | ||
127 | if (reader != null) { | ||
128 | reader.Close(); | ||
129 | } | ||
130 | |||
131 | } | ||
132 | return null; | ||
133 | } | ||
134 | |||
135 | /// <summary> | ||
136 | /// // Returns a list of avatar and UUIDs that match the query | ||
137 | /// </summary> | ||
138 | |||
139 | public List<AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query) | ||
140 | { | ||
141 | List<AvatarPickerAvatar> returnlist = new List<AvatarPickerAvatar>(); | ||
142 | string[] querysplit; | ||
143 | querysplit = query.Split(' '); | ||
144 | if (querysplit.Length == 2) | ||
145 | { | ||
146 | try | ||
147 | { | ||
148 | lock (database) | ||
149 | { | ||
150 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
151 | param["first"] = querysplit[0]; | ||
152 | param["second"] = querysplit[1]; | ||
153 | |||
154 | IDbCommand result = | ||
155 | database.Query("SELECT UUID,username,surname FROM users WHERE username = @first AND lastname = @second", param); | ||
156 | IDataReader reader = result.ExecuteReader(); | ||
157 | |||
158 | |||
159 | while (reader.Read()) | ||
160 | { | ||
161 | AvatarPickerAvatar user = new AvatarPickerAvatar(); | ||
162 | user.AvatarID = new LLUUID((string)reader["UUID"]); | ||
163 | user.firstName = (string)reader["username"]; | ||
164 | user.lastName = (string)reader["surname"]; | ||
165 | returnlist.Add(user); | ||
166 | |||
167 | } | ||
168 | reader.Close(); | ||
169 | result.Dispose(); | ||
170 | } | ||
171 | } | ||
172 | catch (Exception e) | ||
173 | { | ||
174 | database.Reconnect(); | ||
175 | MainLog.Instance.Error(e.ToString()); | ||
176 | return returnlist; | ||
177 | } | ||
178 | |||
179 | |||
180 | |||
181 | } | ||
182 | else if (querysplit.Length == 1) | ||
183 | { | ||
184 | |||
185 | try | ||
186 | { | ||
187 | lock (database) | ||
188 | { | ||
189 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
190 | param["first"] = querysplit[0]; | ||
191 | param["second"] = querysplit[1]; | ||
192 | |||
193 | IDbCommand result = | ||
194 | database.Query("SELECT UUID,username,surname FROM users WHERE username = @first OR lastname = @second", param); | ||
195 | IDataReader reader = result.ExecuteReader(); | ||
196 | |||
197 | |||
198 | while (reader.Read()) | ||
199 | { | ||
200 | AvatarPickerAvatar user = new AvatarPickerAvatar(); | ||
201 | user.AvatarID = new LLUUID((string)reader["UUID"]); | ||
202 | user.firstName = (string)reader["username"]; | ||
203 | user.lastName = (string)reader["surname"]; | ||
204 | returnlist.Add(user); | ||
205 | |||
206 | } | ||
207 | reader.Close(); | ||
208 | result.Dispose(); | ||
209 | } | ||
210 | } | ||
211 | catch (Exception e) | ||
212 | { | ||
213 | database.Reconnect(); | ||
214 | MainLog.Instance.Error(e.ToString()); | ||
215 | return returnlist; | ||
216 | } | ||
217 | } | ||
218 | return returnlist; | ||
114 | } | 219 | } |
115 | 220 | ||
116 | /// <summary> | 221 | /// <summary> |
@@ -120,28 +225,18 @@ namespace OpenSim.Framework.Data.MSSQL | |||
120 | /// <returns>The sim profile</returns> | 225 | /// <returns>The sim profile</returns> |
121 | public RegionProfileData GetProfileByLLUUID(LLUUID uuid) | 226 | public RegionProfileData GetProfileByLLUUID(LLUUID uuid) |
122 | { | 227 | { |
123 | Dictionary<string, string> param = new Dictionary<string, string>(); | 228 | Dictionary<string, string> param = new Dictionary<string, string>(); |
124 | param["uuid"] = uuid.ToStringHyphenated(); | 229 | param["uuid"] = uuid.ToString(); |
125 | |||
126 | IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = @uuid", param); | 230 | IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = @uuid", param); |
127 | IDataReader reader = result.ExecuteReader(); | 231 | IDataReader reader = result.ExecuteReader(); |
128 | 232 | ||
129 | RegionProfileData row = database.getRow(reader); | 233 | RegionProfileData row = database.getRegionRow(reader); |
130 | reader.Close(); | 234 | reader.Close(); |
131 | result.Dispose(); | 235 | result.Dispose(); |
132 | 236 | ||
133 | return row; | 237 | return row; |
134 | } | 238 | } |
135 | /// <summary> | ||
136 | /// // Returns a list of avatar and UUIDs that match the query | ||
137 | /// </summary> | ||
138 | 239 | ||
139 | public List<OpenSim.Framework.Data.AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query) | ||
140 | { | ||
141 | //Do nothing yet | ||
142 | List<AvatarPickerAvatar> returnlist = new List<AvatarPickerAvatar>(); | ||
143 | return returnlist; | ||
144 | } | ||
145 | /// <summary> | 240 | /// <summary> |
146 | /// Adds a new specified region to the database | 241 | /// Adds a new specified region to the database |
147 | /// </summary> | 242 | /// </summary> |
@@ -149,7 +244,20 @@ namespace OpenSim.Framework.Data.MSSQL | |||
149 | /// <returns>A dataresponse enum indicating success</returns> | 244 | /// <returns>A dataresponse enum indicating success</returns> |
150 | public DataResponse AddProfile(RegionProfileData profile) | 245 | public DataResponse AddProfile(RegionProfileData profile) |
151 | { | 246 | { |
152 | if (database.insertRow(profile)) | 247 | |
248 | try | ||
249 | { | ||
250 | if (GetProfileByLLUUID(profile.UUID) != null) | ||
251 | { | ||
252 | return DataResponse.RESPONSE_OK; | ||
253 | } | ||
254 | } | ||
255 | catch (Exception) | ||
256 | { | ||
257 | System.Console.WriteLine("No regions found. Create new one."); | ||
258 | } | ||
259 | |||
260 | if (database.insertRegionRow(profile)) | ||
153 | { | 261 | { |
154 | return DataResponse.RESPONSE_OK; | 262 | return DataResponse.RESPONSE_OK; |
155 | } | 263 | } |
@@ -201,7 +309,5 @@ namespace OpenSim.Framework.Data.MSSQL | |||
201 | { | 309 | { |
202 | return null; | 310 | return null; |
203 | } | 311 | } |
204 | // This is here because MSSQL GridData only seems to know about itself o.O | ||
205 | |||
206 | } | 312 | } |
207 | } \ No newline at end of file | 313 | } |