aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MSSQL/MSSQLEstateData.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Data/MSSQL/MSSQLEstateData.cs99
1 files changed, 50 insertions, 49 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLEstateData.cs b/OpenSim/Data/MSSQL/MSSQLEstateData.cs
index c0c6349..6f6f076 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);
@@ -103,11 +90,11 @@ namespace OpenSim.Data.MSSQL
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 {
@@ -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
158 foreach (string name in names)
159 {
160 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 143
168 es.EstateID = Convert.ToUInt32(idParameter.Value); 144 foreach (string name in names)
145 {
146 insertCommand.Parameters.Add(_Database.CreateParameter("@" + name, _FieldMap[name].GetValue(es)));
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 {
@@ -187,12 +176,14 @@ namespace OpenSim.Data.MSSQL
187 // Munge and transfer the ban list 176 // Munge and transfer the ban list
188 177
189 sql = string.Format("insert into estateban select {0}, bannedUUID, bannedIp, bannedIpHostMask, '' from regionban where regionban.regionUUID = @UUID", es.EstateID); 178 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)) 179 using (SqlConnection conn = new SqlConnection(m_connectionString))
180 using (SqlCommand cmd = new SqlCommand(sql, conn))
191 { 181 {
182
192 cmd.Parameters.Add(_Database.CreateParameter("@UUID", regionID)); 183 cmd.Parameters.Add(_Database.CreateParameter("@UUID", regionID));
193 try 184 try
194 { 185 {
195 186 conn.Open();
196 cmd.ExecuteNonQuery(); 187 cmd.ExecuteNonQuery();
197 } 188 }
198 catch (Exception) 189 catch (Exception)
@@ -226,7 +217,7 @@ namespace OpenSim.Data.MSSQL
226 217
227 names.Remove("EstateID"); 218 names.Remove("EstateID");
228 219
229 string sql = string.Format("UPDATE estate_settings SET ") ; 220 string sql = string.Format("UPDATE estate_settings SET ");
230 foreach (string name in names) 221 foreach (string name in names)
231 { 222 {
232 sql += name + " = @" + name + ", "; 223 sql += name + " = @" + name + ", ";
@@ -234,7 +225,8 @@ namespace OpenSim.Data.MSSQL
234 sql = sql.Remove(sql.LastIndexOf(",")); 225 sql = sql.Remove(sql.LastIndexOf(","));
235 sql += " WHERE EstateID = @EstateID"; 226 sql += " WHERE EstateID = @EstateID";
236 227
237 using (AutoClosingSqlCommand cmd = _Database.Query(sql)) 228 using (SqlConnection conn = new SqlConnection(m_connectionString))
229 using (SqlCommand cmd = new SqlCommand(sql, conn))
238 { 230 {
239 foreach (string name in names) 231 foreach (string name in names)
240 { 232 {
@@ -242,6 +234,7 @@ namespace OpenSim.Data.MSSQL
242 } 234 }
243 235
244 cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID)); 236 cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID));
237 conn.Open();
245 cmd.ExecuteNonQuery(); 238 cmd.ExecuteNonQuery();
246 } 239 }
247 240
@@ -266,12 +259,13 @@ namespace OpenSim.Data.MSSQL
266 259
267 string sql = "select bannedUUID from estateban where EstateID = @EstateID"; 260 string sql = "select bannedUUID from estateban where EstateID = @EstateID";
268 261
269 using (AutoClosingSqlCommand cmd = _Database.Query(sql)) 262 using (SqlConnection conn = new SqlConnection(m_connectionString))
263 using (SqlCommand cmd = new SqlCommand(sql, conn))
270 { 264 {
271 SqlParameter idParameter = new SqlParameter("@EstateID", SqlDbType.Int); 265 SqlParameter idParameter = new SqlParameter("@EstateID", SqlDbType.Int);
272 idParameter.Value = es.EstateID; 266 idParameter.Value = es.EstateID;
273 cmd.Parameters.Add(idParameter); 267 cmd.Parameters.Add(idParameter);
274 268 conn.Open();
275 using (SqlDataReader reader = cmd.ExecuteReader()) 269 using (SqlDataReader reader = cmd.ExecuteReader())
276 { 270 {
277 while (reader.Read()) 271 while (reader.Read())
@@ -293,10 +287,11 @@ namespace OpenSim.Data.MSSQL
293 287
294 string sql = string.Format("select uuid from {0} where EstateID = @EstateID", table); 288 string sql = string.Format("select uuid from {0} where EstateID = @EstateID", table);
295 289
296 using (AutoClosingSqlCommand cmd = _Database.Query(sql)) 290 using (SqlConnection conn = new SqlConnection(m_connectionString))
291 using (SqlCommand cmd = new SqlCommand(sql, conn))
297 { 292 {
298 cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID)); 293 cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID));
299 294 conn.Open();
300 using (SqlDataReader reader = cmd.ExecuteReader()) 295 using (SqlDataReader reader = cmd.ExecuteReader())
301 { 296 {
302 while (reader.Read()) 297 while (reader.Read())
@@ -313,20 +308,24 @@ namespace OpenSim.Data.MSSQL
313 { 308 {
314 //Delete first 309 //Delete first
315 string sql = "delete from estateban where EstateID = @EstateID"; 310 string sql = "delete from estateban where EstateID = @EstateID";
316 using (AutoClosingSqlCommand cmd = _Database.Query(sql)) 311 using (SqlConnection conn = new SqlConnection(m_connectionString))
312 using (SqlCommand cmd = new SqlCommand(sql, conn))
317 { 313 {
318 cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID)); 314 cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID));
315 conn.Open();
319 cmd.ExecuteNonQuery(); 316 cmd.ExecuteNonQuery();
320 } 317 }
321 318
322 //Insert after 319 //Insert after
323 sql = "insert into estateban (EstateID, bannedUUID) values ( @EstateID, @bannedUUID )"; 320 sql = "insert into estateban (EstateID, bannedUUID) values ( @EstateID, @bannedUUID )";
324 using (AutoClosingSqlCommand cmd = _Database.Query(sql)) 321 using (SqlConnection conn = new SqlConnection(m_connectionString))
322 using (SqlCommand cmd = new SqlCommand(sql, conn))
325 { 323 {
326 foreach (EstateBan b in es.EstateBans) 324 foreach (EstateBan b in es.EstateBans)
327 { 325 {
328 cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID)); 326 cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID));
329 cmd.Parameters.Add(_Database.CreateParameter("@bannedUUID", b.BannedUserID)); 327 cmd.Parameters.Add(_Database.CreateParameter("@bannedUUID", b.BannedUserID));
328 conn.Open();
330 cmd.ExecuteNonQuery(); 329 cmd.ExecuteNonQuery();
331 cmd.Parameters.Clear(); 330 cmd.Parameters.Clear();
332 } 331 }
@@ -337,14 +336,16 @@ namespace OpenSim.Data.MSSQL
337 { 336 {
338 //Delete first 337 //Delete first
339 string sql = string.Format("delete from {0} where EstateID = @EstateID", table); 338 string sql = string.Format("delete from {0} where EstateID = @EstateID", table);
340 using (AutoClosingSqlCommand cmd = _Database.Query(sql)) 339 using (SqlConnection conn = new SqlConnection(m_connectionString))
340 using (SqlCommand cmd = new SqlCommand(sql, conn))
341 { 341 {
342 cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID)); 342 cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID));
343 cmd.ExecuteNonQuery(); 343 cmd.ExecuteNonQuery();
344 } 344 }
345 345
346 sql = string.Format("insert into {0} (EstateID, uuid) values ( @EstateID, @uuid )", table); 346 sql = string.Format("insert into {0} (EstateID, uuid) values ( @EstateID, @uuid )", table);
347 using (AutoClosingSqlCommand cmd = _Database.Query(sql)) 347 using (SqlConnection conn = new SqlConnection(m_connectionString))
348 using (SqlCommand cmd = new SqlCommand(sql, conn))
348 { 349 {
349 cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID)); 350 cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID));
350 351
@@ -359,7 +360,7 @@ namespace OpenSim.Data.MSSQL
359 } 360 }
360 else 361 else
361 cmd.Parameters["@uuid"].Value = uuid.Guid; //.ToString(); //TODO check if this works 362 cmd.Parameters["@uuid"].Value = uuid.Guid; //.ToString(); //TODO check if this works
362 363 conn.Open();
363 cmd.ExecuteNonQuery(); 364 cmd.ExecuteNonQuery();
364 } 365 }
365 } 366 }