diff options
author | John Hurliman | 2009-10-04 13:57:51 -0700 |
---|---|---|
committer | John Hurliman | 2009-10-04 13:57:51 -0700 |
commit | 29a4614529bbda02b9c690d2d1812be1d1e7bbae (patch) | |
tree | 89725829b37d502158a114c862a56a075b005b1b /OpenSim/Data/MySQL/MySQLInventoryData.cs | |
parent | Guarding a line that is sometimes throwing a null pointer exception. (diff) | |
download | opensim-SC_OLD-29a4614529bbda02b9c690d2d1812be1d1e7bbae.zip opensim-SC_OLD-29a4614529bbda02b9c690d2d1812be1d1e7bbae.tar.gz opensim-SC_OLD-29a4614529bbda02b9c690d2d1812be1d1e7bbae.tar.bz2 opensim-SC_OLD-29a4614529bbda02b9c690d2d1812be1d1e7bbae.tar.xz |
* MySQL data tests now pass by fixing a bad fix for a bad cast on the asset Local member in MySQLAssetData
* First pass at applying the using(){} pattern to IDisposable objects. Always use the using pattern on IDisposable objects whenever possible, do not manually call .Close() or .Dispose() unless there is no other way to write the code. This pass mostly covers OpenSim.Data.MySQL, and should have no functional change (tests still pass)
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLInventoryData.cs')
-rw-r--r-- | OpenSim/Data/MySQL/MySQLInventoryData.cs | 335 |
1 files changed, 166 insertions, 169 deletions
diff --git a/OpenSim/Data/MySQL/MySQLInventoryData.cs b/OpenSim/Data/MySQL/MySQLInventoryData.cs index 0eecf06..598971d 100644 --- a/OpenSim/Data/MySQL/MySQLInventoryData.cs +++ b/OpenSim/Data/MySQL/MySQLInventoryData.cs | |||
@@ -135,30 +135,30 @@ namespace OpenSim.Data.MySQL | |||
135 | 135 | ||
136 | database.CheckConnection(); | 136 | database.CheckConnection(); |
137 | 137 | ||
138 | MySqlCommand result = | 138 | using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE parentFolderID = ?uuid", |
139 | new MySqlCommand("SELECT * FROM inventoryitems WHERE parentFolderID = ?uuid", | 139 | database.Connection)) |
140 | database.Connection); | ||
141 | result.Parameters.AddWithValue("?uuid", folderID.ToString()); | ||
142 | MySqlDataReader reader = result.ExecuteReader(); | ||
143 | |||
144 | while (reader.Read()) | ||
145 | { | 140 | { |
146 | // A null item (because something went wrong) breaks everything in the folder | 141 | result.Parameters.AddWithValue("?uuid", folderID.ToString()); |
147 | InventoryItemBase item = readInventoryItem(reader); | ||
148 | if (item != null) | ||
149 | items.Add(item); | ||
150 | } | ||
151 | 142 | ||
152 | reader.Close(); | 143 | using (MySqlDataReader reader = result.ExecuteReader()) |
153 | result.Dispose(); | 144 | { |
145 | while (reader.Read()) | ||
146 | { | ||
147 | // A null item (because something went wrong) breaks everything in the folder | ||
148 | InventoryItemBase item = readInventoryItem(reader); | ||
149 | if (item != null) | ||
150 | items.Add(item); | ||
151 | } | ||
154 | 152 | ||
155 | return items; | 153 | return items; |
154 | } | ||
155 | } | ||
156 | } | 156 | } |
157 | } | 157 | } |
158 | catch (Exception e) | 158 | catch (Exception e) |
159 | { | 159 | { |
160 | database.Reconnect(); | 160 | database.Reconnect(); |
161 | m_log.Error(e.ToString()); | 161 | m_log.Error(e.Message, e); |
162 | return null; | 162 | return null; |
163 | } | 163 | } |
164 | } | 164 | } |
@@ -176,29 +176,28 @@ namespace OpenSim.Data.MySQL | |||
176 | { | 176 | { |
177 | database.CheckConnection(); | 177 | database.CheckConnection(); |
178 | 178 | ||
179 | MySqlCommand result = | 179 | using (MySqlCommand result = new MySqlCommand( |
180 | new MySqlCommand( | 180 | "SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", |
181 | "SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", | 181 | database.Connection)) |
182 | database.Connection); | 182 | { |
183 | result.Parameters.AddWithValue("?uuid", user.ToString()); | 183 | result.Parameters.AddWithValue("?uuid", user.ToString()); |
184 | result.Parameters.AddWithValue("?zero", UUID.Zero.ToString()); | 184 | result.Parameters.AddWithValue("?zero", UUID.Zero.ToString()); |
185 | MySqlDataReader reader = result.ExecuteReader(); | ||
186 | |||
187 | List<InventoryFolderBase> items = new List<InventoryFolderBase>(); | ||
188 | while (reader.Read()) | ||
189 | items.Add(readInventoryFolder(reader)); | ||
190 | |||
191 | 185 | ||
192 | reader.Close(); | 186 | using (MySqlDataReader reader = result.ExecuteReader()) |
193 | result.Dispose(); | 187 | { |
188 | List<InventoryFolderBase> items = new List<InventoryFolderBase>(); | ||
189 | while (reader.Read()) | ||
190 | items.Add(readInventoryFolder(reader)); | ||
194 | 191 | ||
195 | return items; | 192 | return items; |
193 | } | ||
194 | } | ||
196 | } | 195 | } |
197 | } | 196 | } |
198 | catch (Exception e) | 197 | catch (Exception e) |
199 | { | 198 | { |
200 | database.Reconnect(); | 199 | database.Reconnect(); |
201 | m_log.Error(e.ToString()); | 200 | m_log.Error(e.Message, e); |
202 | return null; | 201 | return null; |
203 | } | 202 | } |
204 | } | 203 | } |
@@ -217,41 +216,38 @@ namespace OpenSim.Data.MySQL | |||
217 | { | 216 | { |
218 | database.CheckConnection(); | 217 | database.CheckConnection(); |
219 | 218 | ||
220 | MySqlCommand result = | 219 | using (MySqlCommand result = new MySqlCommand( |
221 | new MySqlCommand( | 220 | "SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", |
222 | "SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", | 221 | database.Connection)) |
223 | database.Connection); | 222 | { |
224 | result.Parameters.AddWithValue("?uuid", user.ToString()); | 223 | result.Parameters.AddWithValue("?uuid", user.ToString()); |
225 | result.Parameters.AddWithValue("?zero", UUID.Zero.ToString()); | 224 | result.Parameters.AddWithValue("?zero", UUID.Zero.ToString()); |
226 | 225 | ||
227 | MySqlDataReader reader = result.ExecuteReader(); | 226 | using (MySqlDataReader reader = result.ExecuteReader()) |
227 | { | ||
228 | List<InventoryFolderBase> items = new List<InventoryFolderBase>(); | ||
229 | while (reader.Read()) | ||
230 | items.Add(readInventoryFolder(reader)); | ||
228 | 231 | ||
229 | List<InventoryFolderBase> items = new List<InventoryFolderBase>(); | 232 | InventoryFolderBase rootFolder = null; |
230 | while (reader.Read()) | ||
231 | items.Add(readInventoryFolder(reader)); | ||
232 | 233 | ||
233 | InventoryFolderBase rootFolder = null; | 234 | // There should only ever be one root folder for a user. However, if there's more |
235 | // than one we'll simply use the first one rather than failing. It would be even | ||
236 | // nicer to print some message to this effect, but this feels like it's too low a | ||
237 | // to put such a message out, and it's too minor right now to spare the time to | ||
238 | // suitably refactor. | ||
239 | if (items.Count > 0) | ||
240 | rootFolder = items[0]; | ||
234 | 241 | ||
235 | // There should only ever be one root folder for a user. However, if there's more | 242 | return rootFolder; |
236 | // than one we'll simply use the first one rather than failing. It would be even | 243 | } |
237 | // nicer to print some message to this effect, but this feels like it's too low a | ||
238 | // to put such a message out, and it's too minor right now to spare the time to | ||
239 | // suitably refactor. | ||
240 | if (items.Count > 0) | ||
241 | { | ||
242 | rootFolder = items[0]; | ||
243 | } | 244 | } |
244 | |||
245 | reader.Close(); | ||
246 | result.Dispose(); | ||
247 | |||
248 | return rootFolder; | ||
249 | } | 245 | } |
250 | } | 246 | } |
251 | catch (Exception e) | 247 | catch (Exception e) |
252 | { | 248 | { |
253 | database.Reconnect(); | 249 | database.Reconnect(); |
254 | m_log.Error(e.ToString()); | 250 | m_log.Error(e.Message, e); |
255 | return null; | 251 | return null; |
256 | } | 252 | } |
257 | } | 253 | } |
@@ -271,27 +267,26 @@ namespace OpenSim.Data.MySQL | |||
271 | { | 267 | { |
272 | database.CheckConnection(); | 268 | database.CheckConnection(); |
273 | 269 | ||
274 | MySqlCommand result = | 270 | using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?uuid", |
275 | new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?uuid", | 271 | database.Connection)) |
276 | database.Connection); | 272 | { |
277 | result.Parameters.AddWithValue("?uuid", parentID.ToString()); | 273 | result.Parameters.AddWithValue("?uuid", parentID.ToString()); |
278 | MySqlDataReader reader = result.ExecuteReader(); | 274 | using (MySqlDataReader reader = result.ExecuteReader()) |
279 | 275 | { | |
280 | List<InventoryFolderBase> items = new List<InventoryFolderBase>(); | 276 | List<InventoryFolderBase> items = new List<InventoryFolderBase>(); |
281 | |||
282 | while (reader.Read()) | ||
283 | items.Add(readInventoryFolder(reader)); | ||
284 | 277 | ||
285 | reader.Close(); | 278 | while (reader.Read()) |
286 | result.Dispose(); | 279 | items.Add(readInventoryFolder(reader)); |
287 | 280 | ||
288 | return items; | 281 | return items; |
282 | } | ||
283 | } | ||
289 | } | 284 | } |
290 | } | 285 | } |
291 | catch (Exception e) | 286 | catch (Exception e) |
292 | { | 287 | { |
293 | database.Reconnect(); | 288 | database.Reconnect(); |
294 | m_log.Error(e.ToString()); | 289 | m_log.Error(e.Message, e); |
295 | return null; | 290 | return null; |
296 | } | 291 | } |
297 | } | 292 | } |
@@ -370,25 +365,25 @@ namespace OpenSim.Data.MySQL | |||
370 | { | 365 | { |
371 | database.CheckConnection(); | 366 | database.CheckConnection(); |
372 | 367 | ||
373 | MySqlCommand result = | 368 | using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE inventoryID = ?uuid", database.Connection)) |
374 | new MySqlCommand("SELECT * FROM inventoryitems WHERE inventoryID = ?uuid", database.Connection); | 369 | { |
375 | result.Parameters.AddWithValue("?uuid", itemID.ToString()); | 370 | result.Parameters.AddWithValue("?uuid", itemID.ToString()); |
376 | MySqlDataReader reader = result.ExecuteReader(); | ||
377 | |||
378 | InventoryItemBase item = null; | ||
379 | if (reader.Read()) | ||
380 | item = readInventoryItem(reader); | ||
381 | 371 | ||
382 | reader.Close(); | 372 | using (MySqlDataReader reader = result.ExecuteReader()) |
383 | result.Dispose(); | 373 | { |
374 | InventoryItemBase item = null; | ||
375 | if (reader.Read()) | ||
376 | item = readInventoryItem(reader); | ||
384 | 377 | ||
385 | return item; | 378 | return item; |
379 | } | ||
380 | } | ||
386 | } | 381 | } |
387 | } | 382 | } |
388 | catch (Exception e) | 383 | catch (Exception e) |
389 | { | 384 | { |
390 | database.Reconnect(); | 385 | database.Reconnect(); |
391 | m_log.Error(e.ToString()); | 386 | m_log.Error(e.Message, e); |
392 | } | 387 | } |
393 | return null; | 388 | return null; |
394 | } | 389 | } |
@@ -413,7 +408,7 @@ namespace OpenSim.Data.MySQL | |||
413 | } | 408 | } |
414 | catch (Exception e) | 409 | catch (Exception e) |
415 | { | 410 | { |
416 | m_log.Error(e.ToString()); | 411 | m_log.Error(e.Message, e); |
417 | } | 412 | } |
418 | 413 | ||
419 | return null; | 414 | return null; |
@@ -433,24 +428,25 @@ namespace OpenSim.Data.MySQL | |||
433 | { | 428 | { |
434 | database.CheckConnection(); | 429 | database.CheckConnection(); |
435 | 430 | ||
436 | MySqlCommand result = | 431 | using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", database.Connection)) |
437 | new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", database.Connection); | 432 | { |
438 | result.Parameters.AddWithValue("?uuid", folderID.ToString()); | 433 | result.Parameters.AddWithValue("?uuid", folderID.ToString()); |
439 | MySqlDataReader reader = result.ExecuteReader(); | ||
440 | 434 | ||
441 | InventoryFolderBase folder = null; | 435 | using (MySqlDataReader reader = result.ExecuteReader()) |
442 | if (reader.Read()) | 436 | { |
443 | folder = readInventoryFolder(reader); | 437 | InventoryFolderBase folder = null; |
444 | reader.Close(); | 438 | if (reader.Read()) |
445 | result.Dispose(); | 439 | folder = readInventoryFolder(reader); |
446 | 440 | ||
447 | return folder; | 441 | return folder; |
442 | } | ||
443 | } | ||
448 | } | 444 | } |
449 | } | 445 | } |
450 | catch (Exception e) | 446 | catch (Exception e) |
451 | { | 447 | { |
452 | database.Reconnect(); | 448 | database.Reconnect(); |
453 | m_log.Error(e.ToString()); | 449 | m_log.Error(e.Message, e); |
454 | return null; | 450 | return null; |
455 | } | 451 | } |
456 | } | 452 | } |
@@ -698,69 +694,73 @@ namespace OpenSim.Data.MySQL | |||
698 | try | 694 | try |
699 | { | 695 | { |
700 | List<InventoryFolderBase> folders = new List<InventoryFolderBase>(); | 696 | List<InventoryFolderBase> folders = new List<InventoryFolderBase>(); |
701 | Dictionary<UUID, List<InventoryFolderBase>> hashtable | 697 | Dictionary<UUID, List<InventoryFolderBase>> hashtable = new Dictionary<UUID, List<InventoryFolderBase>>(); ; |
702 | = new Dictionary<UUID, List<InventoryFolderBase>>(); ; | ||
703 | List<InventoryFolderBase> parentFolder = new List<InventoryFolderBase>(); | 698 | List<InventoryFolderBase> parentFolder = new List<InventoryFolderBase>(); |
699 | bool buildResultsFromHashTable = false; | ||
700 | |||
704 | lock (database) | 701 | lock (database) |
705 | { | 702 | { |
706 | MySqlCommand result; | ||
707 | MySqlDataReader reader; | ||
708 | bool buildResultsFromHashTable = false; | ||
709 | |||
710 | database.CheckConnection(); | 703 | database.CheckConnection(); |
711 | 704 | ||
712 | /* Fetch the parent folder from the database to determine the agent ID, and if | 705 | /* Fetch the parent folder from the database to determine the agent ID, and if |
713 | * we're querying the root of the inventory folder tree */ | 706 | * we're querying the root of the inventory folder tree */ |
714 | result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", | 707 | using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", database.Connection)) |
715 | database.Connection); | 708 | { |
716 | result.Parameters.AddWithValue("?uuid", parentID.ToString()); | 709 | result.Parameters.AddWithValue("?uuid", parentID.ToString()); |
717 | reader = result.ExecuteReader(); | 710 | |
718 | while (reader.Read()) // Should be at most 1 result | 711 | using (MySqlDataReader reader = result.ExecuteReader()) |
719 | parentFolder.Add(readInventoryFolder(reader)); | 712 | { |
720 | reader.Close(); | 713 | // Should be at most 1 result |
721 | result.Dispose(); | 714 | while (reader.Read()) |
715 | parentFolder.Add(readInventoryFolder(reader)); | ||
716 | } | ||
717 | } | ||
722 | 718 | ||
723 | if (parentFolder.Count >= 1) // No result means parent folder does not exist | 719 | if (parentFolder.Count >= 1) // No result means parent folder does not exist |
724 | { | 720 | { |
725 | if (parentFolder[0].ParentID == UUID.Zero) // We are querying the root folder | 721 | if (parentFolder[0].ParentID == UUID.Zero) // We are querying the root folder |
726 | { | 722 | { |
727 | /* Get all of the agent's folders from the database, put them in a list and return it */ | 723 | /* Get all of the agent's folders from the database, put them in a list and return it */ |
728 | result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE agentID = ?uuid", | 724 | using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE agentID = ?uuid", database.Connection)) |
729 | database.Connection); | ||
730 | result.Parameters.AddWithValue("?uuid", parentFolder[0].Owner.ToString()); | ||
731 | reader = result.ExecuteReader(); | ||
732 | while (reader.Read()) | ||
733 | { | 725 | { |
734 | InventoryFolderBase curFolder = readInventoryFolder(reader); | 726 | result.Parameters.AddWithValue("?uuid", parentFolder[0].Owner.ToString()); |
735 | if (curFolder.ID != parentID) // Do not need to add the root node of the tree to the list | 727 | |
736 | folders.Add(curFolder); | 728 | using (MySqlDataReader reader = result.ExecuteReader()) |
729 | { | ||
730 | while (reader.Read()) | ||
731 | { | ||
732 | InventoryFolderBase curFolder = readInventoryFolder(reader); | ||
733 | if (curFolder.ID != parentID) // Do not need to add the root node of the tree to the list | ||
734 | folders.Add(curFolder); | ||
735 | } | ||
736 | } | ||
737 | } | 737 | } |
738 | reader.Close(); | ||
739 | result.Dispose(); | ||
740 | } // if we are querying the root folder | 738 | } // if we are querying the root folder |
741 | else // else we are querying a subtree of the inventory folder tree | 739 | else // else we are querying a subtree of the inventory folder tree |
742 | { | 740 | { |
743 | /* Get all of the agent's folders from the database, put them all in a hash table | 741 | /* Get all of the agent's folders from the database, put them all in a hash table |
744 | * indexed by their parent ID */ | 742 | * indexed by their parent ID */ |
745 | result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE agentID = ?uuid", | 743 | using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE agentID = ?uuid", database.Connection)) |
746 | database.Connection); | ||
747 | result.Parameters.AddWithValue("?uuid", parentFolder[0].Owner.ToString()); | ||
748 | reader = result.ExecuteReader(); | ||
749 | while (reader.Read()) | ||
750 | { | 744 | { |
751 | InventoryFolderBase curFolder = readInventoryFolder(reader); | 745 | result.Parameters.AddWithValue("?uuid", parentFolder[0].Owner.ToString()); |
752 | if (hashtable.ContainsKey(curFolder.ParentID)) // Current folder already has a sibling | 746 | |
753 | hashtable[curFolder.ParentID].Add(curFolder); // append to sibling list | 747 | using (MySqlDataReader reader = result.ExecuteReader()) |
754 | else // else current folder has no known (yet) siblings | ||
755 | { | 748 | { |
756 | List<InventoryFolderBase> siblingList = new List<InventoryFolderBase>(); | 749 | while (reader.Read()) |
757 | siblingList.Add(curFolder); | 750 | { |
758 | // Current folder has no known (yet) siblings | 751 | InventoryFolderBase curFolder = readInventoryFolder(reader); |
759 | hashtable.Add(curFolder.ParentID, siblingList); | 752 | if (hashtable.ContainsKey(curFolder.ParentID)) // Current folder already has a sibling |
753 | hashtable[curFolder.ParentID].Add(curFolder); // append to sibling list | ||
754 | else // else current folder has no known (yet) siblings | ||
755 | { | ||
756 | List<InventoryFolderBase> siblingList = new List<InventoryFolderBase>(); | ||
757 | siblingList.Add(curFolder); | ||
758 | // Current folder has no known (yet) siblings | ||
759 | hashtable.Add(curFolder.ParentID, siblingList); | ||
760 | } | ||
761 | } // while more items to read from the database | ||
760 | } | 762 | } |
761 | } // while more items to read from the database | 763 | } |
762 | reader.Close(); | ||
763 | result.Dispose(); | ||
764 | 764 | ||
765 | // Set flag so we know we need to build the results from the hash table after | 765 | // Set flag so we know we need to build the results from the hash table after |
766 | // we unlock the database | 766 | // we unlock the database |
@@ -781,12 +781,13 @@ namespace OpenSim.Data.MySQL | |||
781 | folders.AddRange(hashtable[folders[i].ID]); | 781 | folders.AddRange(hashtable[folders[i].ID]); |
782 | } | 782 | } |
783 | } // lock (database) | 783 | } // lock (database) |
784 | |||
784 | return folders; | 785 | return folders; |
785 | } | 786 | } |
786 | catch (Exception e) | 787 | catch (Exception e) |
787 | { | 788 | { |
788 | database.Reconnect(); | 789 | database.Reconnect(); |
789 | m_log.Error(e.ToString()); | 790 | m_log.Error(e.Message, e); |
790 | return null; | 791 | return null; |
791 | } | 792 | } |
792 | } | 793 | } |
@@ -801,19 +802,18 @@ namespace OpenSim.Data.MySQL | |||
801 | { | 802 | { |
802 | database.CheckConnection(); | 803 | database.CheckConnection(); |
803 | 804 | ||
804 | MySqlCommand cmd = | 805 | using (MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryfolders WHERE folderID=?uuid", database.Connection)) |
805 | new MySqlCommand("DELETE FROM inventoryfolders WHERE folderID=?uuid", database.Connection); | ||
806 | cmd.Parameters.AddWithValue("?uuid", folderID.ToString()); | ||
807 | |||
808 | lock (database) | ||
809 | { | 806 | { |
810 | cmd.ExecuteNonQuery(); | 807 | cmd.Parameters.AddWithValue("?uuid", folderID.ToString()); |
808 | |||
809 | lock (database) | ||
810 | cmd.ExecuteNonQuery(); | ||
811 | } | 811 | } |
812 | } | 812 | } |
813 | catch (MySqlException e) | 813 | catch (MySqlException e) |
814 | { | 814 | { |
815 | database.Reconnect(); | 815 | database.Reconnect(); |
816 | m_log.Error(e.ToString()); | 816 | m_log.Error(e.Message, e); |
817 | } | 817 | } |
818 | } | 818 | } |
819 | 819 | ||
@@ -827,13 +827,12 @@ namespace OpenSim.Data.MySQL | |||
827 | { | 827 | { |
828 | database.CheckConnection(); | 828 | database.CheckConnection(); |
829 | 829 | ||
830 | MySqlCommand cmd = | 830 | using (MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryitems WHERE parentFolderID=?uuid", database.Connection)) |
831 | new MySqlCommand("DELETE FROM inventoryitems WHERE parentFolderID=?uuid", database.Connection); | ||
832 | cmd.Parameters.AddWithValue("?uuid", folderID.ToString()); | ||
833 | |||
834 | lock (database) | ||
835 | { | 831 | { |
836 | cmd.ExecuteNonQuery(); | 832 | cmd.Parameters.AddWithValue("?uuid", folderID.ToString()); |
833 | |||
834 | lock (database) | ||
835 | cmd.ExecuteNonQuery(); | ||
837 | } | 836 | } |
838 | } | 837 | } |
839 | catch (MySqlException e) | 838 | catch (MySqlException e) |
@@ -865,40 +864,38 @@ namespace OpenSim.Data.MySQL | |||
865 | 864 | ||
866 | public List<InventoryItemBase> fetchActiveGestures(UUID avatarID) | 865 | public List<InventoryItemBase> fetchActiveGestures(UUID avatarID) |
867 | { | 866 | { |
868 | MySqlDataReader result = null; | ||
869 | MySqlCommand sqlCmd = null; | ||
870 | lock (database) | 867 | lock (database) |
871 | { | 868 | { |
872 | try | 869 | try |
873 | { | 870 | { |
874 | database.CheckConnection(); | 871 | database.CheckConnection(); |
875 | sqlCmd = new MySqlCommand( | ||
876 | "SELECT * FROM inventoryitems WHERE avatarId = ?uuid AND assetType = ?type and flags = 1", | ||
877 | database.Connection); | ||
878 | sqlCmd.Parameters.AddWithValue("?uuid", avatarID.ToString()); | ||
879 | sqlCmd.Parameters.AddWithValue("?type", (int)AssetType.Gesture); | ||
880 | result = sqlCmd.ExecuteReader(); | ||
881 | 872 | ||
882 | List<InventoryItemBase> list = new List<InventoryItemBase>(); | 873 | using (MySqlCommand sqlCmd = new MySqlCommand( |
883 | while (result.Read()) | 874 | "SELECT * FROM inventoryitems WHERE avatarId = ?uuid AND assetType = ?type and flags = 1", |
875 | database.Connection)) | ||
884 | { | 876 | { |
885 | InventoryItemBase item = readInventoryItem(result); | 877 | sqlCmd.Parameters.AddWithValue("?uuid", avatarID.ToString()); |
886 | if (item != null) | 878 | sqlCmd.Parameters.AddWithValue("?type", (int)AssetType.Gesture); |
887 | list.Add(item); | 879 | |
880 | using (MySqlDataReader result = sqlCmd.ExecuteReader()) | ||
881 | { | ||
882 | List<InventoryItemBase> list = new List<InventoryItemBase>(); | ||
883 | while (result.Read()) | ||
884 | { | ||
885 | InventoryItemBase item = readInventoryItem(result); | ||
886 | if (item != null) | ||
887 | list.Add(item); | ||
888 | } | ||
889 | return list; | ||
890 | } | ||
888 | } | 891 | } |
889 | return list; | ||
890 | } | 892 | } |
891 | catch (Exception e) | 893 | catch (Exception e) |
892 | { | 894 | { |
893 | database.Reconnect(); | 895 | database.Reconnect(); |
894 | m_log.Error(e.ToString()); | 896 | m_log.Error(e.Message, e); |
895 | return null; | 897 | return null; |
896 | } | 898 | } |
897 | finally | ||
898 | { | ||
899 | if (result != null) result.Close(); | ||
900 | if (sqlCmd != null) sqlCmd.Dispose(); | ||
901 | } | ||
902 | } | 899 | } |
903 | } | 900 | } |
904 | } | 901 | } |