aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs
diff options
context:
space:
mode:
authorTleiades Hax2007-10-13 07:26:21 +0000
committerTleiades Hax2007-10-13 07:26:21 +0000
commit1232eb1c587ffdc06c26a1c5b1b4fa5f22848754 (patch)
tree468fb8483a2cd03e472a6988ef60f1c8ff01c07e /OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs
parentChange 3 UserServer login messages from writeline to MainLog to help diagnose... (diff)
downloadopensim-SC_OLD-1232eb1c587ffdc06c26a1c5b1b4fa5f22848754.zip
opensim-SC_OLD-1232eb1c587ffdc06c26a1c5b1b4fa5f22848754.tar.gz
opensim-SC_OLD-1232eb1c587ffdc06c26a1c5b1b4fa5f22848754.tar.bz2
opensim-SC_OLD-1232eb1c587ffdc06c26a1c5b1b4fa5f22848754.tar.xz
Asset server implementation. Again one of these "plumbing" releases, where no real functionality has been introduced, but ground work has been made, enabling the asset server, and preparing the sim server to query the asset server.
Introduced an "IPlugin" interface, which plugins can inherit from.
Diffstat (limited to 'OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs')
-rw-r--r--OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs133
1 files changed, 40 insertions, 93 deletions
diff --git a/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs b/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs
index 804fd5f..6423f28 100644
--- a/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs
+++ b/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs
@@ -28,7 +28,6 @@
28using System; 28using System;
29using System.IO; 29using System.IO;
30using System.Data; 30using System.Data;
31using System.Reflection;
32using System.Collections.Generic; 31using System.Collections.Generic;
33using libsecondlife; 32using libsecondlife;
34using OpenSim.Framework.Types; 33using OpenSim.Framework.Types;
@@ -65,41 +64,13 @@ namespace OpenSim.Framework.Data.MySQL
65 } 64 }
66 65
67 #region Test and initialization code 66 #region Test and initialization code
68 /// <summary>
69 /// Extract a named string resource from the embedded resources
70 /// </summary>
71 /// <param name="name">name of embedded resource</param>
72 /// <returns>string contained within the embedded resource</returns>
73 private string getResourceString(string name)
74 {
75 Assembly assem = this.GetType().Assembly;
76 string[] names = assem.GetManifestResourceNames();
77
78 foreach(string s in names)
79 if(s.EndsWith(name))
80 using (Stream resource = assem.GetManifestResourceStream(s))
81 {
82 using (StreamReader resourceReader = new StreamReader(resource))
83 {
84 string resourceString = resourceReader.ReadToEnd();
85 return resourceString;
86 }
87 }
88 throw new Exception(string.Format("Resource '{0}' was not found", name));
89 }
90 67
91 private void ExecuteResourceSql(MySqlConnection conn, string name) 68 private void UpgradeFoldersTable(string oldVersion)
92 {
93 MySqlCommand cmd = new MySqlCommand(getResourceString(name), conn);
94 cmd.ExecuteNonQuery();
95 }
96
97 private void UpgradeFoldersTable(MySqlConnection conn, string oldVersion)
98 { 69 {
99 // null as the version, indicates that the table didn't exist 70 // null as the version, indicates that the table didn't exist
100 if (oldVersion == null) 71 if (oldVersion == null)
101 { 72 {
102 ExecuteResourceSql(conn, "CreateFoldersTable.sql"); 73 database.ExecuteResourceSql("CreateFoldersTable.sql");
103 return; 74 return;
104 } 75 }
105 76
@@ -107,15 +78,15 @@ namespace OpenSim.Framework.Data.MySQL
107 if (oldVersion == "Rev. 2") 78 if (oldVersion == "Rev. 2")
108 return; 79 return;
109 80
110 ExecuteResourceSql(conn, "UpgradeFoldersTableToVersion2.sql"); 81 database.ExecuteResourceSql("UpgradeFoldersTableToVersion2.sql");
111 } 82 }
112 83
113 private void UpgradeItemsTable(MySqlConnection conn, string oldVersion) 84 private void UpgradeItemsTable(string oldVersion)
114 { 85 {
115 // null as the version, indicates that the table didn't exist 86 // null as the version, indicates that the table didn't exist
116 if (oldVersion == null) 87 if (oldVersion == null)
117 { 88 {
118 ExecuteResourceSql(conn, "CreateItemsTable.sql"); 89 database.ExecuteResourceSql("CreateItemsTable.sql");
119 return; 90 return;
120 } 91 }
121 92
@@ -123,7 +94,7 @@ namespace OpenSim.Framework.Data.MySQL
123 if (oldVersion == "Rev. 2") 94 if (oldVersion == "Rev. 2")
124 return; 95 return;
125 96
126 ExecuteResourceSql(conn, "UpgradeItemsTableToVersion2.sql"); 97 database.ExecuteResourceSql("UpgradeItemsTableToVersion2.sql");
127 } 98 }
128 99
129 private void TestTables(MySqlConnection conn) 100 private void TestTables(MySqlConnection conn)
@@ -134,25 +105,10 @@ namespace OpenSim.Framework.Data.MySQL
134 tableList["inventoryfolders"] = null; 105 tableList["inventoryfolders"] = null;
135 tableList["inventoryitems"] = null; 106 tableList["inventoryitems"] = null;
136 107
137 MySqlCommand tablesCmd = new MySqlCommand("SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='opensim'", conn); 108 database.GetTableVersion(tableList);
138 MySqlDataReader tables = tablesCmd.ExecuteReader();
139 while (tables.Read())
140 {
141 try
142 {
143 string tableName = (string)tables["TABLE_NAME"];
144 string comment = (string)tables["TABLE_COMMENT"];
145 tableList[tableName] = comment;
146 }
147 catch (Exception e)
148 {
149 MainLog.Instance.Error(e.ToString());
150 }
151 }
152 tables.Close();
153 109
154 UpgradeFoldersTable(conn, tableList["inventoryfolders"]); 110 UpgradeFoldersTable(tableList["inventoryfolders"]);
155 UpgradeItemsTable(conn, tableList["inventoryitems"]); 111 UpgradeItemsTable(tableList["inventoryitems"]);
156 } 112 }
157 #endregion 113 #endregion
158 114
@@ -179,12 +135,7 @@ namespace OpenSim.Framework.Data.MySQL
179 /// <returns>A string containing the DB provider</returns> 135 /// <returns>A string containing the DB provider</returns>
180 public string getVersion() 136 public string getVersion()
181 { 137 {
182 System.Reflection.Module module = this.GetType().Module; 138 return database.getVersion();
183 string dllName = module.Assembly.ManifestModule.Name;
184 Version dllVersion = module.Assembly.GetName().Version;
185
186
187 return string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, dllVersion.Revision);
188 } 139 }
189 140
190 /// <summary> 141 /// <summary>
@@ -201,7 +152,7 @@ namespace OpenSim.Framework.Data.MySQL
201 List<InventoryItemBase> items = new List<InventoryItemBase>(); 152 List<InventoryItemBase> items = new List<InventoryItemBase>();
202 153
203 MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE parentFolderID = ?uuid", database.Connection); 154 MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE parentFolderID = ?uuid", database.Connection);
204 result.Parameters.Add("?uuid", folderID.ToStringHyphenated()); 155 result.Parameters.AddWithValue("?uuid", folderID.ToStringHyphenated());
205 MySqlDataReader reader = result.ExecuteReader(); 156 MySqlDataReader reader = result.ExecuteReader();
206 157
207 while(reader.Read()) 158 while(reader.Read())
@@ -233,8 +184,8 @@ namespace OpenSim.Framework.Data.MySQL
233 lock (database) 184 lock (database)
234 { 185 {
235 MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", database.Connection); 186 MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", database.Connection);
236 result.Parameters.Add("?uuid", user.ToStringHyphenated()); 187 result.Parameters.AddWithValue("?uuid", user.ToStringHyphenated());
237 result.Parameters.Add("?zero", LLUUID.Zero.ToStringHyphenated()); 188 result.Parameters.AddWithValue("?zero", LLUUID.Zero.ToStringHyphenated());
238 MySqlDataReader reader = result.ExecuteReader(); 189 MySqlDataReader reader = result.ExecuteReader();
239 190
240 List<InventoryFolderBase> items = new List<InventoryFolderBase>(); 191 List<InventoryFolderBase> items = new List<InventoryFolderBase>();
@@ -267,13 +218,9 @@ namespace OpenSim.Framework.Data.MySQL
267 { 218 {
268 lock (database) 219 lock (database)
269 { 220 {
270 Dictionary<string, string> param = new Dictionary<string, string>();
271 param["?uuid"] = user.ToStringHyphenated();
272 param["?zero"] = LLUUID.Zero.ToStringHyphenated();
273
274 MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", database.Connection); 221 MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", database.Connection);
275 result.Parameters.Add("?uuid", user.ToStringHyphenated()); 222 result.Parameters.AddWithValue("?uuid", user.ToStringHyphenated());
276 result.Parameters.Add("?zero", LLUUID.Zero.ToStringHyphenated()); 223 result.Parameters.AddWithValue("?zero", LLUUID.Zero.ToStringHyphenated());
277 224
278 MySqlDataReader reader = result.ExecuteReader(); 225 MySqlDataReader reader = result.ExecuteReader();
279 226
@@ -308,7 +255,7 @@ namespace OpenSim.Framework.Data.MySQL
308 lock (database) 255 lock (database)
309 { 256 {
310 MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?uuid", database.Connection); 257 MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?uuid", database.Connection);
311 result.Parameters.Add("?uuid", parentID.ToStringHyphenated()); 258 result.Parameters.AddWithValue("?uuid", parentID.ToStringHyphenated());
312 MySqlDataReader reader = result.ExecuteReader(); 259 MySqlDataReader reader = result.ExecuteReader();
313 260
314 List<InventoryFolderBase> items = new List<InventoryFolderBase>(); 261 List<InventoryFolderBase> items = new List<InventoryFolderBase>();
@@ -378,7 +325,7 @@ namespace OpenSim.Framework.Data.MySQL
378 Dictionary<string, string> param = new Dictionary<string, string>(); 325 Dictionary<string, string> param = new Dictionary<string, string>();
379 326
380 MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE inventoryID = ?uuid", database.Connection); 327 MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE inventoryID = ?uuid", database.Connection);
381 result.Parameters.Add("?uuid", itemID.ToStringHyphenated()); 328 result.Parameters.AddWithValue("?uuid", itemID.ToStringHyphenated());
382 MySqlDataReader reader = result.ExecuteReader(); 329 MySqlDataReader reader = result.ExecuteReader();
383 330
384 InventoryItemBase item = null; 331 InventoryItemBase item = null;
@@ -438,7 +385,7 @@ namespace OpenSim.Framework.Data.MySQL
438 lock (database) 385 lock (database)
439 { 386 {
440 MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", database.Connection); 387 MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", database.Connection);
441 result.Parameters.Add("?uuid", folderID.ToStringHyphenated()); 388 result.Parameters.AddWithValue("?uuid", folderID.ToStringHyphenated());
442 MySqlDataReader reader = result.ExecuteReader(); 389 MySqlDataReader reader = result.ExecuteReader();
443 390
444 reader.Read(); 391 reader.Read();
@@ -469,19 +416,19 @@ namespace OpenSim.Framework.Data.MySQL
469 try 416 try
470 { 417 {
471 MySqlCommand result = new MySqlCommand(sql, database.Connection); 418 MySqlCommand result = new MySqlCommand(sql, database.Connection);
472 result.Parameters.Add("?inventoryID", item.inventoryID.ToStringHyphenated()); 419 result.Parameters.AddWithValue("?inventoryID", item.inventoryID.ToStringHyphenated());
473 result.Parameters.Add("?assetID", item.assetID.ToStringHyphenated()); 420 result.Parameters.AddWithValue("?assetID", item.assetID.ToStringHyphenated());
474 result.Parameters.Add("?assetType", item.assetType.ToString()); 421 result.Parameters.AddWithValue("?assetType", item.assetType.ToString());
475 result.Parameters.Add("?parentFolderID", item.parentFolderID.ToStringHyphenated()); 422 result.Parameters.AddWithValue("?parentFolderID", item.parentFolderID.ToStringHyphenated());
476 result.Parameters.Add("?avatarID", item.avatarID.ToStringHyphenated()); 423 result.Parameters.AddWithValue("?avatarID", item.avatarID.ToStringHyphenated());
477 result.Parameters.Add("?inventoryName", item.inventoryName); 424 result.Parameters.AddWithValue("?inventoryName", item.inventoryName);
478 result.Parameters.Add("?inventoryDescription", item.inventoryDescription); 425 result.Parameters.AddWithValue("?inventoryDescription", item.inventoryDescription);
479 result.Parameters.Add("?inventoryNextPermissions", item.inventoryNextPermissions.ToString()); 426 result.Parameters.AddWithValue("?inventoryNextPermissions", item.inventoryNextPermissions.ToString());
480 result.Parameters.Add("?inventoryCurrentPermissions", item.inventoryCurrentPermissions.ToString()); 427 result.Parameters.AddWithValue("?inventoryCurrentPermissions", item.inventoryCurrentPermissions.ToString());
481 result.Parameters.Add("?invType", item.invType); 428 result.Parameters.AddWithValue("?invType", item.invType);
482 result.Parameters.Add("?creatorID", item.creatorsID.ToStringHyphenated()); 429 result.Parameters.AddWithValue("?creatorID", item.creatorsID.ToStringHyphenated());
483 result.Parameters.Add("?inventoryBasePermissions", item.inventoryBasePermissions); 430 result.Parameters.AddWithValue("?inventoryBasePermissions", item.inventoryBasePermissions);
484 result.Parameters.Add("?inventoryEveryOnePermissions", item.inventoryEveryOnePermissions); 431 result.Parameters.AddWithValue("?inventoryEveryOnePermissions", item.inventoryEveryOnePermissions);
485 result.ExecuteNonQuery(); 432 result.ExecuteNonQuery();
486 result.Dispose(); 433 result.Dispose();
487 } 434 }
@@ -509,7 +456,7 @@ namespace OpenSim.Framework.Data.MySQL
509 try 456 try
510 { 457 {
511 MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryitems WHERE inventoryID=?uuid", database.Connection); 458 MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryitems WHERE inventoryID=?uuid", database.Connection);
512 cmd.Parameters.Add("?uuid", itemID.ToStringHyphenated()); 459 cmd.Parameters.AddWithValue("?uuid", itemID.ToStringHyphenated());
513 cmd.ExecuteNonQuery(); 460 cmd.ExecuteNonQuery();
514 } 461 }
515 catch (MySqlException e) 462 catch (MySqlException e)
@@ -529,12 +476,12 @@ namespace OpenSim.Framework.Data.MySQL
529 sql += "(?folderID, ?agentID, ?parentFolderID, ?folderName, ?type, ?version)"; 476 sql += "(?folderID, ?agentID, ?parentFolderID, ?folderName, ?type, ?version)";
530 477
531 MySqlCommand cmd = new MySqlCommand(sql, database.Connection); 478 MySqlCommand cmd = new MySqlCommand(sql, database.Connection);
532 cmd.Parameters.Add("?folderID", folder.folderID.ToStringHyphenated()); 479 cmd.Parameters.AddWithValue("?folderID", folder.folderID.ToStringHyphenated());
533 cmd.Parameters.Add("?agentID", folder.agentID.ToStringHyphenated()); 480 cmd.Parameters.AddWithValue("?agentID", folder.agentID.ToStringHyphenated());
534 cmd.Parameters.Add("?parentFolderID", folder.parentID.ToStringHyphenated()); 481 cmd.Parameters.AddWithValue("?parentFolderID", folder.parentID.ToStringHyphenated());
535 cmd.Parameters.Add("?folderName", folder.name); 482 cmd.Parameters.AddWithValue("?folderName", folder.name);
536 cmd.Parameters.Add("?type", (short)folder.type); 483 cmd.Parameters.AddWithValue("?type", (short)folder.type);
537 cmd.Parameters.Add("?version", folder.version); 484 cmd.Parameters.AddWithValue("?version", folder.version);
538 485
539 try 486 try
540 { 487 {
@@ -590,7 +537,7 @@ namespace OpenSim.Framework.Data.MySQL
590 try 537 try
591 { 538 {
592 MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryfolders WHERE folderID=?uuid", database.Connection); 539 MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryfolders WHERE folderID=?uuid", database.Connection);
593 cmd.Parameters.Add("?uuid", folderID.ToStringHyphenated()); 540 cmd.Parameters.AddWithValue("?uuid", folderID.ToStringHyphenated());
594 cmd.ExecuteNonQuery(); 541 cmd.ExecuteNonQuery();
595 } 542 }
596 catch (MySqlException e) 543 catch (MySqlException e)
@@ -605,7 +552,7 @@ namespace OpenSim.Framework.Data.MySQL
605 try 552 try
606 { 553 {
607 MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryitems WHERE parentFolderID=?uuid", database.Connection); 554 MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryitems WHERE parentFolderID=?uuid", database.Connection);
608 cmd.Parameters.Add("?uuid", folderID.ToStringHyphenated()); 555 cmd.Parameters.AddWithValue("?uuid", folderID.ToStringHyphenated());
609 cmd.ExecuteNonQuery(); 556 cmd.ExecuteNonQuery();
610 } 557 }
611 catch (MySqlException e) 558 catch (MySqlException e)