diff options
author | Tleiades Hax | 2007-10-13 07:26:21 +0000 |
---|---|---|
committer | Tleiades Hax | 2007-10-13 07:26:21 +0000 |
commit | 1232eb1c587ffdc06c26a1c5b1b4fa5f22848754 (patch) | |
tree | 468fb8483a2cd03e472a6988ef60f1c8ff01c07e /OpenSim/Framework/Data.MySQL | |
parent | Change 3 UserServer login messages from writeline to MainLog to help diagnose... (diff) | |
download | opensim-SC-1232eb1c587ffdc06c26a1c5b1b4fa5f22848754.zip opensim-SC-1232eb1c587ffdc06c26a1c5b1b4fa5f22848754.tar.gz opensim-SC-1232eb1c587ffdc06c26a1c5b1b4fa5f22848754.tar.bz2 opensim-SC-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')
-rw-r--r-- | OpenSim/Framework/Data.MySQL/MySQLAssetData.cs | 112 | ||||
-rw-r--r-- | OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs | 133 | ||||
-rw-r--r-- | OpenSim/Framework/Data.MySQL/MySQLManager.cs | 92 | ||||
-rw-r--r-- | OpenSim/Framework/Data.MySQL/Resources/CreateAssetsTable.sql | 11 |
4 files changed, 252 insertions, 96 deletions
diff --git a/OpenSim/Framework/Data.MySQL/MySQLAssetData.cs b/OpenSim/Framework/Data.MySQL/MySQLAssetData.cs new file mode 100644 index 0000000..70e04b6 --- /dev/null +++ b/OpenSim/Framework/Data.MySQL/MySQLAssetData.cs | |||
@@ -0,0 +1,112 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using MySql.Data.MySqlClient; | ||
4 | |||
5 | using libsecondlife; | ||
6 | using OpenSim.Framework.Console; | ||
7 | using OpenSim.Framework.Interfaces; | ||
8 | using OpenSim.Framework.Types; | ||
9 | |||
10 | namespace OpenSim.Framework.Data.MySQL | ||
11 | { | ||
12 | class MySQLAssetData : IAssetProvider | ||
13 | { | ||
14 | MySQLManager _dbConnection; | ||
15 | #region IAssetProvider Members | ||
16 | |||
17 | private void UpgradeAssetsTable(string oldVersion) | ||
18 | { | ||
19 | // null as the version, indicates that the table didn't exist | ||
20 | if (oldVersion == null) | ||
21 | { | ||
22 | MainLog.Instance.Notice("ASSETS", "Creating new database tables"); | ||
23 | _dbConnection.ExecuteResourceSql("CreateAssetsTable.sql"); | ||
24 | return; | ||
25 | } | ||
26 | } | ||
27 | |||
28 | /// <summary> | ||
29 | /// Ensure that the assets related tables exists and are at the latest version | ||
30 | /// </summary> | ||
31 | private void TestTables() | ||
32 | { | ||
33 | |||
34 | Dictionary<string, string> tableList = new Dictionary<string, string>(); | ||
35 | |||
36 | tableList["assets"] = null; | ||
37 | _dbConnection.GetTableVersion(tableList); | ||
38 | |||
39 | UpgradeAssetsTable(tableList["assets"]); | ||
40 | |||
41 | } | ||
42 | |||
43 | public AssetBase FetchAsset(LLUUID uuid) | ||
44 | { | ||
45 | throw new Exception("The method or operation is not implemented."); | ||
46 | } | ||
47 | |||
48 | public void CreateAsset(AssetBase asset) | ||
49 | { | ||
50 | MySqlCommand cmd = new MySqlCommand("REPLACE INTO assets(id, name, description, assetType, invType, local, temporary, data)" + | ||
51 | "VALUES(?id, ?name, ?description, ?assetType, ?invType, ?local, ?temporary, ?data)", _dbConnection.Connection); | ||
52 | MySqlParameter p = cmd.Parameters.Add("?id", MySqlDbType.Binary, 16); | ||
53 | p.Value = asset.FullID.GetBytes(); | ||
54 | cmd.Parameters.AddWithValue("?name", asset.Name); | ||
55 | cmd.Parameters.AddWithValue("?description", asset.Description); | ||
56 | cmd.Parameters.AddWithValue("?assetType", asset.Type); | ||
57 | cmd.Parameters.AddWithValue("?invType", asset.InvType); | ||
58 | cmd.Parameters.AddWithValue("?local", asset.Local); | ||
59 | cmd.Parameters.AddWithValue("?temporary", asset.Temporary); | ||
60 | cmd.Parameters.AddWithValue("?data", asset.Data); | ||
61 | cmd.ExecuteNonQuery(); | ||
62 | } | ||
63 | |||
64 | public void UpdateAsset(AssetBase asset) | ||
65 | { | ||
66 | CreateAsset(asset); | ||
67 | } | ||
68 | |||
69 | public bool ExistsAsset(LLUUID uuid) | ||
70 | { | ||
71 | throw new Exception("The method or operation is not implemented."); | ||
72 | } | ||
73 | |||
74 | /// <summary> | ||
75 | /// All writes are immediately commited to the database, so this is a no-op | ||
76 | /// </summary> | ||
77 | public void CommitAssets() | ||
78 | { | ||
79 | } | ||
80 | |||
81 | #endregion | ||
82 | |||
83 | #region IPlugin Members | ||
84 | |||
85 | public void Initialise() | ||
86 | { | ||
87 | IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini"); | ||
88 | string hostname = GridDataMySqlFile.ParseFileReadValue("hostname"); | ||
89 | string database = GridDataMySqlFile.ParseFileReadValue("database"); | ||
90 | string username = GridDataMySqlFile.ParseFileReadValue("username"); | ||
91 | string password = GridDataMySqlFile.ParseFileReadValue("password"); | ||
92 | string pooling = GridDataMySqlFile.ParseFileReadValue("pooling"); | ||
93 | string port = GridDataMySqlFile.ParseFileReadValue("port"); | ||
94 | |||
95 | _dbConnection = new MySQLManager(hostname, database, username, password, pooling, port); | ||
96 | |||
97 | TestTables(); | ||
98 | } | ||
99 | |||
100 | public string Version | ||
101 | { | ||
102 | get { return _dbConnection.getVersion(); } | ||
103 | } | ||
104 | |||
105 | public string Name | ||
106 | { | ||
107 | get { return "MySQL Asset storage engine"; } | ||
108 | } | ||
109 | |||
110 | #endregion | ||
111 | } | ||
112 | } | ||
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 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.IO; | 29 | using System.IO; |
30 | using System.Data; | 30 | using System.Data; |
31 | using System.Reflection; | ||
32 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
33 | using libsecondlife; | 32 | using libsecondlife; |
34 | using OpenSim.Framework.Types; | 33 | using 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) |
diff --git a/OpenSim/Framework/Data.MySQL/MySQLManager.cs b/OpenSim/Framework/Data.MySQL/MySQLManager.cs index ea174b2..d3f6976 100644 --- a/OpenSim/Framework/Data.MySQL/MySQLManager.cs +++ b/OpenSim/Framework/Data.MySQL/MySQLManager.cs | |||
@@ -26,10 +26,14 @@ | |||
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.IO; |
30 | using System.Data; | 30 | using System.Data; |
31 | using System.Reflection; | ||
32 | using System.Collections.Generic; | ||
31 | using libsecondlife; | 33 | using libsecondlife; |
34 | |||
32 | using MySql.Data.MySqlClient; | 35 | using MySql.Data.MySqlClient; |
36 | |||
33 | using OpenSim.Framework.Types; | 37 | using OpenSim.Framework.Types; |
34 | using OpenSim.Framework.Console; | 38 | using OpenSim.Framework.Console; |
35 | 39 | ||
@@ -114,6 +118,88 @@ namespace OpenSim.Framework.Data.MySQL | |||
114 | } | 118 | } |
115 | 119 | ||
116 | /// <summary> | 120 | /// <summary> |
121 | /// Returns the version of this DB provider | ||
122 | /// </summary> | ||
123 | /// <returns>A string containing the DB provider</returns> | ||
124 | public string getVersion() | ||
125 | { | ||
126 | System.Reflection.Module module = this.GetType().Module; | ||
127 | string dllName = module.Assembly.ManifestModule.Name; | ||
128 | Version dllVersion = module.Assembly.GetName().Version; | ||
129 | |||
130 | |||
131 | return string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, dllVersion.Revision); | ||
132 | } | ||
133 | |||
134 | |||
135 | /// <summary> | ||
136 | /// Extract a named string resource from the embedded resources | ||
137 | /// </summary> | ||
138 | /// <param name="name">name of embedded resource</param> | ||
139 | /// <returns>string contained within the embedded resource</returns> | ||
140 | private string getResourceString(string name) | ||
141 | { | ||
142 | Assembly assem = this.GetType().Assembly; | ||
143 | string[] names = assem.GetManifestResourceNames(); | ||
144 | |||
145 | foreach (string s in names) | ||
146 | if (s.EndsWith(name)) | ||
147 | using (Stream resource = assem.GetManifestResourceStream(s)) | ||
148 | { | ||
149 | using (StreamReader resourceReader = new StreamReader(resource)) | ||
150 | { | ||
151 | string resourceString = resourceReader.ReadToEnd(); | ||
152 | return resourceString; | ||
153 | } | ||
154 | } | ||
155 | throw new Exception(string.Format("Resource '{0}' was not found", name)); | ||
156 | } | ||
157 | |||
158 | /// <summary> | ||
159 | /// Execute a SQL statement stored in a resource, as a string | ||
160 | /// </summary> | ||
161 | /// <param name="name"></param> | ||
162 | public void ExecuteResourceSql(string name) | ||
163 | { | ||
164 | MySqlCommand cmd = new MySqlCommand(getResourceString(name), dbcon); | ||
165 | cmd.ExecuteNonQuery(); | ||
166 | } | ||
167 | |||
168 | /// <summary> | ||
169 | /// Given a list of tables, return the version of the tables, as seen in the database | ||
170 | /// </summary> | ||
171 | /// <param name="tableList"></param> | ||
172 | public void GetTableVersion(Dictionary<string, string> tableList) | ||
173 | { | ||
174 | lock (dbcon) | ||
175 | { | ||
176 | MySqlCommand tablesCmd = new MySqlCommand("SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=?dbname", dbcon); | ||
177 | tablesCmd.Parameters.AddWithValue("?dbname", dbcon.Database); | ||
178 | using (MySqlDataReader tables = tablesCmd.ExecuteReader()) | ||
179 | { | ||
180 | while (tables.Read()) | ||
181 | { | ||
182 | try | ||
183 | { | ||
184 | string tableName = (string)tables["TABLE_NAME"]; | ||
185 | string comment = (string)tables["TABLE_COMMENT"]; | ||
186 | if(tableList.ContainsKey(tableName)) | ||
187 | tableList[tableName] = comment; | ||
188 | } | ||
189 | catch (Exception e) | ||
190 | { | ||
191 | MainLog.Instance.Error(e.ToString()); | ||
192 | } | ||
193 | } | ||
194 | tables.Close(); | ||
195 | } | ||
196 | } | ||
197 | } | ||
198 | |||
199 | |||
200 | // at some time this code should be cleaned up | ||
201 | |||
202 | /// <summary> | ||
117 | /// Runs a query with protection against SQL Injection by using parameterised input. | 203 | /// Runs a query with protection against SQL Injection by using parameterised input. |
118 | /// </summary> | 204 | /// </summary> |
119 | /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param> | 205 | /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param> |
@@ -127,7 +213,7 @@ namespace OpenSim.Framework.Data.MySQL | |||
127 | dbcommand.CommandText = sql; | 213 | dbcommand.CommandText = sql; |
128 | foreach (KeyValuePair<string, string> param in parameters) | 214 | foreach (KeyValuePair<string, string> param in parameters) |
129 | { | 215 | { |
130 | dbcommand.Parameters.Add(param.Key, param.Value); | 216 | dbcommand.Parameters.AddWithValue(param.Key, param.Value); |
131 | } | 217 | } |
132 | 218 | ||
133 | return (IDbCommand)dbcommand; | 219 | return (IDbCommand)dbcommand; |
@@ -161,7 +247,7 @@ namespace OpenSim.Framework.Data.MySQL | |||
161 | dbcommand.CommandText = sql; | 247 | dbcommand.CommandText = sql; |
162 | foreach (KeyValuePair<string, string> param in parameters) | 248 | foreach (KeyValuePair<string, string> param in parameters) |
163 | { | 249 | { |
164 | dbcommand.Parameters.Add(param.Key, param.Value); | 250 | dbcommand.Parameters.AddWithValue(param.Key, param.Value); |
165 | } | 251 | } |
166 | 252 | ||
167 | return (IDbCommand)dbcommand; | 253 | return (IDbCommand)dbcommand; |
diff --git a/OpenSim/Framework/Data.MySQL/Resources/CreateAssetsTable.sql b/OpenSim/Framework/Data.MySQL/Resources/CreateAssetsTable.sql new file mode 100644 index 0000000..049a3a2 --- /dev/null +++ b/OpenSim/Framework/Data.MySQL/Resources/CreateAssetsTable.sql | |||
@@ -0,0 +1,11 @@ | |||
1 | CREATE TABLE `assets` ( | ||
2 | `id` binary(16) NOT NULL, | ||
3 | `name` varchar(64) NOT NULL, | ||
4 | `description` varchar(64) NOT NULL, | ||
5 | `assetType` smallint(5) unsigned NOT NULL, | ||
6 | `invType` smallint(5) unsigned NOT NULL, | ||
7 | `local` tinyint(1) NOT NULL, | ||
8 | `temporary` tinyint(1) NOT NULL, | ||
9 | `data` longblob NOT NULL, | ||
10 | PRIMARY KEY (`id`) | ||
11 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Rev. 1'; \ No newline at end of file | ||