diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/MSSQL/MSSQLEstateData.cs | 139 |
1 files changed, 73 insertions, 66 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLEstateData.cs b/OpenSim/Data/MSSQL/MSSQLEstateData.cs index c0c6349..474f706 100644 --- a/OpenSim/Data/MSSQL/MSSQLEstateData.cs +++ b/OpenSim/Data/MSSQL/MSSQLEstateData.cs | |||
@@ -44,7 +44,7 @@ namespace OpenSim.Data.MSSQL | |||
44 | private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 44 | private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
45 | 45 | ||
46 | private MSSQLManager _Database; | 46 | private MSSQLManager _Database; |
47 | 47 | private string m_connectionString; | |
48 | private FieldInfo[] _Fields; | 48 | private FieldInfo[] _Fields; |
49 | private Dictionary<string, FieldInfo> _FieldMap = new Dictionary<string, FieldInfo>(); | 49 | private Dictionary<string, FieldInfo> _FieldMap = new Dictionary<string, FieldInfo>(); |
50 | 50 | ||
@@ -58,22 +58,9 @@ namespace OpenSim.Data.MSSQL | |||
58 | { | 58 | { |
59 | if (!string.IsNullOrEmpty(connectionString)) | 59 | if (!string.IsNullOrEmpty(connectionString)) |
60 | { | 60 | { |
61 | m_connectionString = connectionString; | ||
61 | _Database = new MSSQLManager(connectionString); | 62 | _Database = new MSSQLManager(connectionString); |
62 | } | 63 | } |
63 | else | ||
64 | { | ||
65 | //TODO when can this be deleted | ||
66 | IniFile iniFile = new IniFile("mssql_connection.ini"); | ||
67 | string settingDataSource = iniFile.ParseFileReadValue("data_source"); | ||
68 | string settingInitialCatalog = iniFile.ParseFileReadValue("initial_catalog"); | ||
69 | string settingPersistSecurityInfo = iniFile.ParseFileReadValue("persist_security_info"); | ||
70 | string settingUserId = iniFile.ParseFileReadValue("user_id"); | ||
71 | string settingPassword = iniFile.ParseFileReadValue("password"); | ||
72 | |||
73 | _Database = | ||
74 | new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, | ||
75 | settingPassword); | ||
76 | } | ||
77 | 64 | ||
78 | //Migration settings | 65 | //Migration settings |
79 | _Database.CheckMigration(_migrationStore); | 66 | _Database.CheckMigration(_migrationStore); |
@@ -96,18 +83,18 @@ namespace OpenSim.Data.MSSQL | |||
96 | /// </summary> | 83 | /// </summary> |
97 | /// <param name="regionID">region ID.</param> | 84 | /// <param name="regionID">region ID.</param> |
98 | /// <returns></returns> | 85 | /// <returns></returns> |
99 | public EstateSettings LoadEstateSettings(UUID regionID) | 86 | public EstateSettings LoadEstateSettings(UUID regionID, bool create) |
100 | { | 87 | { |
101 | EstateSettings es = new EstateSettings(); | 88 | EstateSettings es = new EstateSettings(); |
102 | 89 | ||
103 | string sql = "select estate_settings." + String.Join(",estate_settings.", FieldList) + " from estate_map left join estate_settings on estate_map.EstateID = estate_settings.EstateID where estate_settings.EstateID is not null and RegionID = @RegionID"; | 90 | string sql = "select estate_settings." + String.Join(",estate_settings.", FieldList) + " from estate_map left join estate_settings on estate_map.EstateID = estate_settings.EstateID where estate_settings.EstateID is not null and RegionID = @RegionID"; |
104 | 91 | ||
105 | bool insertEstate = false; | 92 | bool insertEstate = false; |
106 | 93 | using (SqlConnection conn = new SqlConnection(m_connectionString)) | |
107 | using (AutoClosingSqlCommand cmd = _Database.Query(sql)) | 94 | using (SqlCommand cmd = new SqlCommand(sql, conn)) |
108 | { | 95 | { |
109 | cmd.Parameters.Add(_Database.CreateParameter("@RegionID", regionID)); | 96 | cmd.Parameters.Add(_Database.CreateParameter("@RegionID", regionID)); |
110 | 97 | conn.Open(); | |
111 | using (SqlDataReader reader = cmd.ExecuteReader()) | 98 | using (SqlDataReader reader = cmd.ExecuteReader()) |
112 | { | 99 | { |
113 | if (reader.Read()) | 100 | if (reader.Read()) |
@@ -124,7 +111,7 @@ namespace OpenSim.Data.MSSQL | |||
124 | } | 111 | } |
125 | else if (_FieldMap[name].GetValue(es) is UUID) | 112 | else if (_FieldMap[name].GetValue(es) is UUID) |
126 | { | 113 | { |
127 | _FieldMap[name].SetValue(es, new UUID((Guid) reader[name])); // uuid); | 114 | _FieldMap[name].SetValue(es, new UUID((Guid)reader[name])); // uuid); |
128 | } | 115 | } |
129 | else | 116 | else |
130 | { | 117 | { |
@@ -140,7 +127,7 @@ namespace OpenSim.Data.MSSQL | |||
140 | } | 127 | } |
141 | 128 | ||
142 | 129 | ||
143 | if (insertEstate) | 130 | if (insertEstate && create) |
144 | { | 131 | { |
145 | List<string> names = new List<string>(FieldList); | 132 | List<string> names = new List<string>(FieldList); |
146 | 133 | ||
@@ -149,34 +136,36 @@ namespace OpenSim.Data.MSSQL | |||
149 | sql = string.Format("insert into estate_settings ({0}) values ( @{1})", String.Join(",", names.ToArray()), String.Join(", @", names.ToArray())); | 136 | sql = string.Format("insert into estate_settings ({0}) values ( @{1})", String.Join(",", names.ToArray()), String.Join(", @", names.ToArray())); |
150 | 137 | ||
151 | //_Log.Debug("[DB ESTATE]: SQL: " + sql); | 138 | //_Log.Debug("[DB ESTATE]: SQL: " + sql); |
152 | using (SqlConnection connection = _Database.DatabaseConnection()) | 139 | using (SqlConnection conn = new SqlConnection(m_connectionString)) |
140 | using (SqlCommand insertCommand = new SqlCommand(sql, conn)) | ||
153 | { | 141 | { |
154 | using (SqlCommand insertCommand = connection.CreateCommand()) | 142 | insertCommand.CommandText = sql + " SET @ID = SCOPE_IDENTITY()"; |
155 | { | ||
156 | insertCommand.CommandText = sql + " SET @ID = SCOPE_IDENTITY()"; | ||
157 | 143 | ||
158 | foreach (string name in names) | 144 | foreach (string name in names) |
159 | { | 145 | { |
160 | insertCommand.Parameters.Add(_Database.CreateParameter("@" + name, _FieldMap[name].GetValue(es))); | 146 | insertCommand.Parameters.Add(_Database.CreateParameter("@" + name, _FieldMap[name].GetValue(es))); |
161 | } | ||
162 | SqlParameter idParameter = new SqlParameter("@ID", SqlDbType.Int); | ||
163 | idParameter.Direction = ParameterDirection.Output; | ||
164 | insertCommand.Parameters.Add(idParameter); | ||
165 | |||
166 | insertCommand.ExecuteNonQuery(); | ||
167 | |||
168 | es.EstateID = Convert.ToUInt32(idParameter.Value); | ||
169 | } | 147 | } |
148 | SqlParameter idParameter = new SqlParameter("@ID", SqlDbType.Int); | ||
149 | idParameter.Direction = ParameterDirection.Output; | ||
150 | insertCommand.Parameters.Add(idParameter); | ||
151 | conn.Open(); | ||
152 | insertCommand.ExecuteNonQuery(); | ||
153 | |||
154 | es.EstateID = Convert.ToUInt32(idParameter.Value); | ||
170 | } | 155 | } |
171 | 156 | ||
172 | using (AutoClosingSqlCommand cmd = _Database.Query("INSERT INTO [estate_map] ([RegionID] ,[EstateID]) VALUES (@RegionID, @EstateID)")) | 157 | sql = "INSERT INTO [estate_map] ([RegionID] ,[EstateID]) VALUES (@RegionID, @EstateID)"; |
158 | using (SqlConnection conn = new SqlConnection(m_connectionString)) | ||
159 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | ||
173 | { | 160 | { |
161 | |||
174 | cmd.Parameters.Add(_Database.CreateParameter("@RegionID", regionID)); | 162 | cmd.Parameters.Add(_Database.CreateParameter("@RegionID", regionID)); |
175 | cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID)); | 163 | cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID)); |
176 | // This will throw on dupe key | 164 | // This will throw on dupe key |
177 | try | 165 | try |
178 | { | 166 | { |
179 | cmd.ExecuteNonQuery(); | 167 | conn.Open(); |
168 | cmd.ExecuteNonQuery(); | ||
180 | } | 169 | } |
181 | catch (Exception e) | 170 | catch (Exception e) |
182 | { | 171 | { |
@@ -184,23 +173,6 @@ namespace OpenSim.Data.MSSQL | |||
184 | } | 173 | } |
185 | } | 174 | } |
186 | 175 | ||
187 | // Munge and transfer the ban list | ||
188 | |||
189 | sql = string.Format("insert into estateban select {0}, bannedUUID, bannedIp, bannedIpHostMask, '' from regionban where regionban.regionUUID = @UUID", es.EstateID); | ||
190 | using (AutoClosingSqlCommand cmd = _Database.Query(sql)) | ||
191 | { | ||
192 | cmd.Parameters.Add(_Database.CreateParameter("@UUID", regionID)); | ||
193 | try | ||
194 | { | ||
195 | |||
196 | cmd.ExecuteNonQuery(); | ||
197 | } | ||
198 | catch (Exception) | ||
199 | { | ||
200 | _Log.Debug("[ESTATE DB]: Error setting up estateban from regionban"); | ||
201 | } | ||
202 | } | ||
203 | |||
204 | //TODO check if this is needed?? | 176 | //TODO check if this is needed?? |
205 | es.Save(); | 177 | es.Save(); |
206 | } | 178 | } |
@@ -226,7 +198,7 @@ namespace OpenSim.Data.MSSQL | |||
226 | 198 | ||
227 | names.Remove("EstateID"); | 199 | names.Remove("EstateID"); |
228 | 200 | ||
229 | string sql = string.Format("UPDATE estate_settings SET ") ; | 201 | string sql = string.Format("UPDATE estate_settings SET "); |
230 | foreach (string name in names) | 202 | foreach (string name in names) |
231 | { | 203 | { |
232 | sql += name + " = @" + name + ", "; | 204 | sql += name + " = @" + name + ", "; |
@@ -234,7 +206,8 @@ namespace OpenSim.Data.MSSQL | |||
234 | sql = sql.Remove(sql.LastIndexOf(",")); | 206 | sql = sql.Remove(sql.LastIndexOf(",")); |
235 | sql += " WHERE EstateID = @EstateID"; | 207 | sql += " WHERE EstateID = @EstateID"; |
236 | 208 | ||
237 | using (AutoClosingSqlCommand cmd = _Database.Query(sql)) | 209 | using (SqlConnection conn = new SqlConnection(m_connectionString)) |
210 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | ||
238 | { | 211 | { |
239 | foreach (string name in names) | 212 | foreach (string name in names) |
240 | { | 213 | { |
@@ -242,6 +215,7 @@ namespace OpenSim.Data.MSSQL | |||
242 | } | 215 | } |
243 | 216 | ||
244 | cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID)); | 217 | cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID)); |
218 | conn.Open(); | ||
245 | cmd.ExecuteNonQuery(); | 219 | cmd.ExecuteNonQuery(); |
246 | } | 220 | } |
247 | 221 | ||
@@ -266,12 +240,13 @@ namespace OpenSim.Data.MSSQL | |||
266 | 240 | ||
267 | string sql = "select bannedUUID from estateban where EstateID = @EstateID"; | 241 | string sql = "select bannedUUID from estateban where EstateID = @EstateID"; |
268 | 242 | ||
269 | using (AutoClosingSqlCommand cmd = _Database.Query(sql)) | 243 | using (SqlConnection conn = new SqlConnection(m_connectionString)) |
244 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | ||
270 | { | 245 | { |
271 | SqlParameter idParameter = new SqlParameter("@EstateID", SqlDbType.Int); | 246 | SqlParameter idParameter = new SqlParameter("@EstateID", SqlDbType.Int); |
272 | idParameter.Value = es.EstateID; | 247 | idParameter.Value = es.EstateID; |
273 | cmd.Parameters.Add(idParameter); | 248 | cmd.Parameters.Add(idParameter); |
274 | 249 | conn.Open(); | |
275 | using (SqlDataReader reader = cmd.ExecuteReader()) | 250 | using (SqlDataReader reader = cmd.ExecuteReader()) |
276 | { | 251 | { |
277 | while (reader.Read()) | 252 | while (reader.Read()) |
@@ -293,10 +268,11 @@ namespace OpenSim.Data.MSSQL | |||
293 | 268 | ||
294 | string sql = string.Format("select uuid from {0} where EstateID = @EstateID", table); | 269 | string sql = string.Format("select uuid from {0} where EstateID = @EstateID", table); |
295 | 270 | ||
296 | using (AutoClosingSqlCommand cmd = _Database.Query(sql)) | 271 | using (SqlConnection conn = new SqlConnection(m_connectionString)) |
272 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | ||
297 | { | 273 | { |
298 | cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID)); | 274 | cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID)); |
299 | 275 | conn.Open(); | |
300 | using (SqlDataReader reader = cmd.ExecuteReader()) | 276 | using (SqlDataReader reader = cmd.ExecuteReader()) |
301 | { | 277 | { |
302 | while (reader.Read()) | 278 | while (reader.Read()) |
@@ -313,20 +289,24 @@ namespace OpenSim.Data.MSSQL | |||
313 | { | 289 | { |
314 | //Delete first | 290 | //Delete first |
315 | string sql = "delete from estateban where EstateID = @EstateID"; | 291 | string sql = "delete from estateban where EstateID = @EstateID"; |
316 | using (AutoClosingSqlCommand cmd = _Database.Query(sql)) | 292 | using (SqlConnection conn = new SqlConnection(m_connectionString)) |
293 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | ||
317 | { | 294 | { |
318 | cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID)); | 295 | cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID)); |
296 | conn.Open(); | ||
319 | cmd.ExecuteNonQuery(); | 297 | cmd.ExecuteNonQuery(); |
320 | } | 298 | } |
321 | 299 | ||
322 | //Insert after | 300 | //Insert after |
323 | sql = "insert into estateban (EstateID, bannedUUID) values ( @EstateID, @bannedUUID )"; | 301 | sql = "insert into estateban (EstateID, bannedUUID) values ( @EstateID, @bannedUUID )"; |
324 | using (AutoClosingSqlCommand cmd = _Database.Query(sql)) | 302 | using (SqlConnection conn = new SqlConnection(m_connectionString)) |
303 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | ||
325 | { | 304 | { |
326 | foreach (EstateBan b in es.EstateBans) | 305 | foreach (EstateBan b in es.EstateBans) |
327 | { | 306 | { |
328 | cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID)); | 307 | cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID)); |
329 | cmd.Parameters.Add(_Database.CreateParameter("@bannedUUID", b.BannedUserID)); | 308 | cmd.Parameters.Add(_Database.CreateParameter("@bannedUUID", b.BannedUserID)); |
309 | conn.Open(); | ||
330 | cmd.ExecuteNonQuery(); | 310 | cmd.ExecuteNonQuery(); |
331 | cmd.Parameters.Clear(); | 311 | cmd.Parameters.Clear(); |
332 | } | 312 | } |
@@ -337,14 +317,16 @@ namespace OpenSim.Data.MSSQL | |||
337 | { | 317 | { |
338 | //Delete first | 318 | //Delete first |
339 | string sql = string.Format("delete from {0} where EstateID = @EstateID", table); | 319 | string sql = string.Format("delete from {0} where EstateID = @EstateID", table); |
340 | using (AutoClosingSqlCommand cmd = _Database.Query(sql)) | 320 | using (SqlConnection conn = new SqlConnection(m_connectionString)) |
321 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | ||
341 | { | 322 | { |
342 | cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID)); | 323 | cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID)); |
343 | cmd.ExecuteNonQuery(); | 324 | cmd.ExecuteNonQuery(); |
344 | } | 325 | } |
345 | 326 | ||
346 | sql = string.Format("insert into {0} (EstateID, uuid) values ( @EstateID, @uuid )", table); | 327 | sql = string.Format("insert into {0} (EstateID, uuid) values ( @EstateID, @uuid )", table); |
347 | using (AutoClosingSqlCommand cmd = _Database.Query(sql)) | 328 | using (SqlConnection conn = new SqlConnection(m_connectionString)) |
329 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | ||
348 | { | 330 | { |
349 | cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID)); | 331 | cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID)); |
350 | 332 | ||
@@ -359,11 +341,36 @@ namespace OpenSim.Data.MSSQL | |||
359 | } | 341 | } |
360 | else | 342 | else |
361 | cmd.Parameters["@uuid"].Value = uuid.Guid; //.ToString(); //TODO check if this works | 343 | cmd.Parameters["@uuid"].Value = uuid.Guid; //.ToString(); //TODO check if this works |
362 | 344 | conn.Open(); | |
363 | cmd.ExecuteNonQuery(); | 345 | cmd.ExecuteNonQuery(); |
364 | } | 346 | } |
365 | } | 347 | } |
366 | } | 348 | } |
349 | |||
350 | public EstateSettings LoadEstateSettings(int estateID) | ||
351 | { | ||
352 | return new EstateSettings(); | ||
353 | } | ||
354 | |||
355 | public List<int> GetEstates(string search) | ||
356 | { | ||
357 | return new List<int>(); | ||
358 | } | ||
359 | |||
360 | public bool LinkRegion(UUID regionID, int estateID) | ||
361 | { | ||
362 | return false; | ||
363 | } | ||
364 | |||
365 | public List<UUID> GetRegions(int estateID) | ||
366 | { | ||
367 | return new List<UUID>(); | ||
368 | } | ||
369 | |||
370 | public bool DeleteEstate(int estateID) | ||
371 | { | ||
372 | return false; | ||
373 | } | ||
367 | #endregion | 374 | #endregion |
368 | } | 375 | } |
369 | } | 376 | } |