aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs')
-rw-r--r--OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs117
1 files changed, 68 insertions, 49 deletions
diff --git a/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs b/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs
index ded584e..f303a6b 100644
--- a/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs
+++ b/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs
@@ -26,13 +26,10 @@
26* 26*
27*/ 27*/
28using System; 28using System;
29using System.IO;
30using System.Data;
31using System.Collections.Generic; 29using System.Collections.Generic;
32using libsecondlife; 30using libsecondlife;
33using OpenSim.Framework;
34using OpenSim.Framework.Console;
35using MySql.Data.MySqlClient; 31using MySql.Data.MySqlClient;
32using OpenSim.Framework.Console;
36 33
37namespace OpenSim.Framework.Data.MySQL 34namespace OpenSim.Framework.Data.MySQL
38{ 35{
@@ -59,7 +56,9 @@ namespace OpenSim.Framework.Data.MySQL
59 string settingPooling = GridDataMySqlFile.ParseFileReadValue("pooling"); 56 string settingPooling = GridDataMySqlFile.ParseFileReadValue("pooling");
60 string settingPort = GridDataMySqlFile.ParseFileReadValue("port"); 57 string settingPort = GridDataMySqlFile.ParseFileReadValue("port");
61 58
62 database = new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword, settingPooling, settingPort); 59 database =
60 new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword, settingPooling,
61 settingPort);
63 TestTables(database.Connection); 62 TestTables(database.Connection);
64 } 63 }
65 64
@@ -99,7 +98,6 @@ namespace OpenSim.Framework.Data.MySQL
99 98
100 private void TestTables(MySqlConnection conn) 99 private void TestTables(MySqlConnection conn)
101 { 100 {
102
103 Dictionary<string, string> tableList = new Dictionary<string, string>(); 101 Dictionary<string, string> tableList = new Dictionary<string, string>();
104 102
105 tableList["inventoryfolders"] = null; 103 tableList["inventoryfolders"] = null;
@@ -110,6 +108,7 @@ namespace OpenSim.Framework.Data.MySQL
110 UpgradeFoldersTable(tableList["inventoryfolders"]); 108 UpgradeFoldersTable(tableList["inventoryfolders"]);
111 UpgradeItemsTable(tableList["inventoryitems"]); 109 UpgradeItemsTable(tableList["inventoryitems"]);
112 } 110 }
111
113 #endregion 112 #endregion
114 113
115 /// <summary> 114 /// <summary>
@@ -151,11 +150,13 @@ namespace OpenSim.Framework.Data.MySQL
151 { 150 {
152 List<InventoryItemBase> items = new List<InventoryItemBase>(); 151 List<InventoryItemBase> items = new List<InventoryItemBase>();
153 152
154 MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE parentFolderID = ?uuid", database.Connection); 153 MySqlCommand result =
154 new MySqlCommand("SELECT * FROM inventoryitems WHERE parentFolderID = ?uuid",
155 database.Connection);
155 result.Parameters.AddWithValue("?uuid", folderID.ToStringHyphenated()); 156 result.Parameters.AddWithValue("?uuid", folderID.ToStringHyphenated());
156 MySqlDataReader reader = result.ExecuteReader(); 157 MySqlDataReader reader = result.ExecuteReader();
157 158
158 while(reader.Read()) 159 while (reader.Read())
159 items.Add(readInventoryItem(reader)); 160 items.Add(readInventoryItem(reader));
160 161
161 reader.Close(); 162 reader.Close();
@@ -183,13 +184,16 @@ namespace OpenSim.Framework.Data.MySQL
183 { 184 {
184 lock (database) 185 lock (database)
185 { 186 {
186 MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", database.Connection); 187 MySqlCommand result =
188 new MySqlCommand(
189 "SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid",
190 database.Connection);
187 result.Parameters.AddWithValue("?uuid", user.ToStringHyphenated()); 191 result.Parameters.AddWithValue("?uuid", user.ToStringHyphenated());
188 result.Parameters.AddWithValue("?zero", LLUUID.Zero.ToStringHyphenated()); 192 result.Parameters.AddWithValue("?zero", LLUUID.Zero.ToStringHyphenated());
189 MySqlDataReader reader = result.ExecuteReader(); 193 MySqlDataReader reader = result.ExecuteReader();
190 194
191 List<InventoryFolderBase> items = new List<InventoryFolderBase>(); 195 List<InventoryFolderBase> items = new List<InventoryFolderBase>();
192 while(reader.Read()) 196 while (reader.Read())
193 items.Add(readInventoryFolder(reader)); 197 items.Add(readInventoryFolder(reader));
194 198
195 199
@@ -218,17 +222,21 @@ namespace OpenSim.Framework.Data.MySQL
218 { 222 {
219 lock (database) 223 lock (database)
220 { 224 {
221 MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", database.Connection); 225 MySqlCommand result =
226 new MySqlCommand(
227 "SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid",
228 database.Connection);
222 result.Parameters.AddWithValue("?uuid", user.ToStringHyphenated()); 229 result.Parameters.AddWithValue("?uuid", user.ToStringHyphenated());
223 result.Parameters.AddWithValue("?zero", LLUUID.Zero.ToStringHyphenated()); 230 result.Parameters.AddWithValue("?zero", LLUUID.Zero.ToStringHyphenated());
224 231
225 MySqlDataReader reader = result.ExecuteReader(); 232 MySqlDataReader reader = result.ExecuteReader();
226 233
227 List<InventoryFolderBase> items = new List<InventoryFolderBase>(); 234 List<InventoryFolderBase> items = new List<InventoryFolderBase>();
228 while(reader.Read()) 235 while (reader.Read())
229 items.Add(readInventoryFolder(reader)); 236 items.Add(readInventoryFolder(reader));
230 237
231 InventoryFolderBase rootFolder = items[0]; //should only be one folder with parent set to zero (the root one). 238 InventoryFolderBase rootFolder = items[0];
239 //should only be one folder with parent set to zero (the root one).
232 reader.Close(); 240 reader.Close();
233 result.Dispose(); 241 result.Dispose();
234 242
@@ -254,13 +262,15 @@ namespace OpenSim.Framework.Data.MySQL
254 { 262 {
255 lock (database) 263 lock (database)
256 { 264 {
257 MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?uuid", database.Connection); 265 MySqlCommand result =
266 new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?uuid",
267 database.Connection);
258 result.Parameters.AddWithValue("?uuid", parentID.ToStringHyphenated()); 268 result.Parameters.AddWithValue("?uuid", parentID.ToStringHyphenated());
259 MySqlDataReader reader = result.ExecuteReader(); 269 MySqlDataReader reader = result.ExecuteReader();
260 270
261 List<InventoryFolderBase> items = new List<InventoryFolderBase>(); 271 List<InventoryFolderBase> items = new List<InventoryFolderBase>();
262 272
263 while(reader.Read()) 273 while (reader.Read())
264 items.Add(readInventoryFolder(reader)); 274 items.Add(readInventoryFolder(reader));
265 275
266 reader.Close(); 276 reader.Close();
@@ -288,19 +298,19 @@ namespace OpenSim.Framework.Data.MySQL
288 { 298 {
289 InventoryItemBase item = new InventoryItemBase(); 299 InventoryItemBase item = new InventoryItemBase();
290 300
291 item.inventoryID = new LLUUID((string)reader["inventoryID"]); 301 item.inventoryID = new LLUUID((string) reader["inventoryID"]);
292 item.assetID = new LLUUID((string)reader["assetID"]); 302 item.assetID = new LLUUID((string) reader["assetID"]);
293 item.assetType = (int)reader["assetType"]; 303 item.assetType = (int) reader["assetType"];
294 item.parentFolderID = new LLUUID((string)reader["parentFolderID"]); 304 item.parentFolderID = new LLUUID((string) reader["parentFolderID"]);
295 item.avatarID = new LLUUID((string)reader["avatarID"]); 305 item.avatarID = new LLUUID((string) reader["avatarID"]);
296 item.inventoryName = (string)reader["inventoryName"]; 306 item.inventoryName = (string) reader["inventoryName"];
297 item.inventoryDescription = (string)reader["inventoryDescription"]; 307 item.inventoryDescription = (string) reader["inventoryDescription"];
298 item.inventoryNextPermissions = (uint)reader["inventoryNextPermissions"]; 308 item.inventoryNextPermissions = (uint) reader["inventoryNextPermissions"];
299 item.inventoryCurrentPermissions = (uint)reader["inventoryCurrentPermissions"]; 309 item.inventoryCurrentPermissions = (uint) reader["inventoryCurrentPermissions"];
300 item.invType = (int)reader["invType"]; 310 item.invType = (int) reader["invType"];
301 item.creatorsID = new LLUUID((string)reader["creatorID"]); 311 item.creatorsID = new LLUUID((string) reader["creatorID"]);
302 item.inventoryBasePermissions = (uint)reader["inventoryBasePermissions"]; 312 item.inventoryBasePermissions = (uint) reader["inventoryBasePermissions"];
303 item.inventoryEveryOnePermissions = (uint)reader["inventoryEveryOnePermissions"]; 313 item.inventoryEveryOnePermissions = (uint) reader["inventoryEveryOnePermissions"];
304 return item; 314 return item;
305 } 315 }
306 catch (MySqlException e) 316 catch (MySqlException e)
@@ -324,12 +334,13 @@ namespace OpenSim.Framework.Data.MySQL
324 { 334 {
325 Dictionary<string, string> param = new Dictionary<string, string>(); 335 Dictionary<string, string> param = new Dictionary<string, string>();
326 336
327 MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE inventoryID = ?uuid", database.Connection); 337 MySqlCommand result =
338 new MySqlCommand("SELECT * FROM inventoryitems WHERE inventoryID = ?uuid", database.Connection);
328 result.Parameters.AddWithValue("?uuid", itemID.ToStringHyphenated()); 339 result.Parameters.AddWithValue("?uuid", itemID.ToStringHyphenated());
329 MySqlDataReader reader = result.ExecuteReader(); 340 MySqlDataReader reader = result.ExecuteReader();
330 341
331 InventoryItemBase item = null; 342 InventoryItemBase item = null;
332 if(reader.Read()) 343 if (reader.Read())
333 item = readInventoryItem(reader); 344 item = readInventoryItem(reader);
334 345
335 reader.Close(); 346 reader.Close();
@@ -356,12 +367,12 @@ namespace OpenSim.Framework.Data.MySQL
356 try 367 try
357 { 368 {
358 InventoryFolderBase folder = new InventoryFolderBase(); 369 InventoryFolderBase folder = new InventoryFolderBase();
359 folder.agentID = new LLUUID((string)reader["agentID"]); 370 folder.agentID = new LLUUID((string) reader["agentID"]);
360 folder.parentID = new LLUUID((string)reader["parentFolderID"]); 371 folder.parentID = new LLUUID((string) reader["parentFolderID"]);
361 folder.folderID = new LLUUID((string)reader["folderID"]); 372 folder.folderID = new LLUUID((string) reader["folderID"]);
362 folder.name = (string)reader["folderName"]; 373 folder.name = (string) reader["folderName"];
363 folder.type = (short)reader["type"]; 374 folder.type = (short) reader["type"];
364 folder.version = (ushort)((int)reader["version"]); 375 folder.version = (ushort) ((int) reader["version"]);
365 return folder; 376 return folder;
366 } 377 }
367 catch (Exception e) 378 catch (Exception e)
@@ -384,7 +395,8 @@ namespace OpenSim.Framework.Data.MySQL
384 { 395 {
385 lock (database) 396 lock (database)
386 { 397 {
387 MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", database.Connection); 398 MySqlCommand result =
399 new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", database.Connection);
388 result.Parameters.AddWithValue("?uuid", folderID.ToStringHyphenated()); 400 result.Parameters.AddWithValue("?uuid", folderID.ToStringHyphenated());
389 MySqlDataReader reader = result.ExecuteReader(); 401 MySqlDataReader reader = result.ExecuteReader();
390 402
@@ -410,8 +422,10 @@ namespace OpenSim.Framework.Data.MySQL
410 /// <param name="item">The inventory item</param> 422 /// <param name="item">The inventory item</param>
411 public void addInventoryItem(InventoryItemBase item) 423 public void addInventoryItem(InventoryItemBase item)
412 { 424 {
413 string sql = "REPLACE INTO inventoryitems (inventoryID, assetID, assetType, parentFolderID, avatarID, inventoryName, inventoryDescription, inventoryNextPermissions, inventoryCurrentPermissions, invType, creatorID, inventoryBasePermissions, inventoryEveryOnePermissions) VALUES "; 425 string sql =
414 sql += "(?inventoryID, ?assetID, ?assetType, ?parentFolderID, ?avatarID, ?inventoryName, ?inventoryDescription, ?inventoryNextPermissions, ?inventoryCurrentPermissions, ?invType, ?creatorID, ?inventoryBasePermissions, ?inventoryEveryOnePermissions)"; 426 "REPLACE INTO inventoryitems (inventoryID, assetID, assetType, parentFolderID, avatarID, inventoryName, inventoryDescription, inventoryNextPermissions, inventoryCurrentPermissions, invType, creatorID, inventoryBasePermissions, inventoryEveryOnePermissions) VALUES ";
427 sql +=
428 "(?inventoryID, ?assetID, ?assetType, ?parentFolderID, ?avatarID, ?inventoryName, ?inventoryDescription, ?inventoryNextPermissions, ?inventoryCurrentPermissions, ?invType, ?creatorID, ?inventoryBasePermissions, ?inventoryEveryOnePermissions)";
415 429
416 try 430 try
417 { 431 {
@@ -424,7 +438,8 @@ namespace OpenSim.Framework.Data.MySQL
424 result.Parameters.AddWithValue("?inventoryName", item.inventoryName); 438 result.Parameters.AddWithValue("?inventoryName", item.inventoryName);
425 result.Parameters.AddWithValue("?inventoryDescription", item.inventoryDescription); 439 result.Parameters.AddWithValue("?inventoryDescription", item.inventoryDescription);
426 result.Parameters.AddWithValue("?inventoryNextPermissions", item.inventoryNextPermissions.ToString()); 440 result.Parameters.AddWithValue("?inventoryNextPermissions", item.inventoryNextPermissions.ToString());
427 result.Parameters.AddWithValue("?inventoryCurrentPermissions", item.inventoryCurrentPermissions.ToString()); 441 result.Parameters.AddWithValue("?inventoryCurrentPermissions",
442 item.inventoryCurrentPermissions.ToString());
428 result.Parameters.AddWithValue("?invType", item.invType); 443 result.Parameters.AddWithValue("?invType", item.invType);
429 result.Parameters.AddWithValue("?creatorID", item.creatorsID.ToStringHyphenated()); 444 result.Parameters.AddWithValue("?creatorID", item.creatorsID.ToStringHyphenated());
430 result.Parameters.AddWithValue("?inventoryBasePermissions", item.inventoryBasePermissions); 445 result.Parameters.AddWithValue("?inventoryBasePermissions", item.inventoryBasePermissions);
@@ -455,7 +470,8 @@ namespace OpenSim.Framework.Data.MySQL
455 { 470 {
456 try 471 try
457 { 472 {
458 MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryitems WHERE inventoryID=?uuid", database.Connection); 473 MySqlCommand cmd =
474 new MySqlCommand("DELETE FROM inventoryitems WHERE inventoryID=?uuid", database.Connection);
459 cmd.Parameters.AddWithValue("?uuid", itemID.ToStringHyphenated()); 475 cmd.Parameters.AddWithValue("?uuid", itemID.ToStringHyphenated());
460 cmd.ExecuteNonQuery(); 476 cmd.ExecuteNonQuery();
461 } 477 }
@@ -472,7 +488,8 @@ namespace OpenSim.Framework.Data.MySQL
472 /// <param name="folder">Folder to create</param> 488 /// <param name="folder">Folder to create</param>
473 public void addInventoryFolder(InventoryFolderBase folder) 489 public void addInventoryFolder(InventoryFolderBase folder)
474 { 490 {
475 string sql = "REPLACE INTO inventoryfolders (folderID, agentID, parentFolderID, folderName, type, version) VALUES "; 491 string sql =
492 "REPLACE INTO inventoryfolders (folderID, agentID, parentFolderID, folderName, type, version) VALUES ";
476 sql += "(?folderID, ?agentID, ?parentFolderID, ?folderName, ?type, ?version)"; 493 sql += "(?folderID, ?agentID, ?parentFolderID, ?folderName, ?type, ?version)";
477 494
478 MySqlCommand cmd = new MySqlCommand(sql, database.Connection); 495 MySqlCommand cmd = new MySqlCommand(sql, database.Connection);
@@ -480,9 +497,9 @@ namespace OpenSim.Framework.Data.MySQL
480 cmd.Parameters.AddWithValue("?agentID", folder.agentID.ToStringHyphenated()); 497 cmd.Parameters.AddWithValue("?agentID", folder.agentID.ToStringHyphenated());
481 cmd.Parameters.AddWithValue("?parentFolderID", folder.parentID.ToStringHyphenated()); 498 cmd.Parameters.AddWithValue("?parentFolderID", folder.parentID.ToStringHyphenated());
482 cmd.Parameters.AddWithValue("?folderName", folder.name); 499 cmd.Parameters.AddWithValue("?folderName", folder.name);
483 cmd.Parameters.AddWithValue("?type", (short)folder.type); 500 cmd.Parameters.AddWithValue("?type", (short) folder.type);
484 cmd.Parameters.AddWithValue("?version", folder.version); 501 cmd.Parameters.AddWithValue("?version", folder.version);
485 502
486 try 503 try
487 { 504 {
488 cmd.ExecuteNonQuery(); 505 cmd.ExecuteNonQuery();
@@ -515,7 +532,7 @@ namespace OpenSim.Framework.Data.MySQL
515 foreach (InventoryFolderBase f in subfolderList) 532 foreach (InventoryFolderBase f in subfolderList)
516 folders.Add(f); 533 folders.Add(f);
517 } 534 }
518 535
519 /// <summary> 536 /// <summary>
520 /// Returns all child folders in the hierarchy from the parent folder and down 537 /// Returns all child folders in the hierarchy from the parent folder and down
521 /// </summary> 538 /// </summary>
@@ -536,7 +553,8 @@ namespace OpenSim.Framework.Data.MySQL
536 { 553 {
537 try 554 try
538 { 555 {
539 MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryfolders WHERE folderID=?uuid", database.Connection); 556 MySqlCommand cmd =
557 new MySqlCommand("DELETE FROM inventoryfolders WHERE folderID=?uuid", database.Connection);
540 cmd.Parameters.AddWithValue("?uuid", folderID.ToStringHyphenated()); 558 cmd.Parameters.AddWithValue("?uuid", folderID.ToStringHyphenated());
541 cmd.ExecuteNonQuery(); 559 cmd.ExecuteNonQuery();
542 } 560 }
@@ -551,7 +569,8 @@ namespace OpenSim.Framework.Data.MySQL
551 { 569 {
552 try 570 try
553 { 571 {
554 MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryitems WHERE parentFolderID=?uuid", database.Connection); 572 MySqlCommand cmd =
573 new MySqlCommand("DELETE FROM inventoryitems WHERE parentFolderID=?uuid", database.Connection);
555 cmd.Parameters.AddWithValue("?uuid", folderID.ToStringHyphenated()); 574 cmd.Parameters.AddWithValue("?uuid", folderID.ToStringHyphenated());
556 cmd.ExecuteNonQuery(); 575 cmd.ExecuteNonQuery();
557 } 576 }
@@ -586,4 +605,4 @@ namespace OpenSim.Framework.Data.MySQL
586 } 605 }
587 } 606 }
588 } 607 }
589} 608} \ No newline at end of file