aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL/MySQLLegacyRegionData.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Data/MySQL/MySQLLegacyRegionData.cs1075
1 files changed, 560 insertions, 515 deletions
diff --git a/OpenSim/Data/MySQL/MySQLLegacyRegionData.cs b/OpenSim/Data/MySQL/MySQLLegacyRegionData.cs
index e57e929..f84beb6 100644
--- a/OpenSim/Data/MySQL/MySQLLegacyRegionData.cs
+++ b/OpenSim/Data/MySQL/MySQLLegacyRegionData.cs
@@ -48,75 +48,54 @@ namespace OpenSim.Data.MySQL
48 { 48 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50 50
51 private string m_ConnectionString; 51 private string m_connectionString;
52 52 private object m_dbLock = new object();
53 private MySqlConnection m_Connection = null;
54 53
55 public void Initialise(string connectionString) 54 public void Initialise(string connectionString)
56 { 55 {
57 m_ConnectionString = connectionString; 56 m_connectionString = connectionString;
58 57
59 m_Connection = new MySqlConnection(m_ConnectionString); 58 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
59 {
60 dbcon.Open();
60 61
61 m_Connection.Open(); 62 // Apply new Migrations
63 //
64 Assembly assem = GetType().Assembly;
65 Migration m = new Migration(dbcon, assem, "RegionStore");
66 m.Update();
62 67
63 // Apply new Migrations 68 // Clean dropped attachments
64 // 69 //
65 Assembly assem = GetType().Assembly; 70 try
66 Migration m = new Migration(m_Connection, assem, "RegionStore"); 71 {
67 m.Update(); 72 using (MySqlCommand cmd = dbcon.CreateCommand())
68 73 {
69 // NOTE: This is a very slow query that times out on regions with a lot of prims. 74 cmd.CommandText = "delete from prims, primshapes using prims " +
70 // I'm told that it is no longer relevant so it's commented out now, but if it 75 "left join primshapes on prims.uuid = primshapes.uuid " +
71 // is relevant it should be added as a console command instead of part of the 76 "where PCode = 9 and State <> 0";
72 // startup phase 77 ExecuteNonQuery(cmd);
73 // Clean dropped attachments 78 }
74 // 79 }
75 //try 80 catch (MySqlException ex)
76 //{ 81 {
77 // using (MySqlCommand cmd = m_Connection.CreateCommand()) 82 m_log.Error("[REGION DB]: Error cleaning up dropped attachments: " + ex.Message);
78 // { 83 }
79 // cmd.CommandText = "delete from prims, primshapes using prims " + 84 }
80 // "left join primshapes on prims.uuid = primshapes.uuid " +
81 // "where PCode = 9 and State <> 0";
82 // ExecuteNonQuery(cmd);
83 // }
84 //}
85 //catch (MySqlException ex)
86 //{
87 // m_log.Error("[REGION DB]: Error cleaning up dropped attachments: " + ex.Message);
88 //}
89 } 85 }
90 86
91 private IDataReader ExecuteReader(MySqlCommand c) 87 private IDataReader ExecuteReader(MySqlCommand c)
92 { 88 {
93 IDataReader r = null; 89 IDataReader r = null;
94 bool errorSeen = false;
95 90
96 while (true) 91 try
97 { 92 {
98 try 93 r = c.ExecuteReader();
99 { 94 }
100 r = c.ExecuteReader(); 95 catch (Exception e)
101 } 96 {
102 catch (Exception) 97 m_log.Error("[REGION DB]: MySQL error in ExecuteReader: " + e.Message);
103 { 98 throw;
104 Thread.Sleep(500);
105
106 m_Connection.Close();
107 m_Connection = (MySqlConnection) ((ICloneable)m_Connection).Clone();
108 m_Connection.Open();
109 c.Connection = m_Connection;
110
111 if (!errorSeen)
112 {
113 errorSeen = true;
114 continue;
115 }
116 throw;
117 }
118
119 break;
120 } 99 }
121 100
122 return r; 101 return r;
@@ -124,32 +103,14 @@ namespace OpenSim.Data.MySQL
124 103
125 private void ExecuteNonQuery(MySqlCommand c) 104 private void ExecuteNonQuery(MySqlCommand c)
126 { 105 {
127 bool errorSeen = false; 106 try
128
129 while (true)
130 { 107 {
131 try 108 c.ExecuteNonQuery();
132 { 109 }
133 c.ExecuteNonQuery(); 110 catch (Exception e)
134 } 111 {
135 catch (Exception) 112 m_log.Error("[REGION DB]: MySQL error in ExecuteNonQuery: " + e.Message);
136 { 113 throw;
137 Thread.Sleep(500);
138
139 m_Connection.Close();
140 m_Connection = (MySqlConnection) ((ICloneable)m_Connection).Clone();
141 m_Connection.Open();
142 c.Connection = m_Connection;
143
144 if (!errorSeen)
145 {
146 errorSeen = true;
147 continue;
148 }
149 throw;
150 }
151
152 break;
153 } 114 }
154 } 115 }
155 116
@@ -166,115 +127,119 @@ namespace OpenSim.Data.MySQL
166 if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0) 127 if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0)
167 return; 128 return;
168 129
169 lock (m_Connection) 130 lock (m_dbLock)
170 { 131 {
171 MySqlCommand cmd = m_Connection.CreateCommand(); 132 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
172
173 foreach (SceneObjectPart prim in obj.Children.Values)
174 { 133 {
175 cmd.Parameters.Clear(); 134 dbcon.Open();
176 135 MySqlCommand cmd = dbcon.CreateCommand();
177 cmd.CommandText = "replace into prims ("+
178 "UUID, CreationDate, "+
179 "Name, Text, Description, "+
180 "SitName, TouchName, ObjectFlags, "+
181 "OwnerMask, NextOwnerMask, GroupMask, "+
182 "EveryoneMask, BaseMask, PositionX, "+
183 "PositionY, PositionZ, GroupPositionX, "+
184 "GroupPositionY, GroupPositionZ, VelocityX, "+
185 "VelocityY, VelocityZ, AngularVelocityX, "+
186 "AngularVelocityY, AngularVelocityZ, "+
187 "AccelerationX, AccelerationY, "+
188 "AccelerationZ, RotationX, "+
189 "RotationY, RotationZ, "+
190 "RotationW, SitTargetOffsetX, "+
191 "SitTargetOffsetY, SitTargetOffsetZ, "+
192 "SitTargetOrientW, SitTargetOrientX, "+
193 "SitTargetOrientY, SitTargetOrientZ, "+
194 "RegionUUID, CreatorID, "+
195 "OwnerID, GroupID, "+
196 "LastOwnerID, SceneGroupID, "+
197 "PayPrice, PayButton1, "+
198 "PayButton2, PayButton3, "+
199 "PayButton4, LoopedSound, "+
200 "LoopedSoundGain, TextureAnimation, "+
201 "OmegaX, OmegaY, OmegaZ, "+
202 "CameraEyeOffsetX, CameraEyeOffsetY, "+
203 "CameraEyeOffsetZ, CameraAtOffsetX, "+
204 "CameraAtOffsetY, CameraAtOffsetZ, "+
205 "ForceMouselook, ScriptAccessPin, "+
206 "AllowedDrop, DieAtEdge, "+
207 "SalePrice, SaleType, "+
208 "ColorR, ColorG, ColorB, ColorA, "+
209 "ParticleSystem, ClickAction, Material, "+
210 "CollisionSound, CollisionSoundVolume, "+
211 "PassTouches, "+
212 "LinkNumber) values (" + "?UUID, "+
213 "?CreationDate, ?Name, ?Text, "+
214 "?Description, ?SitName, ?TouchName, "+
215 "?ObjectFlags, ?OwnerMask, ?NextOwnerMask, "+
216 "?GroupMask, ?EveryoneMask, ?BaseMask, "+
217 "?PositionX, ?PositionY, ?PositionZ, "+
218 "?GroupPositionX, ?GroupPositionY, "+
219 "?GroupPositionZ, ?VelocityX, "+
220 "?VelocityY, ?VelocityZ, ?AngularVelocityX, "+
221 "?AngularVelocityY, ?AngularVelocityZ, "+
222 "?AccelerationX, ?AccelerationY, "+
223 "?AccelerationZ, ?RotationX, "+
224 "?RotationY, ?RotationZ, "+
225 "?RotationW, ?SitTargetOffsetX, "+
226 "?SitTargetOffsetY, ?SitTargetOffsetZ, "+
227 "?SitTargetOrientW, ?SitTargetOrientX, "+
228 "?SitTargetOrientY, ?SitTargetOrientZ, "+
229 "?RegionUUID, ?CreatorID, ?OwnerID, "+
230 "?GroupID, ?LastOwnerID, ?SceneGroupID, "+
231 "?PayPrice, ?PayButton1, ?PayButton2, "+
232 "?PayButton3, ?PayButton4, ?LoopedSound, "+
233 "?LoopedSoundGain, ?TextureAnimation, "+
234 "?OmegaX, ?OmegaY, ?OmegaZ, "+
235 "?CameraEyeOffsetX, ?CameraEyeOffsetY, "+
236 "?CameraEyeOffsetZ, ?CameraAtOffsetX, "+
237 "?CameraAtOffsetY, ?CameraAtOffsetZ, "+
238 "?ForceMouselook, ?ScriptAccessPin, "+
239 "?AllowedDrop, ?DieAtEdge, ?SalePrice, "+
240 "?SaleType, ?ColorR, ?ColorG, "+
241 "?ColorB, ?ColorA, ?ParticleSystem, "+
242 "?ClickAction, ?Material, ?CollisionSound, "+
243 "?CollisionSoundVolume, ?PassTouches, ?LinkNumber)";
244
245 FillPrimCommand(cmd, prim, obj.UUID, regionUUID);
246 136
247 ExecuteNonQuery(cmd); 137 foreach (SceneObjectPart prim in obj.Children.Values)
138 {
139 cmd.Parameters.Clear();
248 140
249 cmd.Parameters.Clear(); 141 cmd.CommandText = "replace into prims (" +
250 142 "UUID, CreationDate, " +
251 cmd.CommandText = "replace into primshapes ("+ 143 "Name, Text, Description, " +
252 "UUID, Shape, ScaleX, ScaleY, "+ 144 "SitName, TouchName, ObjectFlags, " +
253 "ScaleZ, PCode, PathBegin, PathEnd, "+ 145 "OwnerMask, NextOwnerMask, GroupMask, " +
254 "PathScaleX, PathScaleY, PathShearX, "+ 146 "EveryoneMask, BaseMask, PositionX, " +
255 "PathShearY, PathSkew, PathCurve, "+ 147 "PositionY, PositionZ, GroupPositionX, " +
256 "PathRadiusOffset, PathRevolutions, "+ 148 "GroupPositionY, GroupPositionZ, VelocityX, " +
257 "PathTaperX, PathTaperY, PathTwist, "+ 149 "VelocityY, VelocityZ, AngularVelocityX, " +
258 "PathTwistBegin, ProfileBegin, ProfileEnd, "+ 150 "AngularVelocityY, AngularVelocityZ, " +
259 "ProfileCurve, ProfileHollow, Texture, "+ 151 "AccelerationX, AccelerationY, " +
260 "ExtraParams, State) values (?UUID, "+ 152 "AccelerationZ, RotationX, " +
261 "?Shape, ?ScaleX, ?ScaleY, ?ScaleZ, "+ 153 "RotationY, RotationZ, " +
262 "?PCode, ?PathBegin, ?PathEnd, "+ 154 "RotationW, SitTargetOffsetX, " +
263 "?PathScaleX, ?PathScaleY, "+ 155 "SitTargetOffsetY, SitTargetOffsetZ, " +
264 "?PathShearX, ?PathShearY, "+ 156 "SitTargetOrientW, SitTargetOrientX, " +
265 "?PathSkew, ?PathCurve, ?PathRadiusOffset, "+ 157 "SitTargetOrientY, SitTargetOrientZ, " +
266 "?PathRevolutions, ?PathTaperX, "+ 158 "RegionUUID, CreatorID, " +
267 "?PathTaperY, ?PathTwist, "+ 159 "OwnerID, GroupID, " +
268 "?PathTwistBegin, ?ProfileBegin, "+ 160 "LastOwnerID, SceneGroupID, " +
269 "?ProfileEnd, ?ProfileCurve, "+ 161 "PayPrice, PayButton1, " +
270 "?ProfileHollow, ?Texture, ?ExtraParams, "+ 162 "PayButton2, PayButton3, " +
271 "?State)"; 163 "PayButton4, LoopedSound, " +
272 164 "LoopedSoundGain, TextureAnimation, " +
273 FillShapeCommand(cmd, prim); 165 "OmegaX, OmegaY, OmegaZ, " +
166 "CameraEyeOffsetX, CameraEyeOffsetY, " +
167 "CameraEyeOffsetZ, CameraAtOffsetX, " +
168 "CameraAtOffsetY, CameraAtOffsetZ, " +
169 "ForceMouselook, ScriptAccessPin, " +
170 "AllowedDrop, DieAtEdge, " +
171 "SalePrice, SaleType, " +
172 "ColorR, ColorG, ColorB, ColorA, " +
173 "ParticleSystem, ClickAction, Material, " +
174 "CollisionSound, CollisionSoundVolume, " +
175 "PassTouches, " +
176 "LinkNumber) values (" + "?UUID, " +
177 "?CreationDate, ?Name, ?Text, " +
178 "?Description, ?SitName, ?TouchName, " +
179 "?ObjectFlags, ?OwnerMask, ?NextOwnerMask, " +
180 "?GroupMask, ?EveryoneMask, ?BaseMask, " +
181 "?PositionX, ?PositionY, ?PositionZ, " +
182 "?GroupPositionX, ?GroupPositionY, " +
183 "?GroupPositionZ, ?VelocityX, " +
184 "?VelocityY, ?VelocityZ, ?AngularVelocityX, " +
185 "?AngularVelocityY, ?AngularVelocityZ, " +
186 "?AccelerationX, ?AccelerationY, " +
187 "?AccelerationZ, ?RotationX, " +
188 "?RotationY, ?RotationZ, " +
189 "?RotationW, ?SitTargetOffsetX, " +
190 "?SitTargetOffsetY, ?SitTargetOffsetZ, " +
191 "?SitTargetOrientW, ?SitTargetOrientX, " +
192 "?SitTargetOrientY, ?SitTargetOrientZ, " +
193 "?RegionUUID, ?CreatorID, ?OwnerID, " +
194 "?GroupID, ?LastOwnerID, ?SceneGroupID, " +
195 "?PayPrice, ?PayButton1, ?PayButton2, " +
196 "?PayButton3, ?PayButton4, ?LoopedSound, " +
197 "?LoopedSoundGain, ?TextureAnimation, " +
198 "?OmegaX, ?OmegaY, ?OmegaZ, " +
199 "?CameraEyeOffsetX, ?CameraEyeOffsetY, " +
200 "?CameraEyeOffsetZ, ?CameraAtOffsetX, " +
201 "?CameraAtOffsetY, ?CameraAtOffsetZ, " +
202 "?ForceMouselook, ?ScriptAccessPin, " +
203 "?AllowedDrop, ?DieAtEdge, ?SalePrice, " +
204 "?SaleType, ?ColorR, ?ColorG, " +
205 "?ColorB, ?ColorA, ?ParticleSystem, " +
206 "?ClickAction, ?Material, ?CollisionSound, " +
207 "?CollisionSoundVolume, ?PassTouches, ?LinkNumber)";
208
209 FillPrimCommand(cmd, prim, obj.UUID, regionUUID);
274 210
275 ExecuteNonQuery(cmd); 211 ExecuteNonQuery(cmd);
212
213 cmd.Parameters.Clear();
214
215 cmd.CommandText = "replace into primshapes (" +
216 "UUID, Shape, ScaleX, ScaleY, " +
217 "ScaleZ, PCode, PathBegin, PathEnd, " +
218 "PathScaleX, PathScaleY, PathShearX, " +
219 "PathShearY, PathSkew, PathCurve, " +
220 "PathRadiusOffset, PathRevolutions, " +
221 "PathTaperX, PathTaperY, PathTwist, " +
222 "PathTwistBegin, ProfileBegin, ProfileEnd, " +
223 "ProfileCurve, ProfileHollow, Texture, " +
224 "ExtraParams, State) values (?UUID, " +
225 "?Shape, ?ScaleX, ?ScaleY, ?ScaleZ, " +
226 "?PCode, ?PathBegin, ?PathEnd, " +
227 "?PathScaleX, ?PathScaleY, " +
228 "?PathShearX, ?PathShearY, " +
229 "?PathSkew, ?PathCurve, ?PathRadiusOffset, " +
230 "?PathRevolutions, ?PathTaperX, " +
231 "?PathTaperY, ?PathTwist, " +
232 "?PathTwistBegin, ?ProfileBegin, " +
233 "?ProfileEnd, ?ProfileCurve, " +
234 "?ProfileHollow, ?Texture, ?ExtraParams, " +
235 "?State)";
236
237 FillShapeCommand(cmd, prim);
238
239 ExecuteNonQuery(cmd);
240 }
241 cmd.Dispose();
276 } 242 }
277 cmd.Dispose();
278 } 243 }
279 } 244 }
280 245
@@ -290,22 +255,27 @@ namespace OpenSim.Data.MySQL
290 // cause the loss of a prim, but is cleaner. 255 // cause the loss of a prim, but is cleaner.
291 // It's also faster because it uses the primary key. 256 // It's also faster because it uses the primary key.
292 // 257 //
293 lock (m_Connection) 258 lock (m_dbLock)
294 { 259 {
295 using (MySqlCommand cmd = m_Connection.CreateCommand()) 260 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
296 { 261 {
297 cmd.CommandText = "select UUID from prims where SceneGroupID= ?UUID"; 262 dbcon.Open();
298 cmd.Parameters.AddWithValue("UUID", obj.ToString());
299 263
300 using (IDataReader reader = ExecuteReader(cmd)) 264 using (MySqlCommand cmd = dbcon.CreateCommand())
301 { 265 {
302 while (reader.Read()) 266 cmd.CommandText = "select UUID from prims where SceneGroupID= ?UUID";
303 uuids.Add(new UUID(reader["UUID"].ToString())); 267 cmd.Parameters.AddWithValue("UUID", obj.ToString());
304 }
305 268
306 // delete the main prims 269 using (IDataReader reader = ExecuteReader(cmd))
307 cmd.CommandText = "delete from prims where SceneGroupID= ?UUID"; 270 {
308 ExecuteNonQuery(cmd); 271 while (reader.Read())
272 uuids.Add(new UUID(reader["UUID"].ToString()));
273 }
274
275 // delete the main prims
276 cmd.CommandText = "delete from prims where SceneGroupID= ?UUID";
277 ExecuteNonQuery(cmd);
278 }
309 } 279 }
310 } 280 }
311 281
@@ -326,14 +296,19 @@ namespace OpenSim.Data.MySQL
326 /// <param name="uuid">the Item UUID</param> 296 /// <param name="uuid">the Item UUID</param>
327 private void RemoveItems(UUID uuid) 297 private void RemoveItems(UUID uuid)
328 { 298 {
329 lock (m_Connection) 299 lock (m_dbLock)
330 { 300 {
331 using (MySqlCommand cmd = m_Connection.CreateCommand()) 301 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
332 { 302 {
333 cmd.CommandText = "delete from primitems where PrimID = ?PrimID"; 303 dbcon.Open();
334 cmd.Parameters.AddWithValue("PrimID", uuid.ToString());
335 304
336 ExecuteNonQuery(cmd); 305 using (MySqlCommand cmd = dbcon.CreateCommand())
306 {
307 cmd.CommandText = "delete from primitems where PrimID = ?PrimID";
308 cmd.Parameters.AddWithValue("PrimID", uuid.ToString());
309
310 ExecuteNonQuery(cmd);
311 }
337 } 312 }
338 } 313 }
339 } 314 }
@@ -345,29 +320,33 @@ namespace OpenSim.Data.MySQL
345 /// <param name="uuids">the list of UUIDs</param> 320 /// <param name="uuids">the list of UUIDs</param>
346 private void RemoveShapes(List<UUID> uuids) 321 private void RemoveShapes(List<UUID> uuids)
347 { 322 {
348 lock (m_Connection) 323 lock (m_dbLock)
349 { 324 {
350 string sql = "delete from primshapes where "; 325 string sql = "delete from primshapes where ";
351 326 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
352 using (MySqlCommand cmd = m_Connection.CreateCommand())
353 { 327 {
354 for (int i = 0; i < uuids.Count; i++) 328 dbcon.Open();
329
330 using (MySqlCommand cmd = dbcon.CreateCommand())
355 { 331 {
356 if ((i + 1) == uuids.Count) 332 for (int i = 0; i < uuids.Count; i++)
357 {// end of the list
358 sql += "(UUID = ?UUID" + i + ")";
359 }
360 else
361 { 333 {
362 sql += "(UUID = ?UUID" + i + ") or "; 334 if ((i + 1) == uuids.Count)
335 {// end of the list
336 sql += "(UUID = ?UUID" + i + ")";
337 }
338 else
339 {
340 sql += "(UUID = ?UUID" + i + ") or ";
341 }
363 } 342 }
364 } 343 cmd.CommandText = sql;
365 cmd.CommandText = sql;
366 344
367 for (int i = 0; i < uuids.Count; i++) 345 for (int i = 0; i < uuids.Count; i++)
368 cmd.Parameters.AddWithValue("UUID" + i, uuids[i].ToString()); 346 cmd.Parameters.AddWithValue("UUID" + i, uuids[i].ToString());
369 347
370 ExecuteNonQuery(cmd); 348 ExecuteNonQuery(cmd);
349 }
371 } 350 }
372 } 351 }
373 } 352 }
@@ -379,30 +358,34 @@ namespace OpenSim.Data.MySQL
379 /// <param name="uuids">the list of UUIDs</param> 358 /// <param name="uuids">the list of UUIDs</param>
380 private void RemoveItems(List<UUID> uuids) 359 private void RemoveItems(List<UUID> uuids)
381 { 360 {
382 lock (m_Connection) 361 lock (m_dbLock)
383 { 362 {
384 string sql = "delete from primitems where "; 363 string sql = "delete from primitems where ";
385 364 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
386 using (MySqlCommand cmd = m_Connection.CreateCommand())
387 { 365 {
388 for (int i = 0; i < uuids.Count; i++) 366 dbcon.Open();
367
368 using (MySqlCommand cmd = dbcon.CreateCommand())
389 { 369 {
390 if ((i + 1) == uuids.Count) 370 for (int i = 0; i < uuids.Count; i++)
391 { 371 {
392 // end of the list 372 if ((i + 1) == uuids.Count)
393 sql += "(PrimID = ?PrimID" + i + ")"; 373 {
394 } 374 // end of the list
395 else 375 sql += "(PrimID = ?PrimID" + i + ")";
396 { 376 }
397 sql += "(PrimID = ?PrimID" + i + ") or "; 377 else
378 {
379 sql += "(PrimID = ?PrimID" + i + ") or ";
380 }
398 } 381 }
399 } 382 cmd.CommandText = sql;
400 cmd.CommandText = sql;
401 383
402 for (int i = 0; i < uuids.Count; i++) 384 for (int i = 0; i < uuids.Count; i++)
403 cmd.Parameters.AddWithValue("PrimID" + i, uuids[i].ToString()); 385 cmd.Parameters.AddWithValue("PrimID" + i, uuids[i].ToString());
404 386
405 ExecuteNonQuery(cmd); 387 ExecuteNonQuery(cmd);
388 }
406 } 389 }
407 } 390 }
408 } 391 }
@@ -417,33 +400,38 @@ namespace OpenSim.Data.MySQL
417 400
418 #region Prim Loading 401 #region Prim Loading
419 402
420 lock (m_Connection) 403 lock (m_dbLock)
421 { 404 {
422 using (MySqlCommand cmd = m_Connection.CreateCommand()) 405 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
423 { 406 {
424 cmd.CommandText = 407 dbcon.Open();
425 "SELECT * FROM prims LEFT JOIN primshapes ON prims.UUID = primshapes.UUID WHERE RegionUUID = ?RegionUUID";
426 cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
427 408
428 using (IDataReader reader = ExecuteReader(cmd)) 409 using (MySqlCommand cmd = dbcon.CreateCommand())
429 { 410 {
430 while (reader.Read()) 411 cmd.CommandText =
412 "SELECT * FROM prims LEFT JOIN primshapes ON prims.UUID = primshapes.UUID WHERE RegionUUID = ?RegionUUID";
413 cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
414
415 using (IDataReader reader = ExecuteReader(cmd))
431 { 416 {
432 SceneObjectPart prim = BuildPrim(reader); 417 while (reader.Read())
433 if (reader["Shape"] is DBNull) 418 {
434 prim.Shape = PrimitiveBaseShape.Default; 419 SceneObjectPart prim = BuildPrim(reader);
435 else 420 if (reader["Shape"] is DBNull)
436 prim.Shape = BuildShape(reader); 421 prim.Shape = PrimitiveBaseShape.Default;
422 else
423 prim.Shape = BuildShape(reader);
437 424
438 UUID parentID = new UUID(reader["SceneGroupID"].ToString()); 425 UUID parentID = new UUID(reader["SceneGroupID"].ToString());
439 if (parentID != prim.UUID) 426 if (parentID != prim.UUID)
440 prim.ParentUUID = parentID; 427 prim.ParentUUID = parentID;
441 428
442 prims[prim.UUID] = prim; 429 prims[prim.UUID] = prim;
443 430
444 ++count; 431 ++count;
445 if (count % ROWS_PER_QUERY == 0) 432 if (count % ROWS_PER_QUERY == 0)
446 m_log.Debug("[REGION DB]: Loaded " + count + " prims..."); 433 m_log.Debug("[REGION DB]: Loaded " + count + " prims...");
434 }
447 } 435 }
448 } 436 }
449 } 437 }
@@ -497,20 +485,25 @@ namespace OpenSim.Data.MySQL
497 // list from DB of all prims which have items and 485 // list from DB of all prims which have items and
498 // LoadItems only on those 486 // LoadItems only on those
499 List<SceneObjectPart> primsWithInventory = new List<SceneObjectPart>(); 487 List<SceneObjectPart> primsWithInventory = new List<SceneObjectPart>();
500 lock (m_Connection) 488 lock (m_dbLock)
501 { 489 {
502 using (MySqlCommand itemCmd = m_Connection.CreateCommand()) 490 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
503 { 491 {
504 itemCmd.CommandText = "SELECT DISTINCT primID FROM primitems"; 492 dbcon.Open();
505 using (IDataReader itemReader = ExecuteReader(itemCmd)) 493
494 using (MySqlCommand itemCmd = dbcon.CreateCommand())
506 { 495 {
507 while (itemReader.Read()) 496 itemCmd.CommandText = "SELECT DISTINCT primID FROM primitems";
497 using (IDataReader itemReader = ExecuteReader(itemCmd))
508 { 498 {
509 if (!(itemReader["primID"] is DBNull)) 499 while (itemReader.Read())
510 { 500 {
511 UUID primID = new UUID(itemReader["primID"].ToString()); 501 if (!(itemReader["primID"] is DBNull))
512 if (prims.ContainsKey(primID)) 502 {
513 primsWithInventory.Add(prims[primID]); 503 UUID primID = new UUID(itemReader["primID"].ToString());
504 if (prims.ContainsKey(primID))
505 primsWithInventory.Add(prims[primID]);
506 }
514 } 507 }
515 } 508 }
516 } 509 }
@@ -535,23 +528,28 @@ namespace OpenSim.Data.MySQL
535 /// <param name="prim">The prim</param> 528 /// <param name="prim">The prim</param>
536 private void LoadItems(SceneObjectPart prim) 529 private void LoadItems(SceneObjectPart prim)
537 { 530 {
538 lock (m_Connection) 531 lock (m_dbLock)
539 { 532 {
540 List<TaskInventoryItem> inventory = new List<TaskInventoryItem>(); 533 List<TaskInventoryItem> inventory = new List<TaskInventoryItem>();
541 534
542 using (MySqlCommand cmd = m_Connection.CreateCommand()) 535 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
543 { 536 {
544 cmd.CommandText = "select * from primitems where PrimID = ?PrimID"; 537 dbcon.Open();
545 cmd.Parameters.AddWithValue("PrimID", prim.UUID.ToString());
546 538
547 using (IDataReader reader = ExecuteReader(cmd)) 539 using (MySqlCommand cmd = dbcon.CreateCommand())
548 { 540 {
549 while (reader.Read()) 541 cmd.CommandText = "select * from primitems where PrimID = ?PrimID";
542 cmd.Parameters.AddWithValue("PrimID", prim.UUID.ToString());
543
544 using (IDataReader reader = ExecuteReader(cmd))
550 { 545 {
551 TaskInventoryItem item = BuildItem(reader); 546 while (reader.Read())
547 {
548 TaskInventoryItem item = BuildItem(reader);
552 549
553 item.ParentID = prim.UUID; // Values in database are often wrong 550 item.ParentID = prim.UUID; // Values in database are often wrong
554 inventory.Add(item); 551 inventory.Add(item);
552 }
555 } 553 }
556 } 554 }
557 } 555 }
@@ -564,22 +562,27 @@ namespace OpenSim.Data.MySQL
564 { 562 {
565 m_log.Info("[REGION DB]: Storing terrain"); 563 m_log.Info("[REGION DB]: Storing terrain");
566 564
567 lock (m_Connection) 565 lock (m_dbLock)
568 { 566 {
569 using (MySqlCommand cmd = m_Connection.CreateCommand()) 567 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
570 { 568 {
571 cmd.CommandText = "delete from terrain where RegionUUID = ?RegionUUID"; 569 dbcon.Open();
572 cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
573 570
574 ExecuteNonQuery(cmd); 571 using (MySqlCommand cmd = dbcon.CreateCommand())
572 {
573 cmd.CommandText = "delete from terrain where RegionUUID = ?RegionUUID";
574 cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
575 575
576 cmd.CommandText = "insert into terrain (RegionUUID, " + 576 ExecuteNonQuery(cmd);
577 "Revision, Heightfield) values (?RegionUUID, " +
578 "1, ?Heightfield)";
579 577
580 cmd.Parameters.AddWithValue("Heightfield", SerializeTerrain(ter)); 578 cmd.CommandText = "insert into terrain (RegionUUID, " +
579 "Revision, Heightfield) values (?RegionUUID, " +
580 "1, ?Heightfield)";
581 581
582 ExecuteNonQuery(cmd); 582 cmd.Parameters.AddWithValue("Heightfield", SerializeTerrain(ter));
583
584 ExecuteNonQuery(cmd);
585 }
583 } 586 }
584 } 587 }
585 } 588 }
@@ -588,38 +591,43 @@ namespace OpenSim.Data.MySQL
588 { 591 {
589 double[,] terrain = null; 592 double[,] terrain = null;
590 593
591 lock (m_Connection) 594 lock (m_dbLock)
592 { 595 {
593 using (MySqlCommand cmd = m_Connection.CreateCommand()) 596 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
594 { 597 {
595 cmd.CommandText = "select RegionUUID, Revision, Heightfield " + 598 dbcon.Open();
596 "from terrain where RegionUUID = ?RegionUUID " +
597 "order by Revision desc limit 1";
598 cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
599 599
600 using (IDataReader reader = ExecuteReader(cmd)) 600 using (MySqlCommand cmd = dbcon.CreateCommand())
601 { 601 {
602 while (reader.Read()) 602 cmd.CommandText = "select RegionUUID, Revision, Heightfield " +
603 "from terrain where RegionUUID = ?RegionUUID " +
604 "order by Revision desc limit 1";
605 cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
606
607 using (IDataReader reader = ExecuteReader(cmd))
603 { 608 {
604 int rev = Convert.ToInt32(reader["Revision"]); 609 while (reader.Read())
610 {
611 int rev = Convert.ToInt32(reader["Revision"]);
605 612
606 terrain = new double[(int)Constants.RegionSize, (int)Constants.RegionSize]; 613 terrain = new double[(int)Constants.RegionSize, (int)Constants.RegionSize];
607 terrain.Initialize(); 614 terrain.Initialize();
608 615
609 using (MemoryStream mstr = new MemoryStream((byte[])reader["Heightfield"])) 616 using (MemoryStream mstr = new MemoryStream((byte[])reader["Heightfield"]))
610 {
611 using (BinaryReader br = new BinaryReader(mstr))
612 { 617 {
613 for (int x = 0; x < (int)Constants.RegionSize; x++) 618 using (BinaryReader br = new BinaryReader(mstr))
614 { 619 {
615 for (int y = 0; y < (int)Constants.RegionSize; y++) 620 for (int x = 0; x < (int)Constants.RegionSize; x++)
616 { 621 {
617 terrain[x, y] = br.ReadDouble(); 622 for (int y = 0; y < (int)Constants.RegionSize; y++)
623 {
624 terrain[x, y] = br.ReadDouble();
625 }
618 } 626 }
619 } 627 }
620 }
621 628
622 m_log.InfoFormat("[REGION DB]: Loaded terrain revision r{0}", rev); 629 m_log.InfoFormat("[REGION DB]: Loaded terrain revision r{0}", rev);
630 }
623 } 631 }
624 } 632 }
625 } 633 }
@@ -631,63 +639,73 @@ namespace OpenSim.Data.MySQL
631 639
632 public void RemoveLandObject(UUID globalID) 640 public void RemoveLandObject(UUID globalID)
633 { 641 {
634 lock (m_Connection) 642 lock (m_dbLock)
635 { 643 {
636 using (MySqlCommand cmd = m_Connection.CreateCommand()) 644 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
637 { 645 {
638 cmd.CommandText = "delete from land where UUID = ?UUID"; 646 dbcon.Open();
639 cmd.Parameters.AddWithValue("UUID", globalID.ToString());
640 647
641 ExecuteNonQuery(cmd); 648 using (MySqlCommand cmd = dbcon.CreateCommand())
649 {
650 cmd.CommandText = "delete from land where UUID = ?UUID";
651 cmd.Parameters.AddWithValue("UUID", globalID.ToString());
652
653 ExecuteNonQuery(cmd);
654 }
642 } 655 }
643 } 656 }
644 } 657 }
645 658
646 public void StoreLandObject(ILandObject parcel) 659 public void StoreLandObject(ILandObject parcel)
647 { 660 {
648 lock (m_Connection) 661 lock (m_dbLock)
649 { 662 {
650 using (MySqlCommand cmd = m_Connection.CreateCommand()) 663 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
651 { 664 {
652 cmd.CommandText = "replace into land (UUID, RegionUUID, " + 665 dbcon.Open();
653 "LocalLandID, Bitmap, Name, Description, " +
654 "OwnerUUID, IsGroupOwned, Area, AuctionID, " +
655 "Category, ClaimDate, ClaimPrice, GroupUUID, " +
656 "SalePrice, LandStatus, LandFlags, LandingType, " +
657 "MediaAutoScale, MediaTextureUUID, MediaURL, " +
658 "MusicURL, PassHours, PassPrice, SnapshotUUID, " +
659 "UserLocationX, UserLocationY, UserLocationZ, " +
660 "UserLookAtX, UserLookAtY, UserLookAtZ, " +
661 "AuthbuyerID, OtherCleanTime, Dwell) values (" +
662 "?UUID, ?RegionUUID, " +
663 "?LocalLandID, ?Bitmap, ?Name, ?Description, " +
664 "?OwnerUUID, ?IsGroupOwned, ?Area, ?AuctionID, " +
665 "?Category, ?ClaimDate, ?ClaimPrice, ?GroupUUID, " +
666 "?SalePrice, ?LandStatus, ?LandFlags, ?LandingType, " +
667 "?MediaAutoScale, ?MediaTextureUUID, ?MediaURL, " +
668 "?MusicURL, ?PassHours, ?PassPrice, ?SnapshotUUID, " +
669 "?UserLocationX, ?UserLocationY, ?UserLocationZ, " +
670 "?UserLookAtX, ?UserLookAtY, ?UserLookAtZ, " +
671 "?AuthbuyerID, ?OtherCleanTime, ?Dwell)";
672
673 FillLandCommand(cmd, parcel.LandData, parcel.RegionUUID);
674
675 ExecuteNonQuery(cmd);
676 666
677 cmd.CommandText = "delete from landaccesslist where LandUUID = ?UUID"; 667 using (MySqlCommand cmd = dbcon.CreateCommand())
668 {
669 cmd.CommandText = "replace into land (UUID, RegionUUID, " +
670 "LocalLandID, Bitmap, Name, Description, " +
671 "OwnerUUID, IsGroupOwned, Area, AuctionID, " +
672 "Category, ClaimDate, ClaimPrice, GroupUUID, " +
673 "SalePrice, LandStatus, LandFlags, LandingType, " +
674 "MediaAutoScale, MediaTextureUUID, MediaURL, " +
675 "MusicURL, PassHours, PassPrice, SnapshotUUID, " +
676 "UserLocationX, UserLocationY, UserLocationZ, " +
677 "UserLookAtX, UserLookAtY, UserLookAtZ, " +
678 "AuthbuyerID, OtherCleanTime, Dwell) values (" +
679 "?UUID, ?RegionUUID, " +
680 "?LocalLandID, ?Bitmap, ?Name, ?Description, " +
681 "?OwnerUUID, ?IsGroupOwned, ?Area, ?AuctionID, " +
682 "?Category, ?ClaimDate, ?ClaimPrice, ?GroupUUID, " +
683 "?SalePrice, ?LandStatus, ?LandFlags, ?LandingType, " +
684 "?MediaAutoScale, ?MediaTextureUUID, ?MediaURL, " +
685 "?MusicURL, ?PassHours, ?PassPrice, ?SnapshotUUID, " +
686 "?UserLocationX, ?UserLocationY, ?UserLocationZ, " +
687 "?UserLookAtX, ?UserLookAtY, ?UserLookAtZ, " +
688 "?AuthbuyerID, ?OtherCleanTime, ?Dwell)";
689
690 FillLandCommand(cmd, parcel.LandData, parcel.RegionUUID);
678 691
679 ExecuteNonQuery(cmd); 692 ExecuteNonQuery(cmd);
680 693
681 cmd.Parameters.Clear(); 694 cmd.CommandText = "delete from landaccesslist where LandUUID = ?UUID";
682 cmd.CommandText = "insert into landaccesslist (LandUUID, " +
683 "AccessUUID, Flags) values (?LandUUID, ?AccessUUID, " +
684 "?Flags)";
685 695
686 foreach (ParcelManager.ParcelAccessEntry entry in parcel.LandData.ParcelAccessList)
687 {
688 FillLandAccessCommand(cmd, entry, parcel.LandData.GlobalID);
689 ExecuteNonQuery(cmd); 696 ExecuteNonQuery(cmd);
697
690 cmd.Parameters.Clear(); 698 cmd.Parameters.Clear();
699 cmd.CommandText = "insert into landaccesslist (LandUUID, " +
700 "AccessUUID, Flags) values (?LandUUID, ?AccessUUID, " +
701 "?Flags)";
702
703 foreach (ParcelManager.ParcelAccessEntry entry in parcel.LandData.ParcelAccessList)
704 {
705 FillLandAccessCommand(cmd, entry, parcel.LandData.GlobalID);
706 ExecuteNonQuery(cmd);
707 cmd.Parameters.Clear();
708 }
691 } 709 }
692 } 710 }
693 } 711 }
@@ -697,88 +715,93 @@ namespace OpenSim.Data.MySQL
697 { 715 {
698 RegionMeta7WindlightData nWP = new RegionMeta7WindlightData(); 716 RegionMeta7WindlightData nWP = new RegionMeta7WindlightData();
699 nWP.OnSave += StoreRegionWindlightSettings; 717 nWP.OnSave += StoreRegionWindlightSettings;
700 lock (m_Connection) 718
719 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
701 { 720 {
702 721 dbcon.Open();
722
703 string command = "select * from `regionwindlight` where region_id = ?regionID"; 723 string command = "select * from `regionwindlight` where region_id = ?regionID";
704 724
705 MySqlCommand cmd = new MySqlCommand(command); 725 using(MySqlCommand cmd = new MySqlCommand(command))
726 {
727 cmd.Connection = dbcon;
706 728
707 cmd.Parameters.AddWithValue("?regionID", regionUUID.ToString()); 729 cmd.Parameters.AddWithValue("?regionID", regionUUID.ToString());
708 730
709 IDataReader result = ExecuteReader(cmd); 731 IDataReader result = ExecuteReader(cmd);
710 if (!result.Read()) 732 if (!result.Read())
711 { 733 {
712 //No result, so store our default windlight profile and return it 734 //No result, so store our default windlight profile and return it
713 nWP.regionID = regionUUID; 735 nWP.regionID = regionUUID;
714 StoreRegionWindlightSettings(nWP); 736 StoreRegionWindlightSettings(nWP);
715 return nWP; 737 return nWP;
716 } 738 }
717 else 739 else
718 { 740 {
719 UUID.TryParse(result["region_id"].ToString(), out nWP.regionID); 741 UUID.TryParse(result["region_id"].ToString(), out nWP.regionID);
720 nWP.waterColor.X = Convert.ToSingle(result["water_color_r"]); 742 nWP.waterColor.X = Convert.ToSingle(result["water_color_r"]);
721 nWP.waterColor.Y = Convert.ToSingle(result["water_color_g"]); 743 nWP.waterColor.Y = Convert.ToSingle(result["water_color_g"]);
722 nWP.waterColor.Z = Convert.ToSingle(result["water_color_b"]); 744 nWP.waterColor.Z = Convert.ToSingle(result["water_color_b"]);
723 nWP.waterFogDensityExponent = Convert.ToSingle(result["water_fog_density_exponent"]); 745 nWP.waterFogDensityExponent = Convert.ToSingle(result["water_fog_density_exponent"]);
724 nWP.underwaterFogModifier = Convert.ToSingle(result["underwater_fog_modifier"]); 746 nWP.underwaterFogModifier = Convert.ToSingle(result["underwater_fog_modifier"]);
725 nWP.reflectionWaveletScale.X = Convert.ToSingle(result["reflection_wavelet_scale_1"]); 747 nWP.reflectionWaveletScale.X = Convert.ToSingle(result["reflection_wavelet_scale_1"]);
726 nWP.reflectionWaveletScale.Y = Convert.ToSingle(result["reflection_wavelet_scale_2"]); 748 nWP.reflectionWaveletScale.Y = Convert.ToSingle(result["reflection_wavelet_scale_2"]);
727 nWP.reflectionWaveletScale.Z = Convert.ToSingle(result["reflection_wavelet_scale_3"]); 749 nWP.reflectionWaveletScale.Z = Convert.ToSingle(result["reflection_wavelet_scale_3"]);
728 nWP.fresnelScale = Convert.ToSingle(result["fresnel_scale"]); 750 nWP.fresnelScale = Convert.ToSingle(result["fresnel_scale"]);
729 nWP.fresnelOffset = Convert.ToSingle(result["fresnel_offset"]); 751 nWP.fresnelOffset = Convert.ToSingle(result["fresnel_offset"]);
730 nWP.refractScaleAbove = Convert.ToSingle(result["refract_scale_above"]); 752 nWP.refractScaleAbove = Convert.ToSingle(result["refract_scale_above"]);
731 nWP.refractScaleBelow = Convert.ToSingle(result["refract_scale_below"]); 753 nWP.refractScaleBelow = Convert.ToSingle(result["refract_scale_below"]);
732 nWP.blurMultiplier = Convert.ToSingle(result["blur_multiplier"]); 754 nWP.blurMultiplier = Convert.ToSingle(result["blur_multiplier"]);
733 nWP.bigWaveDirection.X = Convert.ToSingle(result["big_wave_direction_x"]); 755 nWP.bigWaveDirection.X = Convert.ToSingle(result["big_wave_direction_x"]);
734 nWP.bigWaveDirection.Y = Convert.ToSingle(result["big_wave_direction_y"]); 756 nWP.bigWaveDirection.Y = Convert.ToSingle(result["big_wave_direction_y"]);
735 nWP.littleWaveDirection.X = Convert.ToSingle(result["little_wave_direction_x"]); 757 nWP.littleWaveDirection.X = Convert.ToSingle(result["little_wave_direction_x"]);
736 nWP.littleWaveDirection.Y = Convert.ToSingle(result["little_wave_direction_y"]); 758 nWP.littleWaveDirection.Y = Convert.ToSingle(result["little_wave_direction_y"]);
737 UUID.TryParse(result["normal_map_texture"].ToString(), out nWP.normalMapTexture); 759 UUID.TryParse(result["normal_map_texture"].ToString(), out nWP.normalMapTexture);
738 nWP.horizon.X = Convert.ToSingle(result["horizon_r"]); 760 nWP.horizon.X = Convert.ToSingle(result["horizon_r"]);
739 nWP.horizon.Y = Convert.ToSingle(result["horizon_g"]); 761 nWP.horizon.Y = Convert.ToSingle(result["horizon_g"]);
740 nWP.horizon.Z = Convert.ToSingle(result["horizon_b"]); 762 nWP.horizon.Z = Convert.ToSingle(result["horizon_b"]);
741 nWP.horizon.W = Convert.ToSingle(result["horizon_i"]); 763 nWP.horizon.W = Convert.ToSingle(result["horizon_i"]);
742 nWP.hazeHorizon = Convert.ToSingle(result["haze_horizon"]); 764 nWP.hazeHorizon = Convert.ToSingle(result["haze_horizon"]);
743 nWP.blueDensity.X = Convert.ToSingle(result["blue_density_r"]); 765 nWP.blueDensity.X = Convert.ToSingle(result["blue_density_r"]);
744 nWP.blueDensity.Y = Convert.ToSingle(result["blue_density_g"]); 766 nWP.blueDensity.Y = Convert.ToSingle(result["blue_density_g"]);
745 nWP.blueDensity.Z = Convert.ToSingle(result["blue_density_b"]); 767 nWP.blueDensity.Z = Convert.ToSingle(result["blue_density_b"]);
746 nWP.blueDensity.W = Convert.ToSingle(result["blue_density_i"]); 768 nWP.blueDensity.W = Convert.ToSingle(result["blue_density_i"]);
747 nWP.hazeDensity = Convert.ToSingle(result["haze_density"]); 769 nWP.hazeDensity = Convert.ToSingle(result["haze_density"]);
748 nWP.densityMultiplier = Convert.ToSingle(result["density_multiplier"]); 770 nWP.densityMultiplier = Convert.ToSingle(result["density_multiplier"]);
749 nWP.distanceMultiplier = Convert.ToSingle(result["distance_multiplier"]); 771 nWP.distanceMultiplier = Convert.ToSingle(result["distance_multiplier"]);
750 nWP.maxAltitude = Convert.ToUInt16(result["max_altitude"]); 772 nWP.maxAltitude = Convert.ToUInt16(result["max_altitude"]);
751 nWP.sunMoonColor.X = Convert.ToSingle(result["sun_moon_color_r"]); 773 nWP.sunMoonColor.X = Convert.ToSingle(result["sun_moon_color_r"]);
752 nWP.sunMoonColor.Y = Convert.ToSingle(result["sun_moon_color_g"]); 774 nWP.sunMoonColor.Y = Convert.ToSingle(result["sun_moon_color_g"]);
753 nWP.sunMoonColor.Z = Convert.ToSingle(result["sun_moon_color_b"]); 775 nWP.sunMoonColor.Z = Convert.ToSingle(result["sun_moon_color_b"]);
754 nWP.sunMoonColor.W = Convert.ToSingle(result["sun_moon_color_i"]); 776 nWP.sunMoonColor.W = Convert.ToSingle(result["sun_moon_color_i"]);
755 nWP.sunMoonPosition = Convert.ToSingle(result["sun_moon_position"]); 777 nWP.sunMoonPosition = Convert.ToSingle(result["sun_moon_position"]);
756 nWP.ambient.X = Convert.ToSingle(result["ambient_r"]); 778 nWP.ambient.X = Convert.ToSingle(result["ambient_r"]);
757 nWP.ambient.Y = Convert.ToSingle(result["ambient_g"]); 779 nWP.ambient.Y = Convert.ToSingle(result["ambient_g"]);
758 nWP.ambient.Z = Convert.ToSingle(result["ambient_b"]); 780 nWP.ambient.Z = Convert.ToSingle(result["ambient_b"]);
759 nWP.ambient.W = Convert.ToSingle(result["ambient_i"]); 781 nWP.ambient.W = Convert.ToSingle(result["ambient_i"]);
760 nWP.eastAngle = Convert.ToSingle(result["east_angle"]); 782 nWP.eastAngle = Convert.ToSingle(result["east_angle"]);
761 nWP.sunGlowFocus = Convert.ToSingle(result["sun_glow_focus"]); 783 nWP.sunGlowFocus = Convert.ToSingle(result["sun_glow_focus"]);
762 nWP.sunGlowSize = Convert.ToSingle(result["sun_glow_size"]); 784 nWP.sunGlowSize = Convert.ToSingle(result["sun_glow_size"]);
763 nWP.sceneGamma = Convert.ToSingle(result["scene_gamma"]); 785 nWP.sceneGamma = Convert.ToSingle(result["scene_gamma"]);
764 nWP.starBrightness = Convert.ToSingle(result["star_brightness"]); 786 nWP.starBrightness = Convert.ToSingle(result["star_brightness"]);
765 nWP.cloudColor.X = Convert.ToSingle(result["cloud_color_r"]); 787 nWP.cloudColor.X = Convert.ToSingle(result["cloud_color_r"]);
766 nWP.cloudColor.Y = Convert.ToSingle(result["cloud_color_g"]); 788 nWP.cloudColor.Y = Convert.ToSingle(result["cloud_color_g"]);
767 nWP.cloudColor.Z = Convert.ToSingle(result["cloud_color_b"]); 789 nWP.cloudColor.Z = Convert.ToSingle(result["cloud_color_b"]);
768 nWP.cloudColor.W = Convert.ToSingle(result["cloud_color_i"]); 790 nWP.cloudColor.W = Convert.ToSingle(result["cloud_color_i"]);
769 nWP.cloudXYDensity.X = Convert.ToSingle(result["cloud_x"]); 791 nWP.cloudXYDensity.X = Convert.ToSingle(result["cloud_x"]);
770 nWP.cloudXYDensity.Y = Convert.ToSingle(result["cloud_y"]); 792 nWP.cloudXYDensity.Y = Convert.ToSingle(result["cloud_y"]);
771 nWP.cloudXYDensity.Z = Convert.ToSingle(result["cloud_density"]); 793 nWP.cloudXYDensity.Z = Convert.ToSingle(result["cloud_density"]);
772 nWP.cloudCoverage = Convert.ToSingle(result["cloud_coverage"]); 794 nWP.cloudCoverage = Convert.ToSingle(result["cloud_coverage"]);
773 nWP.cloudScale = Convert.ToSingle(result["cloud_scale"]); 795 nWP.cloudScale = Convert.ToSingle(result["cloud_scale"]);
774 nWP.cloudDetailXYDensity.X = Convert.ToSingle(result["cloud_detail_x"]); 796 nWP.cloudDetailXYDensity.X = Convert.ToSingle(result["cloud_detail_x"]);
775 nWP.cloudDetailXYDensity.Y = Convert.ToSingle(result["cloud_detail_y"]); 797 nWP.cloudDetailXYDensity.Y = Convert.ToSingle(result["cloud_detail_y"]);
776 nWP.cloudDetailXYDensity.Z = Convert.ToSingle(result["cloud_detail_density"]); 798 nWP.cloudDetailXYDensity.Z = Convert.ToSingle(result["cloud_detail_density"]);
777 nWP.cloudScrollX = Convert.ToSingle(result["cloud_scroll_x"]); 799 nWP.cloudScrollX = Convert.ToSingle(result["cloud_scroll_x"]);
778 nWP.cloudScrollXLock = Convert.ToBoolean(result["cloud_scroll_x_lock"]); 800 nWP.cloudScrollXLock = Convert.ToBoolean(result["cloud_scroll_x_lock"]);
779 nWP.cloudScrollY = Convert.ToSingle(result["cloud_scroll_y"]); 801 nWP.cloudScrollY = Convert.ToSingle(result["cloud_scroll_y"]);
780 nWP.cloudScrollYLock = Convert.ToBoolean(result["cloud_scroll_y_lock"]); 802 nWP.cloudScrollYLock = Convert.ToBoolean(result["cloud_scroll_y_lock"]);
781 nWP.drawClassicClouds = Convert.ToBoolean(result["draw_classic_clouds"]); 803 nWP.drawClassicClouds = Convert.ToBoolean(result["draw_classic_clouds"]);
804 }
782 } 805 }
783 } 806 }
784 return nWP; 807 return nWP;
@@ -788,27 +811,32 @@ namespace OpenSim.Data.MySQL
788 { 811 {
789 RegionSettings rs = null; 812 RegionSettings rs = null;
790 813
791 lock (m_Connection) 814 lock (m_dbLock)
792 { 815 {
793 using (MySqlCommand cmd = m_Connection.CreateCommand()) 816 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
794 { 817 {
795 cmd.CommandText = "select * from regionsettings where regionUUID = ?RegionUUID"; 818 dbcon.Open();
796 cmd.Parameters.AddWithValue("regionUUID", regionUUID);
797 819
798 using (IDataReader reader = ExecuteReader(cmd)) 820 using (MySqlCommand cmd = dbcon.CreateCommand())
799 { 821 {
800 if (reader.Read()) 822 cmd.CommandText = "select * from regionsettings where regionUUID = ?RegionUUID";
801 { 823 cmd.Parameters.AddWithValue("regionUUID", regionUUID);
802 rs = BuildRegionSettings(reader); 824
803 rs.OnSave += StoreRegionSettings; 825 using (IDataReader reader = ExecuteReader(cmd))
804 }
805 else
806 { 826 {
807 rs = new RegionSettings(); 827 if (reader.Read())
808 rs.RegionUUID = regionUUID; 828 {
809 rs.OnSave += StoreRegionSettings; 829 rs = BuildRegionSettings(reader);
830 rs.OnSave += StoreRegionSettings;
831 }
832 else
833 {
834 rs = new RegionSettings();
835 rs.RegionUUID = regionUUID;
836 rs.OnSave += StoreRegionSettings;
810 837
811 StoreRegionSettings(rs); 838 StoreRegionSettings(rs);
839 }
812 } 840 }
813 } 841 }
814 } 842 }
@@ -819,9 +847,11 @@ namespace OpenSim.Data.MySQL
819 847
820 public void StoreRegionWindlightSettings(RegionMeta7WindlightData wl) 848 public void StoreRegionWindlightSettings(RegionMeta7WindlightData wl)
821 { 849 {
822 lock (m_Connection) 850 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
823 { 851 {
824 using (MySqlCommand cmd = m_Connection.CreateCommand()) 852 dbcon.Open();
853
854 using (MySqlCommand cmd = dbcon.CreateCommand())
825 { 855 {
826 cmd.CommandText = "REPLACE INTO `regionwindlight` (`region_id`, `water_color_r`, `water_color_g`, "; 856 cmd.CommandText = "REPLACE INTO `regionwindlight` (`region_id`, `water_color_r`, `water_color_g`, ";
827 cmd.CommandText += "`water_color_b`, `water_fog_density_exponent`, `underwater_fog_modifier`, "; 857 cmd.CommandText += "`water_color_b`, `water_fog_density_exponent`, `underwater_fog_modifier`, ";
@@ -920,46 +950,51 @@ namespace OpenSim.Data.MySQL
920 950
921 public void StoreRegionSettings(RegionSettings rs) 951 public void StoreRegionSettings(RegionSettings rs)
922 { 952 {
923 lock (m_Connection) 953 lock (m_dbLock)
924 { 954 {
925 using (MySqlCommand cmd = m_Connection.CreateCommand()) 955 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
926 { 956 {
927 cmd.CommandText = "replace into regionsettings (regionUUID, " + 957 dbcon.Open();
928 "block_terraform, block_fly, allow_damage, " +
929 "restrict_pushing, allow_land_resell, " +
930 "allow_land_join_divide, block_show_in_search, " +
931 "agent_limit, object_bonus, maturity, " +
932 "disable_scripts, disable_collisions, " +
933 "disable_physics, terrain_texture_1, " +
934 "terrain_texture_2, terrain_texture_3, " +
935 "terrain_texture_4, elevation_1_nw, " +
936 "elevation_2_nw, elevation_1_ne, " +
937 "elevation_2_ne, elevation_1_se, " +
938 "elevation_2_se, elevation_1_sw, " +
939 "elevation_2_sw, water_height, " +
940 "terrain_raise_limit, terrain_lower_limit, " +
941 "use_estate_sun, fixed_sun, sun_position, " +
942 "covenant, Sandbox, sunvectorx, sunvectory, " +
943 "sunvectorz, loaded_creation_datetime, " +
944 "loaded_creation_id) values (?RegionUUID, ?BlockTerraform, " +
945 "?BlockFly, ?AllowDamage, ?RestrictPushing, " +
946 "?AllowLandResell, ?AllowLandJoinDivide, " +
947 "?BlockShowInSearch, ?AgentLimit, ?ObjectBonus, " +
948 "?Maturity, ?DisableScripts, ?DisableCollisions, " +
949 "?DisablePhysics, ?TerrainTexture1, " +
950 "?TerrainTexture2, ?TerrainTexture3, " +
951 "?TerrainTexture4, ?Elevation1NW, ?Elevation2NW, " +
952 "?Elevation1NE, ?Elevation2NE, ?Elevation1SE, " +
953 "?Elevation2SE, ?Elevation1SW, ?Elevation2SW, " +
954 "?WaterHeight, ?TerrainRaiseLimit, " +
955 "?TerrainLowerLimit, ?UseEstateSun, ?FixedSun, " +
956 "?SunPosition, ?Covenant, ?Sandbox, " +
957 "?SunVectorX, ?SunVectorY, ?SunVectorZ, " +
958 "?LoadedCreationDateTime, ?LoadedCreationID)";
959
960 FillRegionSettingsCommand(cmd, rs);
961 958
962 ExecuteNonQuery(cmd); 959 using (MySqlCommand cmd = dbcon.CreateCommand())
960 {
961 cmd.CommandText = "replace into regionsettings (regionUUID, " +
962 "block_terraform, block_fly, allow_damage, " +
963 "restrict_pushing, allow_land_resell, " +
964 "allow_land_join_divide, block_show_in_search, " +
965 "agent_limit, object_bonus, maturity, " +
966 "disable_scripts, disable_collisions, " +
967 "disable_physics, terrain_texture_1, " +
968 "terrain_texture_2, terrain_texture_3, " +
969 "terrain_texture_4, elevation_1_nw, " +
970 "elevation_2_nw, elevation_1_ne, " +
971 "elevation_2_ne, elevation_1_se, " +
972 "elevation_2_se, elevation_1_sw, " +
973 "elevation_2_sw, water_height, " +
974 "terrain_raise_limit, terrain_lower_limit, " +
975 "use_estate_sun, fixed_sun, sun_position, " +
976 "covenant, Sandbox, sunvectorx, sunvectory, " +
977 "sunvectorz, loaded_creation_datetime, " +
978 "loaded_creation_id) values (?RegionUUID, ?BlockTerraform, " +
979 "?BlockFly, ?AllowDamage, ?RestrictPushing, " +
980 "?AllowLandResell, ?AllowLandJoinDivide, " +
981 "?BlockShowInSearch, ?AgentLimit, ?ObjectBonus, " +
982 "?Maturity, ?DisableScripts, ?DisableCollisions, " +
983 "?DisablePhysics, ?TerrainTexture1, " +
984 "?TerrainTexture2, ?TerrainTexture3, " +
985 "?TerrainTexture4, ?Elevation1NW, ?Elevation2NW, " +
986 "?Elevation1NE, ?Elevation2NE, ?Elevation1SE, " +
987 "?Elevation2SE, ?Elevation1SW, ?Elevation2SW, " +
988 "?WaterHeight, ?TerrainRaiseLimit, " +
989 "?TerrainLowerLimit, ?UseEstateSun, ?FixedSun, " +
990 "?SunPosition, ?Covenant, ?Sandbox, " +
991 "?SunVectorX, ?SunVectorY, ?SunVectorZ, " +
992 "?LoadedCreationDateTime, ?LoadedCreationID)";
993
994 FillRegionSettingsCommand(cmd, rs);
995
996 ExecuteNonQuery(cmd);
997 }
963 } 998 }
964 } 999 }
965 } 1000 }
@@ -968,36 +1003,41 @@ namespace OpenSim.Data.MySQL
968 { 1003 {
969 List<LandData> landData = new List<LandData>(); 1004 List<LandData> landData = new List<LandData>();
970 1005
971 lock (m_Connection) 1006 lock (m_dbLock)
972 { 1007 {
973 using (MySqlCommand cmd = m_Connection.CreateCommand()) 1008 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
974 { 1009 {
975 cmd.CommandText = "select * from land where RegionUUID = ?RegionUUID"; 1010 dbcon.Open();
976 cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
977 1011
978 using (IDataReader reader = ExecuteReader(cmd)) 1012 using (MySqlCommand cmd = dbcon.CreateCommand())
979 { 1013 {
980 while (reader.Read()) 1014 cmd.CommandText = "select * from land where RegionUUID = ?RegionUUID";
1015 cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
1016
1017 using (IDataReader reader = ExecuteReader(cmd))
981 { 1018 {
982 LandData newLand = BuildLandData(reader); 1019 while (reader.Read())
983 landData.Add(newLand); 1020 {
1021 LandData newLand = BuildLandData(reader);
1022 landData.Add(newLand);
1023 }
984 } 1024 }
985 } 1025 }
986 }
987 1026
988 using (MySqlCommand cmd = m_Connection.CreateCommand()) 1027 using (MySqlCommand cmd = dbcon.CreateCommand())
989 {
990 foreach (LandData land in landData)
991 { 1028 {
992 cmd.Parameters.Clear(); 1029 foreach (LandData land in landData)
993 cmd.CommandText = "select * from landaccesslist where LandUUID = ?LandUUID";
994 cmd.Parameters.AddWithValue("LandUUID", land.GlobalID.ToString());
995
996 using (IDataReader reader = ExecuteReader(cmd))
997 { 1030 {
998 while (reader.Read()) 1031 cmd.Parameters.Clear();
1032 cmd.CommandText = "select * from landaccesslist where LandUUID = ?LandUUID";
1033 cmd.Parameters.AddWithValue("LandUUID", land.GlobalID.ToString());
1034
1035 using (IDataReader reader = ExecuteReader(cmd))
999 { 1036 {
1000 land.ParcelAccessList.Add(BuildLandAccessData(reader)); 1037 while (reader.Read())
1038 {
1039 land.ParcelAccessList.Add(BuildLandAccessData(reader));
1040 }
1001 } 1041 }
1002 } 1042 }
1003 } 1043 }
@@ -1705,41 +1745,46 @@ namespace OpenSim.Data.MySQL
1705 1745
1706 public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items) 1746 public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
1707 { 1747 {
1708 lock (m_Connection) 1748 lock (m_dbLock)
1709 { 1749 {
1710 RemoveItems(primID); 1750 RemoveItems(primID);
1711 1751
1712 MySqlCommand cmd = m_Connection.CreateCommand(); 1752 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
1713
1714 if (items.Count == 0)
1715 return;
1716
1717 cmd.CommandText = "insert into primitems ("+
1718 "invType, assetType, name, "+
1719 "description, creationDate, nextPermissions, "+
1720 "currentPermissions, basePermissions, "+
1721 "everyonePermissions, groupPermissions, "+
1722 "flags, itemID, primID, assetID, "+
1723 "parentFolderID, creatorID, ownerID, "+
1724 "groupID, lastOwnerID) values (?invType, "+
1725 "?assetType, ?name, ?description, "+
1726 "?creationDate, ?nextPermissions, "+
1727 "?currentPermissions, ?basePermissions, "+
1728 "?everyonePermissions, ?groupPermissions, "+
1729 "?flags, ?itemID, ?primID, ?assetID, "+
1730 "?parentFolderID, ?creatorID, ?ownerID, "+
1731 "?groupID, ?lastOwnerID)";
1732
1733 foreach (TaskInventoryItem item in items)
1734 { 1753 {
1735 cmd.Parameters.Clear(); 1754 dbcon.Open();
1755
1756 MySqlCommand cmd = dbcon.CreateCommand();
1757
1758 if (items.Count == 0)
1759 return;
1760
1761 cmd.CommandText = "insert into primitems (" +
1762 "invType, assetType, name, " +
1763 "description, creationDate, nextPermissions, " +
1764 "currentPermissions, basePermissions, " +
1765 "everyonePermissions, groupPermissions, " +
1766 "flags, itemID, primID, assetID, " +
1767 "parentFolderID, creatorID, ownerID, " +
1768 "groupID, lastOwnerID) values (?invType, " +
1769 "?assetType, ?name, ?description, " +
1770 "?creationDate, ?nextPermissions, " +
1771 "?currentPermissions, ?basePermissions, " +
1772 "?everyonePermissions, ?groupPermissions, " +
1773 "?flags, ?itemID, ?primID, ?assetID, " +
1774 "?parentFolderID, ?creatorID, ?ownerID, " +
1775 "?groupID, ?lastOwnerID)";
1776
1777 foreach (TaskInventoryItem item in items)
1778 {
1779 cmd.Parameters.Clear();
1736 1780
1737 FillItemCommand(cmd, item); 1781 FillItemCommand(cmd, item);
1738 1782
1739 ExecuteNonQuery(cmd); 1783 ExecuteNonQuery(cmd);
1784 }
1785
1786 cmd.Dispose();
1740 } 1787 }
1741
1742 cmd.Dispose();
1743 } 1788 }
1744 } 1789 }
1745 } 1790 }