aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL/MySQLEstateData.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2009-11-03 19:11:09 +0000
committerJustin Clark-Casey (justincc)2009-11-03 19:11:09 +0000
commitaf0e5d097480de264e7501e7d5d35328be5640bb (patch)
tree4ca5cd796ed9618dc9134a6e5eee1f7e7912bee4 /OpenSim/Data/MySQL/MySQLEstateData.cs
parentminor: remove some mono compiler warnings (diff)
parentFixed a couple of NREs in corner cases. (diff)
downloadopensim-SC_OLD-af0e5d097480de264e7501e7d5d35328be5640bb.zip
opensim-SC_OLD-af0e5d097480de264e7501e7d5d35328be5640bb.tar.gz
opensim-SC_OLD-af0e5d097480de264e7501e7d5d35328be5640bb.tar.bz2
opensim-SC_OLD-af0e5d097480de264e7501e7d5d35328be5640bb.tar.xz
Merge branch 'master' of ssh://justincc@opensimulator.org/var/git/opensim
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLEstateData.cs')
-rw-r--r--OpenSim/Data/MySQL/MySQLEstateData.cs310
1 files changed, 158 insertions, 152 deletions
diff --git a/OpenSim/Data/MySQL/MySQLEstateData.cs b/OpenSim/Data/MySQL/MySQLEstateData.cs
index 7166b29..e8694fc 100644
--- a/OpenSim/Data/MySQL/MySQLEstateData.cs
+++ b/OpenSim/Data/MySQL/MySQLEstateData.cs
@@ -95,17 +95,21 @@ namespace OpenSim.Data.MySQL
95 95
96 protected void GetWaitTimeout() 96 protected void GetWaitTimeout()
97 { 97 {
98 using (MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect, m_connection)) 98 MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect,
99 m_connection);
100
101 using (MySqlDataReader dbReader =
102 cmd.ExecuteReader(CommandBehavior.SingleRow))
99 { 103 {
100 using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow)) 104 if (dbReader.Read())
101 { 105 {
102 if (dbReader.Read()) 106 m_waitTimeout
103 { 107 = Convert.ToInt32(dbReader["@@wait_timeout"]) *
104 m_waitTimeout 108 TimeSpan.TicksPerSecond + m_waitTimeoutLeeway;
105 = Convert.ToInt32(dbReader["@@wait_timeout"]) *
106 TimeSpan.TicksPerSecond + m_waitTimeoutLeeway;
107 }
108 } 109 }
110
111 dbReader.Close();
112 cmd.Dispose();
109 } 113 }
110 114
111 m_lastConnectionUse = DateTime.Now.Ticks; 115 m_lastConnectionUse = DateTime.Now.Ticks;
@@ -143,103 +147,110 @@ namespace OpenSim.Data.MySQL
143 147
144 CheckConnection(); 148 CheckConnection();
145 149
146 bool migration = true; 150 MySqlCommand cmd = m_connection.CreateCommand();
147 151
148 using (MySqlCommand cmd = m_connection.CreateCommand()) 152 cmd.CommandText = sql;
149 { 153 cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
150 cmd.CommandText = sql; 154
151 cmd.Parameters.AddWithValue("?RegionID", regionID.ToString()); 155 IDataReader r = cmd.ExecuteReader();
152 156
153 using (IDataReader r = cmd.ExecuteReader()) 157 if (r.Read())
158 {
159 foreach (string name in FieldList)
154 { 160 {
155 if (r.Read()) 161 if (m_FieldMap[name].GetValue(es) is bool)
156 { 162 {
157 migration = false; 163 int v = Convert.ToInt32(r[name]);
158 164 if (v != 0)
159 foreach (string name in FieldList) 165 m_FieldMap[name].SetValue(es, true);
160 { 166 else
161 if (m_FieldMap[name].GetValue(es) is bool) 167 m_FieldMap[name].SetValue(es, false);
162 { 168 }
163 int v = Convert.ToInt32(r[name]); 169 else if (m_FieldMap[name].GetValue(es) is UUID)
164 if (v != 0) 170 {
165 m_FieldMap[name].SetValue(es, true); 171 UUID uuid = UUID.Zero;
166 else 172
167 m_FieldMap[name].SetValue(es, false); 173 UUID.TryParse(r[name].ToString(), out uuid);
168 } 174 m_FieldMap[name].SetValue(es, uuid);
169 else if (m_FieldMap[name].GetValue(es) is UUID) 175 }
170 { 176 else
171 UUID uuid = UUID.Zero; 177 {
172 178 m_FieldMap[name].SetValue(es, r[name]);
173 UUID.TryParse(r[name].ToString(), out uuid);
174 m_FieldMap[name].SetValue(es, uuid);
175 }
176 else
177 {
178 m_FieldMap[name].SetValue(es, r[name]);
179 }
180 }
181 } 179 }
182 } 180 }
181 r.Close();
183 } 182 }
184 183 else
185 if (migration)
186 { 184 {
187 // Migration case 185 // Migration case
186 //
187 r.Close();
188
188 List<string> names = new List<string>(FieldList); 189 List<string> names = new List<string>(FieldList);
189 190
190 names.Remove("EstateID"); 191 names.Remove("EstateID");
191 192
192 sql = "insert into estate_settings (" + String.Join(",", names.ToArray()) + ") values ( ?" + String.Join(", ?", names.ToArray()) + ")"; 193 sql = "insert into estate_settings (" + String.Join(",", names.ToArray()) + ") values ( ?" + String.Join(", ?", names.ToArray()) + ")";
193 194
194 using (MySqlCommand cmd = m_connection.CreateCommand()) 195 cmd.CommandText = sql;
195 { 196 cmd.Parameters.Clear();
196 cmd.CommandText = sql;
197 cmd.Parameters.Clear();
198 197
199 foreach (string name in FieldList) 198 foreach (string name in FieldList)
199 {
200 if (m_FieldMap[name].GetValue(es) is bool)
200 { 201 {
201 if (m_FieldMap[name].GetValue(es) is bool) 202 if ((bool)m_FieldMap[name].GetValue(es))
202 { 203 cmd.Parameters.AddWithValue("?" + name, "1");
203 if ((bool)m_FieldMap[name].GetValue(es))
204 cmd.Parameters.AddWithValue("?" + name, "1");
205 else
206 cmd.Parameters.AddWithValue("?" + name, "0");
207 }
208 else 204 else
209 { 205 cmd.Parameters.AddWithValue("?" + name, "0");
210 cmd.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString());
211 }
212 } 206 }
207 else
208 {
209 cmd.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString());
210 }
211 }
213 212
214 cmd.ExecuteNonQuery(); 213 cmd.ExecuteNonQuery();
215 214
216 cmd.CommandText = "select LAST_INSERT_ID() as id"; 215 cmd.CommandText = "select LAST_INSERT_ID() as id";
217 cmd.Parameters.Clear(); 216 cmd.Parameters.Clear();
218 217
219 using (IDataReader r = cmd.ExecuteReader()) 218 r = cmd.ExecuteReader();
220 { 219
221 r.Read(); 220 r.Read();
222 es.EstateID = Convert.ToUInt32(r["id"]);
223 }
224 221
225 cmd.CommandText = "insert into estate_map values (?RegionID, ?EstateID)"; 222 es.EstateID = Convert.ToUInt32(r["id"]);
226 cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
227 cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString());
228 223
229 // This will throw on dupe key 224 r.Close();
230 try { cmd.ExecuteNonQuery(); } 225
231 catch (Exception) { } 226 cmd.CommandText = "insert into estate_map values (?RegionID, ?EstateID)";
227 cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
228 cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString());
232 229
233 // Munge and transfer the ban list 230 // This will throw on dupe key
234 cmd.Parameters.Clear(); 231 try
235 cmd.CommandText = "insert into estateban select " + es.EstateID.ToString() + ", bannedUUID, bannedIp, bannedIpHostMask, '' from regionban where regionban.regionUUID = ?UUID"; 232 {
236 cmd.Parameters.AddWithValue("?UUID", regionID.ToString()); 233 cmd.ExecuteNonQuery();
234 }
235 catch (Exception)
236 {
237 }
237 238
238 try { cmd.ExecuteNonQuery(); } 239 // Munge and transfer the ban list
239 catch (Exception) { } 240 //
241 cmd.Parameters.Clear();
242 cmd.CommandText = "insert into estateban select " + es.EstateID.ToString() + ", bannedUUID, bannedIp, bannedIpHostMask, '' from regionban where regionban.regionUUID = ?UUID";
243 cmd.Parameters.AddWithValue("?UUID", regionID.ToString());
240 244
241 es.Save(); 245 try
246 {
247 cmd.ExecuteNonQuery();
248 }
249 catch (Exception)
250 {
242 } 251 }
252
253 es.Save();
243 } 254 }
244 255
245 LoadBanList(es); 256 LoadBanList(es);
@@ -256,28 +267,27 @@ namespace OpenSim.Data.MySQL
256 267
257 CheckConnection(); 268 CheckConnection();
258 269
259 using (MySqlCommand cmd = m_connection.CreateCommand()) 270 MySqlCommand cmd = m_connection.CreateCommand();
260 {
261 cmd.CommandText = sql;
262 271
263 foreach (string name in FieldList) 272 cmd.CommandText = sql;
273
274 foreach (string name in FieldList)
275 {
276 if (m_FieldMap[name].GetValue(es) is bool)
264 { 277 {
265 if (m_FieldMap[name].GetValue(es) is bool) 278 if ((bool)m_FieldMap[name].GetValue(es))
266 { 279 cmd.Parameters.AddWithValue("?" + name, "1");
267 if ((bool)m_FieldMap[name].GetValue(es))
268 cmd.Parameters.AddWithValue("?" + name, "1");
269 else
270 cmd.Parameters.AddWithValue("?" + name, "0");
271 }
272 else 280 else
273 { 281 cmd.Parameters.AddWithValue("?" + name, "0");
274 cmd.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString()); 282 }
275 } 283 else
284 {
285 cmd.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString());
276 } 286 }
277
278 cmd.ExecuteNonQuery();
279 } 287 }
280 288
289 cmd.ExecuteNonQuery();
290
281 SaveBanList(es); 291 SaveBanList(es);
282 SaveUUIDList(es.EstateID, "estate_managers", es.EstateManagers); 292 SaveUUIDList(es.EstateID, "estate_managers", es.EstateManagers);
283 SaveUUIDList(es.EstateID, "estate_users", es.EstateAccess); 293 SaveUUIDList(es.EstateID, "estate_users", es.EstateAccess);
@@ -290,52 +300,50 @@ namespace OpenSim.Data.MySQL
290 300
291 CheckConnection(); 301 CheckConnection();
292 302
293 using (MySqlCommand cmd = m_connection.CreateCommand()) 303 MySqlCommand cmd = m_connection.CreateCommand();
294 {
295 cmd.CommandText = "select bannedUUID from estateban where EstateID = ?EstateID";
296 cmd.Parameters.AddWithValue("?EstateID", es.EstateID);
297 304
298 using (IDataReader r = cmd.ExecuteReader()) 305 cmd.CommandText = "select bannedUUID from estateban where EstateID = ?EstateID";
299 { 306 cmd.Parameters.AddWithValue("?EstateID", es.EstateID);
300 while (r.Read())
301 {
302 EstateBan eb = new EstateBan();
303 307
304 UUID uuid = new UUID(); 308 IDataReader r = cmd.ExecuteReader();
305 UUID.TryParse(r["bannedUUID"].ToString(), out uuid);
306 309
307 eb.BannedUserID = uuid; 310 while (r.Read())
308 eb.BannedHostAddress = "0.0.0.0"; 311 {
309 eb.BannedHostIPMask = "0.0.0.0"; 312 EstateBan eb = new EstateBan();
310 es.AddBan(eb); 313
311 } 314 UUID uuid = new UUID();
312 } 315 UUID.TryParse(r["bannedUUID"].ToString(), out uuid);
316
317 eb.BannedUserID = uuid;
318 eb.BannedHostAddress = "0.0.0.0";
319 eb.BannedHostIPMask = "0.0.0.0";
320 es.AddBan(eb);
313 } 321 }
322 r.Close();
314 } 323 }
315 324
316 private void SaveBanList(EstateSettings es) 325 private void SaveBanList(EstateSettings es)
317 { 326 {
318 CheckConnection(); 327 CheckConnection();
319 328
320 using (MySqlCommand cmd = m_connection.CreateCommand()) 329 MySqlCommand cmd = m_connection.CreateCommand();
321 {
322 cmd.CommandText = "delete from estateban where EstateID = ?EstateID";
323 cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString());
324 330
325 cmd.ExecuteNonQuery(); 331 cmd.CommandText = "delete from estateban where EstateID = ?EstateID";
332 cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString());
326 333
327 cmd.Parameters.Clear(); 334 cmd.ExecuteNonQuery();
328 335
329 cmd.CommandText = "insert into estateban (EstateID, bannedUUID, bannedIp, bannedIpHostMask, bannedNameMask) values ( ?EstateID, ?bannedUUID, '', '', '' )"; 336 cmd.Parameters.Clear();
330 337
331 foreach (EstateBan b in es.EstateBans) 338 cmd.CommandText = "insert into estateban (EstateID, bannedUUID, bannedIp, bannedIpHostMask, bannedNameMask) values ( ?EstateID, ?bannedUUID, '', '', '' )";
332 {
333 cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString());
334 cmd.Parameters.AddWithValue("?bannedUUID", b.BannedUserID.ToString());
335 339
336 cmd.ExecuteNonQuery(); 340 foreach (EstateBan b in es.EstateBans)
337 cmd.Parameters.Clear(); 341 {
338 } 342 cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString());
343 cmd.Parameters.AddWithValue("?bannedUUID", b.BannedUserID.ToString());
344
345 cmd.ExecuteNonQuery();
346 cmd.Parameters.Clear();
339 } 347 }
340 } 348 }
341 349
@@ -343,25 +351,24 @@ namespace OpenSim.Data.MySQL
343 { 351 {
344 CheckConnection(); 352 CheckConnection();
345 353
346 using (MySqlCommand cmd = m_connection.CreateCommand()) 354 MySqlCommand cmd = m_connection.CreateCommand();
347 {
348 cmd.CommandText = "delete from " + table + " where EstateID = ?EstateID";
349 cmd.Parameters.AddWithValue("?EstateID", EstateID.ToString());
350 355
351 cmd.ExecuteNonQuery(); 356 cmd.CommandText = "delete from " + table + " where EstateID = ?EstateID";
357 cmd.Parameters.AddWithValue("?EstateID", EstateID.ToString());
352 358
353 cmd.Parameters.Clear(); 359 cmd.ExecuteNonQuery();
354 360
355 cmd.CommandText = "insert into " + table + " (EstateID, uuid) values ( ?EstateID, ?uuid )"; 361 cmd.Parameters.Clear();
356 362
357 foreach (UUID uuid in data) 363 cmd.CommandText = "insert into " + table + " (EstateID, uuid) values ( ?EstateID, ?uuid )";
358 {
359 cmd.Parameters.AddWithValue("?EstateID", EstateID.ToString());
360 cmd.Parameters.AddWithValue("?uuid", uuid.ToString());
361 364
362 cmd.ExecuteNonQuery(); 365 foreach (UUID uuid in data)
363 cmd.Parameters.Clear(); 366 {
364 } 367 cmd.Parameters.AddWithValue("?EstateID", EstateID.ToString());
368 cmd.Parameters.AddWithValue("?uuid", uuid.ToString());
369
370 cmd.ExecuteNonQuery();
371 cmd.Parameters.Clear();
365 } 372 }
366 } 373 }
367 374
@@ -371,24 +378,23 @@ namespace OpenSim.Data.MySQL
371 378
372 CheckConnection(); 379 CheckConnection();
373 380
374 using (MySqlCommand cmd = m_connection.CreateCommand()) 381 MySqlCommand cmd = m_connection.CreateCommand();
375 {
376 cmd.CommandText = "select uuid from " + table + " where EstateID = ?EstateID";
377 cmd.Parameters.AddWithValue("?EstateID", EstateID);
378 382
379 using (IDataReader r = cmd.ExecuteReader()) 383 cmd.CommandText = "select uuid from " + table + " where EstateID = ?EstateID";
380 { 384 cmd.Parameters.AddWithValue("?EstateID", EstateID);
381 while (r.Read())
382 {
383 // EstateBan eb = new EstateBan();
384 385
385 UUID uuid = new UUID(); 386 IDataReader r = cmd.ExecuteReader();
386 UUID.TryParse(r["uuid"].ToString(), out uuid);
387 387
388 uuids.Add(uuid); 388 while (r.Read())
389 } 389 {
390 } 390 // EstateBan eb = new EstateBan();
391
392 UUID uuid = new UUID();
393 UUID.TryParse(r["uuid"].ToString(), out uuid);
394
395 uuids.Add(uuid);
391 } 396 }
397 r.Close();
392 398
393 return uuids.ToArray(); 399 return uuids.ToArray();
394 } 400 }