aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL/MySQLLegacyRegionData.cs
diff options
context:
space:
mode:
authorMelanie2010-02-08 22:11:38 +0000
committerMelanie2010-02-08 22:11:38 +0000
commitc8f3bb56ff20493b9f51a123a1d89e876e0cab75 (patch)
tree0f878d1eb21f821f517ebe8170776023952e6e2c /OpenSim/Data/MySQL/MySQLLegacyRegionData.cs
parentMerge branch 'master' into careminster (diff)
parentMerge branch 'master' of melanie@opensimulator.org:/var/git/opensim (diff)
downloadopensim-SC_OLD-c8f3bb56ff20493b9f51a123a1d89e876e0cab75.zip
opensim-SC_OLD-c8f3bb56ff20493b9f51a123a1d89e876e0cab75.tar.gz
opensim-SC_OLD-c8f3bb56ff20493b9f51a123a1d89e876e0cab75.tar.bz2
opensim-SC_OLD-c8f3bb56ff20493b9f51a123a1d89e876e0cab75.tar.xz
Merge branch 'master' into careminster
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLLegacyRegionData.cs')
-rw-r--r--OpenSim/Data/MySQL/MySQLLegacyRegionData.cs910
1 files changed, 474 insertions, 436 deletions
diff --git a/OpenSim/Data/MySQL/MySQLLegacyRegionData.cs b/OpenSim/Data/MySQL/MySQLLegacyRegionData.cs
index e57e929..f4485df 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 {
392 // end of the list
393 sql += "(PrimID = ?PrimID" + i + ")";
394 }
395 else
396 { 371 {
397 sql += "(PrimID = ?PrimID" + i + ") or "; 372 if ((i + 1) == uuids.Count)
373 {
374 // end of the list
375 sql += "(PrimID = ?PrimID" + i + ")";
376 }
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 }
@@ -788,27 +806,32 @@ namespace OpenSim.Data.MySQL
788 { 806 {
789 RegionSettings rs = null; 807 RegionSettings rs = null;
790 808
791 lock (m_Connection) 809 lock (m_dbLock)
792 { 810 {
793 using (MySqlCommand cmd = m_Connection.CreateCommand()) 811 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
794 { 812 {
795 cmd.CommandText = "select * from regionsettings where regionUUID = ?RegionUUID"; 813 dbcon.Open();
796 cmd.Parameters.AddWithValue("regionUUID", regionUUID);
797 814
798 using (IDataReader reader = ExecuteReader(cmd)) 815 using (MySqlCommand cmd = dbcon.CreateCommand())
799 { 816 {
800 if (reader.Read()) 817 cmd.CommandText = "select * from regionsettings where regionUUID = ?RegionUUID";
801 { 818 cmd.Parameters.AddWithValue("regionUUID", regionUUID);
802 rs = BuildRegionSettings(reader); 819
803 rs.OnSave += StoreRegionSettings; 820 using (IDataReader reader = ExecuteReader(cmd))
804 }
805 else
806 { 821 {
807 rs = new RegionSettings(); 822 if (reader.Read())
808 rs.RegionUUID = regionUUID; 823 {
809 rs.OnSave += StoreRegionSettings; 824 rs = BuildRegionSettings(reader);
825 rs.OnSave += StoreRegionSettings;
826 }
827 else
828 {
829 rs = new RegionSettings();
830 rs.RegionUUID = regionUUID;
831 rs.OnSave += StoreRegionSettings;
810 832
811 StoreRegionSettings(rs); 833 StoreRegionSettings(rs);
834 }
812 } 835 }
813 } 836 }
814 } 837 }
@@ -920,46 +943,51 @@ namespace OpenSim.Data.MySQL
920 943
921 public void StoreRegionSettings(RegionSettings rs) 944 public void StoreRegionSettings(RegionSettings rs)
922 { 945 {
923 lock (m_Connection) 946 lock (m_dbLock)
924 { 947 {
925 using (MySqlCommand cmd = m_Connection.CreateCommand()) 948 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
926 { 949 {
927 cmd.CommandText = "replace into regionsettings (regionUUID, " + 950 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 951
962 ExecuteNonQuery(cmd); 952 using (MySqlCommand cmd = dbcon.CreateCommand())
953 {
954 cmd.CommandText = "replace into regionsettings (regionUUID, " +
955 "block_terraform, block_fly, allow_damage, " +
956 "restrict_pushing, allow_land_resell, " +
957 "allow_land_join_divide, block_show_in_search, " +
958 "agent_limit, object_bonus, maturity, " +
959 "disable_scripts, disable_collisions, " +
960 "disable_physics, terrain_texture_1, " +
961 "terrain_texture_2, terrain_texture_3, " +
962 "terrain_texture_4, elevation_1_nw, " +
963 "elevation_2_nw, elevation_1_ne, " +
964 "elevation_2_ne, elevation_1_se, " +
965 "elevation_2_se, elevation_1_sw, " +
966 "elevation_2_sw, water_height, " +
967 "terrain_raise_limit, terrain_lower_limit, " +
968 "use_estate_sun, fixed_sun, sun_position, " +
969 "covenant, Sandbox, sunvectorx, sunvectory, " +
970 "sunvectorz, loaded_creation_datetime, " +
971 "loaded_creation_id) values (?RegionUUID, ?BlockTerraform, " +
972 "?BlockFly, ?AllowDamage, ?RestrictPushing, " +
973 "?AllowLandResell, ?AllowLandJoinDivide, " +
974 "?BlockShowInSearch, ?AgentLimit, ?ObjectBonus, " +
975 "?Maturity, ?DisableScripts, ?DisableCollisions, " +
976 "?DisablePhysics, ?TerrainTexture1, " +
977 "?TerrainTexture2, ?TerrainTexture3, " +
978 "?TerrainTexture4, ?Elevation1NW, ?Elevation2NW, " +
979 "?Elevation1NE, ?Elevation2NE, ?Elevation1SE, " +
980 "?Elevation2SE, ?Elevation1SW, ?Elevation2SW, " +
981 "?WaterHeight, ?TerrainRaiseLimit, " +
982 "?TerrainLowerLimit, ?UseEstateSun, ?FixedSun, " +
983 "?SunPosition, ?Covenant, ?Sandbox, " +
984 "?SunVectorX, ?SunVectorY, ?SunVectorZ, " +
985 "?LoadedCreationDateTime, ?LoadedCreationID)";
986
987 FillRegionSettingsCommand(cmd, rs);
988
989 ExecuteNonQuery(cmd);
990 }
963 } 991 }
964 } 992 }
965 } 993 }
@@ -968,36 +996,41 @@ namespace OpenSim.Data.MySQL
968 { 996 {
969 List<LandData> landData = new List<LandData>(); 997 List<LandData> landData = new List<LandData>();
970 998
971 lock (m_Connection) 999 lock (m_dbLock)
972 { 1000 {
973 using (MySqlCommand cmd = m_Connection.CreateCommand()) 1001 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
974 { 1002 {
975 cmd.CommandText = "select * from land where RegionUUID = ?RegionUUID"; 1003 dbcon.Open();
976 cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
977 1004
978 using (IDataReader reader = ExecuteReader(cmd)) 1005 using (MySqlCommand cmd = dbcon.CreateCommand())
979 { 1006 {
980 while (reader.Read()) 1007 cmd.CommandText = "select * from land where RegionUUID = ?RegionUUID";
1008 cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
1009
1010 using (IDataReader reader = ExecuteReader(cmd))
981 { 1011 {
982 LandData newLand = BuildLandData(reader); 1012 while (reader.Read())
983 landData.Add(newLand); 1013 {
1014 LandData newLand = BuildLandData(reader);
1015 landData.Add(newLand);
1016 }
984 } 1017 }
985 } 1018 }
986 }
987 1019
988 using (MySqlCommand cmd = m_Connection.CreateCommand()) 1020 using (MySqlCommand cmd = dbcon.CreateCommand())
989 {
990 foreach (LandData land in landData)
991 { 1021 {
992 cmd.Parameters.Clear(); 1022 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 { 1023 {
998 while (reader.Read()) 1024 cmd.Parameters.Clear();
1025 cmd.CommandText = "select * from landaccesslist where LandUUID = ?LandUUID";
1026 cmd.Parameters.AddWithValue("LandUUID", land.GlobalID.ToString());
1027
1028 using (IDataReader reader = ExecuteReader(cmd))
999 { 1029 {
1000 land.ParcelAccessList.Add(BuildLandAccessData(reader)); 1030 while (reader.Read())
1031 {
1032 land.ParcelAccessList.Add(BuildLandAccessData(reader));
1033 }
1001 } 1034 }
1002 } 1035 }
1003 } 1036 }
@@ -1705,41 +1738,46 @@ namespace OpenSim.Data.MySQL
1705 1738
1706 public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items) 1739 public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
1707 { 1740 {
1708 lock (m_Connection) 1741 lock (m_dbLock)
1709 { 1742 {
1710 RemoveItems(primID); 1743 RemoveItems(primID);
1711 1744
1712 MySqlCommand cmd = m_Connection.CreateCommand(); 1745 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 { 1746 {
1735 cmd.Parameters.Clear(); 1747 dbcon.Open();
1748
1749 MySqlCommand cmd = dbcon.CreateCommand();
1750
1751 if (items.Count == 0)
1752 return;
1753
1754 cmd.CommandText = "insert into primitems (" +
1755 "invType, assetType, name, " +
1756 "description, creationDate, nextPermissions, " +
1757 "currentPermissions, basePermissions, " +
1758 "everyonePermissions, groupPermissions, " +
1759 "flags, itemID, primID, assetID, " +
1760 "parentFolderID, creatorID, ownerID, " +
1761 "groupID, lastOwnerID) values (?invType, " +
1762 "?assetType, ?name, ?description, " +
1763 "?creationDate, ?nextPermissions, " +
1764 "?currentPermissions, ?basePermissions, " +
1765 "?everyonePermissions, ?groupPermissions, " +
1766 "?flags, ?itemID, ?primID, ?assetID, " +
1767 "?parentFolderID, ?creatorID, ?ownerID, " +
1768 "?groupID, ?lastOwnerID)";
1769
1770 foreach (TaskInventoryItem item in items)
1771 {
1772 cmd.Parameters.Clear();
1736 1773
1737 FillItemCommand(cmd, item); 1774 FillItemCommand(cmd, item);
1738 1775
1739 ExecuteNonQuery(cmd); 1776 ExecuteNonQuery(cmd);
1777 }
1778
1779 cmd.Dispose();
1740 } 1780 }
1741
1742 cmd.Dispose();
1743 } 1781 }
1744 } 1782 }
1745 } 1783 }