aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Data.MySQL/MySQLManager.cs
diff options
context:
space:
mode:
authorMW2007-10-08 10:30:15 +0000
committerMW2007-10-08 10:30:15 +0000
commit4c25008850f92bcc79502c71a0e4d34c883d27d0 (patch)
treec5dd571fb11699675c80d363b3261c5be477c018 /OpenSim/Framework/Data.MySQL/MySQLManager.cs
parentsmall bug fix (diff)
downloadopensim-SC_OLD-4c25008850f92bcc79502c71a0e4d34c883d27d0.zip
opensim-SC_OLD-4c25008850f92bcc79502c71a0e4d34c883d27d0.tar.gz
opensim-SC_OLD-4c25008850f92bcc79502c71a0e4d34c883d27d0.tar.bz2
opensim-SC_OLD-4c25008850f92bcc79502c71a0e4d34c883d27d0.tar.xz
Applied patch 485, inventory patch from tleiades (thanks again).
Diffstat (limited to 'OpenSim/Framework/Data.MySQL/MySQLManager.cs')
-rw-r--r--OpenSim/Framework/Data.MySQL/MySQLManager.cs164
1 files changed, 17 insertions, 147 deletions
diff --git a/OpenSim/Framework/Data.MySQL/MySQLManager.cs b/OpenSim/Framework/Data.MySQL/MySQLManager.cs
index a83ee45..ea174b2 100644
--- a/OpenSim/Framework/Data.MySQL/MySQLManager.cs
+++ b/OpenSim/Framework/Data.MySQL/MySQLManager.cs
@@ -31,6 +31,7 @@ using System.Data;
31using libsecondlife; 31using libsecondlife;
32using MySql.Data.MySqlClient; 32using MySql.Data.MySqlClient;
33using OpenSim.Framework.Types; 33using OpenSim.Framework.Types;
34using OpenSim.Framework.Console;
34 35
35namespace OpenSim.Framework.Data.MySQL 36namespace OpenSim.Framework.Data.MySQL
36{ 37{
@@ -42,7 +43,7 @@ namespace OpenSim.Framework.Data.MySQL
42 /// <summary> 43 /// <summary>
43 /// The database connection object 44 /// The database connection object
44 /// </summary> 45 /// </summary>
45 IDbConnection dbcon; 46 MySqlConnection dbcon;
46 /// <summary> 47 /// <summary>
47 /// Connection string for ADO.net 48 /// Connection string for ADO.net
48 /// </summary> 49 /// </summary>
@@ -65,7 +66,7 @@ namespace OpenSim.Framework.Data.MySQL
65 66
66 dbcon.Open(); 67 dbcon.Open();
67 68
68 Console.WriteLine("MySQL connection established"); 69 MainLog.Instance.Verbose("MySQL connection established");
69 } 70 }
70 catch (Exception e) 71 catch (Exception e)
71 { 72 {
@@ -74,6 +75,14 @@ namespace OpenSim.Framework.Data.MySQL
74 } 75 }
75 76
76 /// <summary> 77 /// <summary>
78 /// Get the connection being used
79 /// </summary>
80 public MySqlConnection Connection
81 {
82 get { return dbcon; }
83 }
84
85 /// <summary>
77 /// Shuts down the database connection 86 /// Shuts down the database connection
78 /// </summary> 87 /// </summary>
79 public void Close() 88 public void Close()
@@ -99,7 +108,7 @@ namespace OpenSim.Framework.Data.MySQL
99 } 108 }
100 catch (Exception e) 109 catch (Exception e)
101 { 110 {
102 Console.WriteLine("Unable to reconnect to database " + e.ToString()); 111 MainLog.Instance.Error("Unable to reconnect to database " + e.ToString());
103 } 112 }
104 } 113 }
105 } 114 }
@@ -142,7 +151,7 @@ namespace OpenSim.Framework.Data.MySQL
142 } 151 }
143 catch (Exception e) 152 catch (Exception e)
144 { 153 {
145 Console.WriteLine("Unable to reconnect to database " + e.ToString()); 154 MainLog.Instance.Error("Unable to reconnect to database " + e.ToString());
146 } 155 }
147 156
148 // Run the query again 157 // Run the query again
@@ -160,7 +169,7 @@ namespace OpenSim.Framework.Data.MySQL
160 catch (Exception e) 169 catch (Exception e)
161 { 170 {
162 // Return null if it fails. 171 // Return null if it fails.
163 Console.WriteLine("Failed during Query generation: " + e.ToString()); 172 MainLog.Instance.Error("Failed during Query generation: " + e.ToString());
164 return null; 173 return null;
165 } 174 }
166 } 175 }
@@ -352,72 +361,7 @@ namespace OpenSim.Framework.Data.MySQL
352 return retval; 361 return retval;
353 } 362 }
354 363
355 /// <summary>
356 /// Reads a list of inventory folders returned by a query.
357 /// </summary>
358 /// <param name="reader">A MySQL Data Reader</param>
359 /// <returns>A List containing inventory folders</returns>
360 public List<InventoryFolderBase> readInventoryFolders(IDataReader reader)
361 {
362 List<InventoryFolderBase> rows = new List<InventoryFolderBase>();
363
364 while(reader.Read())
365 {
366 try
367 {
368 InventoryFolderBase folder = new InventoryFolderBase();
369
370 folder.agentID = new LLUUID((string)reader["agentID"]);
371 folder.parentID = new LLUUID((string)reader["parentFolderID"]);
372 folder.folderID = new LLUUID((string)reader["folderID"]);
373 folder.name = (string)reader["folderName"];
374
375 rows.Add(folder);
376 }
377 catch (Exception e)
378 {
379 Console.WriteLine(e.ToString());
380 }
381 }
382
383 return rows;
384 }
385
386 /// <summary>
387 /// Reads a collection of items from an SQL result
388 /// </summary>
389 /// <param name="reader">The SQL Result</param>
390 /// <returns>A List containing Inventory Items</returns>
391 public List<InventoryItemBase> readInventoryItems(IDataReader reader)
392 {
393 List<InventoryItemBase> rows = new List<InventoryItemBase>();
394 364
395 while (reader.Read())
396 {
397 try
398 {
399 InventoryItemBase item = new InventoryItemBase();
400
401 item.assetID = new LLUUID((string)reader["assetID"]);
402 item.avatarID = new LLUUID((string)reader["avatarID"]);
403 item.inventoryCurrentPermissions = Convert.ToUInt32(reader["inventoryCurrentPermissions"].ToString());
404 item.inventoryDescription = (string)reader["inventoryDescription"];
405 item.inventoryID = new LLUUID((string)reader["inventoryID"]);
406 item.inventoryName = (string)reader["inventoryName"];
407 item.inventoryNextPermissions = Convert.ToUInt32(reader["inventoryNextPermissions"].ToString());
408 item.parentFolderID = new LLUUID((string)reader["parentFolderID"]);
409 item.assetType = Convert.ToInt32(reader["type"].ToString());
410
411 rows.Add(item);
412 }
413 catch (Exception e)
414 {
415 Console.WriteLine(e.ToString());
416 }
417 }
418
419 return rows;
420 }
421 365
422 /// <summary> 366 /// <summary>
423 /// Inserts a new row into the log database 367 /// Inserts a new row into the log database
@@ -455,87 +399,13 @@ namespace OpenSim.Framework.Data.MySQL
455 } 399 }
456 catch (Exception e) 400 catch (Exception e)
457 { 401 {
458 Console.WriteLine(e.ToString()); 402 MainLog.Instance.Error(e.ToString());
459 return false;
460 }
461
462 return returnval;
463 }
464
465 /// <summary>
466 /// Inserts a new item into the database
467 /// </summary>
468 /// <param name="item">The item</param>
469 /// <returns>Success?</returns>
470 public bool insertItem(InventoryItemBase item)
471 {
472 string sql = "REPLACE INTO inventoryitems (inventoryID, assetID, type, parentFolderID, avatarID, inventoryName, inventoryDescription, inventoryNextPermissions, inventoryCurrentPermissions) VALUES ";
473 sql += "(?inventoryID, ?assetID, ?type, ?parentFolderID, ?avatarID, ?inventoryName, ?inventoryDescription, ?inventoryNextPermissions, ?inventoryCurrentPermissions)";
474
475 Dictionary<string, string> parameters = new Dictionary<string, string>();
476 parameters["?inventoryID"] = item.inventoryID.ToStringHyphenated();
477 parameters["?assetID"] = item.assetID.ToStringHyphenated();
478 parameters["?type"] = item.assetType.ToString();
479 parameters["?parentFolderID"] = item.parentFolderID.ToStringHyphenated();
480 parameters["?avatarID"] = item.avatarID.ToStringHyphenated();
481 parameters["?inventoryName"] = item.inventoryName;
482 parameters["?inventoryDescription"] = item.inventoryDescription;
483 parameters["?inventoryNextPermissions"] = item.inventoryNextPermissions.ToString();
484 parameters["?inventoryCurrentPermissions"] = item.inventoryCurrentPermissions.ToString();
485
486 bool returnval = false;
487
488 try
489 {
490 IDbCommand result = Query(sql, parameters);
491
492 if (result.ExecuteNonQuery() == 1)
493 returnval = true;
494
495 result.Dispose();
496 }
497 catch (Exception e)
498 {
499 Console.WriteLine(e.ToString());
500 return false; 403 return false;
501 } 404 }
502 405
503 return returnval; 406 return returnval;
504 } 407 }
505 408
506 /// <summary>
507 /// Inserts a new folder into the database
508 /// </summary>
509 /// <param name="folder">The folder</param>
510 /// <returns>Success?</returns>
511 public bool insertFolder(InventoryFolderBase folder)
512 {
513 string sql = "REPLACE INTO inventoryfolders (folderID, agentID, parentFolderID, folderName) VALUES ";
514 sql += "(?folderID, ?agentID, ?parentFolderID, ?folderName)";
515
516 Dictionary<string, string> parameters = new Dictionary<string, string>();
517 parameters["?folderID"] = folder.folderID.ToStringHyphenated();
518 parameters["?agentID"] = folder.agentID.ToStringHyphenated();
519 parameters["?parentFolderID"] = folder.parentID.ToStringHyphenated();
520 parameters["?folderName"] = folder.name;
521
522 bool returnval = false;
523 try
524 {
525 IDbCommand result = Query(sql, parameters);
526
527 if (result.ExecuteNonQuery() == 1)
528 returnval = true;
529
530 result.Dispose();
531 }
532 catch (Exception e)
533 {
534 Console.WriteLine(e.ToString());
535 return false;
536 }
537 return returnval;
538 }
539 409
540 /// <summary> 410 /// <summary>
541 /// Creates a new user and inserts it into the database 411 /// Creates a new user and inserts it into the database
@@ -614,7 +484,7 @@ namespace OpenSim.Framework.Data.MySQL
614 } 484 }
615 catch (Exception e) 485 catch (Exception e)
616 { 486 {
617 Console.WriteLine(e.ToString()); 487 MainLog.Instance.Error(e.ToString());
618 return false; 488 return false;
619 } 489 }
620 490
@@ -683,7 +553,7 @@ namespace OpenSim.Framework.Data.MySQL
683 } 553 }
684 catch (Exception e) 554 catch (Exception e)
685 { 555 {
686 Console.WriteLine(e.ToString()); 556 MainLog.Instance.Error(e.ToString());
687 return false; 557 return false;
688 } 558 }
689 559