From efd90b56b761219af6425b1c7a2cdd3b6ffb4de2 Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Thu, 27 Dec 2007 21:41:48 +0000 Subject: * Optimized usings * shortened references * Removed redundant 'this' * Normalized EOF --- OpenSim/Framework/Data.MSSQL/MSSQLAssetData.cs | 59 ++--- OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs | 46 ++-- OpenSim/Framework/Data.MSSQL/MSSQLInventoryData.cs | 163 +++++++------ OpenSim/Framework/Data.MSSQL/MSSQLLogData.cs | 13 +- OpenSim/Framework/Data.MSSQL/MSSQLManager.cs | 261 +++++++++++---------- OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs | 142 +++++------ 6 files changed, 343 insertions(+), 341 deletions(-) (limited to 'OpenSim/Framework/Data.MSSQL') diff --git a/OpenSim/Framework/Data.MSSQL/MSSQLAssetData.cs b/OpenSim/Framework/Data.MSSQL/MSSQLAssetData.cs index cc0422c..08fbef0 100644 --- a/OpenSim/Framework/Data.MSSQL/MSSQLAssetData.cs +++ b/OpenSim/Framework/Data.MSSQL/MSSQLAssetData.cs @@ -27,18 +27,18 @@ */ using System; -using System.Data; using System.Collections.Generic; +using System.Data; using System.Data.SqlClient; - using libsecondlife; using OpenSim.Framework.Console; namespace OpenSim.Framework.Data.MSSQL { - class MSSQLAssetData : IAssetProvider + internal class MSSQLAssetData : IAssetProvider { - MSSQLManager database; + private MSSQLManager database; + #region IAssetProvider Members private void UpgradeAssetsTable(string tableName) @@ -46,7 +46,7 @@ namespace OpenSim.Framework.Data.MSSQL // null as the version, indicates that the table didn't exist if (tableName == null) { - MainLog.Instance.Notice("ASSETS", "Creating new database tables"); + MainLog.Instance.Notice("ASSETS", "Creating new database tables"); database.ExecuteResourceSql("CreateAssetsTable.sql"); return; } @@ -57,14 +57,12 @@ namespace OpenSim.Framework.Data.MSSQL /// private void TestTables() { - Dictionary tableList = new Dictionary(); tableList["assets"] = null; database.GetTableVersion(tableList); UpgradeAssetsTable(tableList["assets"]); - } public AssetBase FetchAsset(LLUUID assetID) @@ -80,30 +78,27 @@ namespace OpenSim.Framework.Data.MSSQL asset = database.getAssetRow(reader); reader.Close(); result.Dispose(); - + return asset; } public void CreateAsset(AssetBase asset) { - - if (ExistsAsset((LLUUID)asset.FullID)) + if (ExistsAsset((LLUUID) asset.FullID)) { return; } - SqlCommand cmd = new SqlCommand( - "INSERT INTO assets ([id], [name], [description], [assetType], [invType], [local], [temporary], [data])"+ - " VALUES "+ + "INSERT INTO assets ([id], [name], [description], [assetType], [invType], [local], [temporary], [data])" + + " VALUES " + "(@id, @name, @description, @assetType, @invType, @local, @temporary, @data)", database.getConnection()); - + using (cmd) { - //SqlParameter p = cmd.Parameters.Add("id", SqlDbType.NVarChar); //p.Value = asset.FullID.ToString(); cmd.Parameters.AddWithValue("id", asset.FullID.ToString()); @@ -127,24 +122,23 @@ namespace OpenSim.Framework.Data.MSSQL { throw; } - + cmd.Dispose(); } - } public void UpdateAsset(AssetBase asset) { SqlCommand command = new SqlCommand("UPDATE assets set id = @id, " + - "name = @name, " + - "description = @description," + - "assetType = @assetType," + - "invType = @invType," + - "local = @local,"+ - "temporary = @temporary," + - "data = @data where " + - "id = @keyId;", database.getConnection()); + "name = @name, " + + "description = @description," + + "assetType = @assetType," + + "invType = @invType," + + "local = @local," + + "temporary = @temporary," + + "data = @data where " + + "id = @keyId;", database.getConnection()); SqlParameter param1 = new SqlParameter("@id", asset.FullID.ToString()); SqlParameter param2 = new SqlParameter("@name", asset.Name); SqlParameter param3 = new SqlParameter("@description", asset.Description); @@ -172,12 +166,12 @@ namespace OpenSim.Framework.Data.MSSQL { MainLog.Instance.Error(e.ToString()); } - } public bool ExistsAsset(LLUUID uuid) { - if (FetchAsset(uuid) != null) { + if (FetchAsset(uuid) != null) + { return true; } return false; @@ -194,11 +188,8 @@ namespace OpenSim.Framework.Data.MSSQL #region IPlugin Members - - public void Initialise() { - IniFile GridDataMySqlFile = new IniFile("mssql_connection.ini"); string settingDataSource = GridDataMySqlFile.ParseFileReadValue("data_source"); string settingInitialCatalog = GridDataMySqlFile.ParseFileReadValue("initial_catalog"); @@ -206,7 +197,9 @@ namespace OpenSim.Framework.Data.MSSQL string settingUserId = GridDataMySqlFile.ParseFileReadValue("user_id"); string settingPassword = GridDataMySqlFile.ParseFileReadValue("password"); - this.database = new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, settingPassword); + database = + new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, + settingPassword); TestTables(); } @@ -214,7 +207,7 @@ namespace OpenSim.Framework.Data.MSSQL public string Version { // get { return database.getVersion(); } - get { return database.getVersion(); } + get { return database.getVersion(); } } public string Name @@ -224,4 +217,4 @@ namespace OpenSim.Framework.Data.MSSQL #endregion } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs b/OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs index 72db568..7d228e6 100644 --- a/OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs +++ b/OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs @@ -57,8 +57,9 @@ namespace OpenSim.Framework.Data.MSSQL string settingUserId = GridDataMySqlFile.ParseFileReadValue("user_id"); string settingPassword = GridDataMySqlFile.ParseFileReadValue("password"); - database = new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, settingPassword); - + database = + new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, + settingPassword); } /// @@ -120,14 +121,13 @@ namespace OpenSim.Framework.Data.MSSQL result.Dispose(); return row; - } catch (Exception) - { - if (reader != null) { + { + if (reader != null) + { reader.Close(); } - } return null; } @@ -135,7 +135,6 @@ namespace OpenSim.Framework.Data.MSSQL /// /// // Returns a list of avatar and UUIDs that match the query /// - public List GeneratePickerResults(LLUUID queryID, string query) { List returnlist = new List(); @@ -152,18 +151,19 @@ namespace OpenSim.Framework.Data.MSSQL param["second"] = querysplit[1]; IDbCommand result = - database.Query("SELECT UUID,username,surname FROM users WHERE username = @first AND lastname = @second", param); + database.Query( + "SELECT UUID,username,surname FROM users WHERE username = @first AND lastname = @second", + param); IDataReader reader = result.ExecuteReader(); while (reader.Read()) { AvatarPickerAvatar user = new AvatarPickerAvatar(); - user.AvatarID = new LLUUID((string)reader["UUID"]); - user.firstName = (string)reader["username"]; - user.lastName = (string)reader["surname"]; + user.AvatarID = new LLUUID((string) reader["UUID"]); + user.firstName = (string) reader["username"]; + user.lastName = (string) reader["surname"]; returnlist.Add(user); - } reader.Close(); result.Dispose(); @@ -175,13 +175,9 @@ namespace OpenSim.Framework.Data.MSSQL MainLog.Instance.Error(e.ToString()); return returnlist; } - - - } else if (querysplit.Length == 1) { - try { lock (database) @@ -191,18 +187,19 @@ namespace OpenSim.Framework.Data.MSSQL param["second"] = querysplit[1]; IDbCommand result = - database.Query("SELECT UUID,username,surname FROM users WHERE username = @first OR lastname = @second", param); + database.Query( + "SELECT UUID,username,surname FROM users WHERE username = @first OR lastname = @second", + param); IDataReader reader = result.ExecuteReader(); while (reader.Read()) { AvatarPickerAvatar user = new AvatarPickerAvatar(); - user.AvatarID = new LLUUID((string)reader["UUID"]); - user.firstName = (string)reader["username"]; - user.lastName = (string)reader["surname"]; + user.AvatarID = new LLUUID((string) reader["UUID"]); + user.firstName = (string) reader["username"]; + user.lastName = (string) reader["surname"]; returnlist.Add(user); - } reader.Close(); result.Dispose(); @@ -225,8 +222,8 @@ namespace OpenSim.Framework.Data.MSSQL /// The sim profile public RegionProfileData GetProfileByLLUUID(LLUUID uuid) { - Dictionary param = new Dictionary(); - param["uuid"] = uuid.ToString(); + Dictionary param = new Dictionary(); + param["uuid"] = uuid.ToString(); IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = @uuid", param); IDataReader reader = result.ExecuteReader(); @@ -244,7 +241,6 @@ namespace OpenSim.Framework.Data.MSSQL /// A dataresponse enum indicating success public DataResponse AddProfile(RegionProfileData profile) { - try { if (GetProfileByLLUUID(profile.UUID) != null) @@ -310,4 +306,4 @@ namespace OpenSim.Framework.Data.MSSQL return null; } } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Data.MSSQL/MSSQLInventoryData.cs b/OpenSim/Framework/Data.MSSQL/MSSQLInventoryData.cs index a6b8819..4b2c7af 100644 --- a/OpenSim/Framework/Data.MSSQL/MSSQLInventoryData.cs +++ b/OpenSim/Framework/Data.MSSQL/MSSQLInventoryData.cs @@ -26,10 +26,9 @@ * */ using System; -using System.IO; +using System.Collections.Generic; using System.Data; using System.Data.SqlClient; -using System.Collections.Generic; using libsecondlife; using OpenSim.Framework.Console; @@ -57,7 +56,9 @@ namespace OpenSim.Framework.Data.MSSQL string settingUserId = GridDataMySqlFile.ParseFileReadValue("user_id"); string settingPassword = GridDataMySqlFile.ParseFileReadValue("password"); - database = new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, settingPassword); + database = + new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, + settingPassword); TestTables(); } @@ -72,7 +73,6 @@ namespace OpenSim.Framework.Data.MSSQL //database.ExecuteResourceSql("UpgradeFoldersTableToVersion2.sql"); return; } - } private void UpgradeItemsTable(string tableName) @@ -88,17 +88,17 @@ namespace OpenSim.Framework.Data.MSSQL private void TestTables() { - Dictionary tableList = new Dictionary(); tableList["inventoryfolders"] = null; tableList["inventoryitems"] = null; database.GetTableVersion(tableList); - + UpgradeFoldersTable(tableList["inventoryfolders"]); UpgradeItemsTable(tableList["inventoryitems"]); } + #endregion /// @@ -124,7 +124,7 @@ namespace OpenSim.Framework.Data.MSSQL /// A string containing the DB provider public string getVersion() { - return database.getVersion(); + return database.getVersion(); } /// @@ -143,15 +143,16 @@ namespace OpenSim.Framework.Data.MSSQL Dictionary param = new Dictionary(); param["parentFolderID"] = folderID.ToString(); - IDbCommand result = database.Query("SELECT * FROM inventoryitems WHERE parentFolderID = @parentFolderID", param); + IDbCommand result = + database.Query("SELECT * FROM inventoryitems WHERE parentFolderID = @parentFolderID", param); IDataReader reader = result.ExecuteReader(); - while(reader.Read()) + while (reader.Read()) items.Add(readInventoryItem(reader)); reader.Close(); result.Dispose(); - + return items; } } @@ -174,16 +175,17 @@ namespace OpenSim.Framework.Data.MSSQL { lock (database) { - Dictionary param = new Dictionary(); param["uuid"] = user.ToString(); param["zero"] = LLUUID.Zero.ToString(); - IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = @zero AND agentID = @uuid", param); + IDbCommand result = + database.Query( + "SELECT * FROM inventoryfolders WHERE parentFolderID = @zero AND agentID = @uuid", param); IDataReader reader = result.ExecuteReader(); List items = new List(); - while(reader.Read()) + while (reader.Read()) items.Add(readInventoryFolder(reader)); @@ -212,24 +214,27 @@ namespace OpenSim.Framework.Data.MSSQL param["uuid"] = user.ToString(); param["zero"] = LLUUID.Zero.ToString(); - IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = @zero AND agentID = @uuid", param); + IDbCommand result = + database.Query( + "SELECT * FROM inventoryfolders WHERE parentFolderID = @zero AND agentID = @uuid", param); IDataReader reader = result.ExecuteReader(); List items = new List(); - while(reader.Read()) + while (reader.Read()) items.Add(readInventoryFolder(reader)); InventoryFolderBase rootFolder = null; - + // There should only ever be one root folder for a user. However, if there's more // than one we'll simply use the first one rather than failing. It would be even // nicer to print some message to this effect, but this feels like it's too low a // to put such a message out, and it's too minor right now to spare the time to // suitably refactor. - if (items.Count > 0) { + if (items.Count > 0) + { rootFolder = items[0]; } - + reader.Close(); result.Dispose(); @@ -259,12 +264,13 @@ namespace OpenSim.Framework.Data.MSSQL param["parentFolderID"] = parentID.ToString(); - IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = @parentFolderID", param); + IDbCommand result = + database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = @parentFolderID", param); IDataReader reader = result.ExecuteReader(); List items = new List(); - - while(reader.Read()) + + while (reader.Read()) items.Add(readInventoryFolder(reader)); reader.Close(); @@ -292,17 +298,17 @@ namespace OpenSim.Framework.Data.MSSQL { InventoryItemBase item = new InventoryItemBase(); - item.inventoryID = new LLUUID((string)reader["inventoryID"]); - item.assetID = new LLUUID((string)reader["assetID"]); - item.assetType = (int)reader["assetType"]; - item.parentFolderID = new LLUUID((string)reader["parentFolderID"]); - item.avatarID = new LLUUID((string)reader["avatarID"]); - item.inventoryName = (string)reader["inventoryName"]; - item.inventoryDescription = (string)reader["inventoryDescription"]; + item.inventoryID = new LLUUID((string) reader["inventoryID"]); + item.assetID = new LLUUID((string) reader["assetID"]); + item.assetType = (int) reader["assetType"]; + item.parentFolderID = new LLUUID((string) reader["parentFolderID"]); + item.avatarID = new LLUUID((string) reader["avatarID"]); + item.inventoryName = (string) reader["inventoryName"]; + item.inventoryDescription = (string) reader["inventoryDescription"]; item.inventoryNextPermissions = Convert.ToUInt32(reader["inventoryNextPermissions"]); item.inventoryCurrentPermissions = Convert.ToUInt32(reader["inventoryCurrentPermissions"]); - item.invType = (int)reader["invType"]; - item.creatorsID = new LLUUID((string)reader["creatorID"]); + item.invType = (int) reader["invType"]; + item.creatorsID = new LLUUID((string) reader["creatorID"]); item.inventoryBasePermissions = Convert.ToUInt32(reader["inventoryBasePermissions"]); item.inventoryEveryOnePermissions = Convert.ToUInt32(reader["inventoryEveryOnePermissions"]); return item; @@ -322,7 +328,6 @@ namespace OpenSim.Framework.Data.MSSQL /// An inventory item public InventoryItemBase getInventoryItem(LLUUID itemID) { - try { lock (database) @@ -330,11 +335,12 @@ namespace OpenSim.Framework.Data.MSSQL Dictionary param = new Dictionary(); param["inventoryID"] = itemID.ToString(); - IDbCommand result = database.Query("SELECT * FROM inventoryitems WHERE inventoryID = @inventoryID", param); + IDbCommand result = + database.Query("SELECT * FROM inventoryitems WHERE inventoryID = @inventoryID", param); IDataReader reader = result.ExecuteReader(); InventoryItemBase item = null; - if(reader.Read()) + if (reader.Read()) item = readInventoryItem(reader); reader.Close(); @@ -361,12 +367,12 @@ namespace OpenSim.Framework.Data.MSSQL try { InventoryFolderBase folder = new InventoryFolderBase(); - folder.agentID = new LLUUID((string)reader["agentID"]); - folder.parentID = new LLUUID((string)reader["parentFolderID"]); - folder.folderID = new LLUUID((string)reader["folderID"]); - folder.name = (string)reader["folderName"]; - folder.type = (short)reader["type"]; - folder.version = (ushort)((int)reader["version"]); + folder.agentID = new LLUUID((string) reader["agentID"]); + folder.parentID = new LLUUID((string) reader["parentFolderID"]); + folder.folderID = new LLUUID((string) reader["folderID"]); + folder.name = (string) reader["folderName"]; + folder.type = (short) reader["type"]; + folder.version = (ushort) ((int) reader["version"]); return folder; } catch (Exception e) @@ -389,7 +395,7 @@ namespace OpenSim.Framework.Data.MSSQL { lock (database) { - Dictionary param = new Dictionary(); + Dictionary param = new Dictionary(); param["uuid"] = folderID.ToString(); IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE folderID = @uuid", param); @@ -418,8 +424,10 @@ namespace OpenSim.Framework.Data.MSSQL public void addInventoryItem(InventoryItemBase item) { string sql = "INSERT INTO inventoryitems"; - sql += "([inventoryID], [assetID], [assetType], [parentFolderID], [avatarID], [inventoryName], [inventoryDescription], [inventoryNextPermissions], [inventoryCurrentPermissions], [invType], [creatorID], [inventoryBasePermissions], [inventoryEveryOnePermissions]) VALUES "; - sql += "(@inventoryID, @assetID, @assetType, @parentFolderID, @avatarID, @inventoryName, @inventoryDescription, @inventoryNextPermissions, @inventoryCurrentPermissions, @invType, @creatorID, @inventoryBasePermissions, @inventoryEveryOnePermissions);"; + sql += + "([inventoryID], [assetID], [assetType], [parentFolderID], [avatarID], [inventoryName], [inventoryDescription], [inventoryNextPermissions], [inventoryCurrentPermissions], [invType], [creatorID], [inventoryBasePermissions], [inventoryEveryOnePermissions]) VALUES "; + sql += + "(@inventoryID, @assetID, @assetType, @parentFolderID, @avatarID, @inventoryName, @inventoryDescription, @inventoryNextPermissions, @inventoryCurrentPermissions, @invType, @creatorID, @inventoryBasePermissions, @inventoryEveryOnePermissions);"; try { @@ -441,7 +449,6 @@ namespace OpenSim.Framework.Data.MSSQL IDbCommand result = database.Query(sql, param); result.ExecuteNonQuery(); result.Dispose(); - } catch (SqlException e) { @@ -454,21 +461,21 @@ namespace OpenSim.Framework.Data.MSSQL /// /// Inventory item to update public void updateInventoryItem(InventoryItemBase item) - { + { SqlCommand command = new SqlCommand("UPDATE inventoryitems set inventoryID = @inventoryID, " + - "assetID = @assetID, " + - "assetType = @assetType" + - "parentFolderID = @parentFolderID" + - "avatarID = @avatarID" + - "inventoryName = @inventoryName"+ - "inventoryDescription = @inventoryDescription" + - "inventoryNextPermissions = @inventoryNextPermissions" + - "inventoryCurrentPermissions = @inventoryCurrentPermissions" + - "invType = @invType" + - "creatorID = @creatorID" + - "inventoryBasePermissions = @inventoryBasePermissions" + - "inventoryEveryOnePermissions = @inventoryEveryOnePermissions) where " + - "invenoryID = @keyInventoryID;", database.getConnection()); + "assetID = @assetID, " + + "assetType = @assetType" + + "parentFolderID = @parentFolderID" + + "avatarID = @avatarID" + + "inventoryName = @inventoryName" + + "inventoryDescription = @inventoryDescription" + + "inventoryNextPermissions = @inventoryNextPermissions" + + "inventoryCurrentPermissions = @inventoryCurrentPermissions" + + "invType = @invType" + + "creatorID = @creatorID" + + "inventoryBasePermissions = @inventoryBasePermissions" + + "inventoryEveryOnePermissions = @inventoryEveryOnePermissions) where " + + "invenoryID = @keyInventoryID;", database.getConnection()); SqlParameter param1 = new SqlParameter("@inventoryID", item.inventoryID.ToString()); SqlParameter param2 = new SqlParameter("@assetID", item.assetID); SqlParameter param3 = new SqlParameter("@assetType", item.assetType); @@ -481,7 +488,7 @@ namespace OpenSim.Framework.Data.MSSQL SqlParameter param10 = new SqlParameter("@invType", item.invType); SqlParameter param11 = new SqlParameter("@creatorID", item.creatorsID); SqlParameter param12 = new SqlParameter("@inventoryBasePermissions", item.inventoryBasePermissions); - SqlParameter param13 = new SqlParameter("@inventoryEveryOnePermissions", item.inventoryEveryOnePermissions); + SqlParameter param13 = new SqlParameter("@inventoryEveryOnePermissions", item.inventoryEveryOnePermissions); SqlParameter param14 = new SqlParameter("@keyInventoryID", item.inventoryID.ToString()); command.Parameters.Add(param1); command.Parameters.Add(param2); @@ -506,7 +513,6 @@ namespace OpenSim.Framework.Data.MSSQL { MainLog.Instance.Error(e.ToString()); } - } /// @@ -523,8 +529,6 @@ namespace OpenSim.Framework.Data.MSSQL IDbCommand cmd = database.Query("DELETE FROM inventoryitems WHERE inventoryID=@uuid", param); cmd.ExecuteNonQuery(); cmd.Dispose(); - - } catch (SqlException e) { @@ -539,7 +543,8 @@ namespace OpenSim.Framework.Data.MSSQL /// Folder to create public void addInventoryFolder(InventoryFolderBase folder) { - string sql = "INSERT INTO inventoryfolders ([folderID], [agentID], [parentFolderID], [folderName], [type], [version]) VALUES "; + string sql = + "INSERT INTO inventoryfolders ([folderID], [agentID], [parentFolderID], [folderName], [type], [version]) VALUES "; sql += "(@folderID, @agentID, @parentFolderID, @folderName, @type, @version);"; @@ -550,9 +555,9 @@ namespace OpenSim.Framework.Data.MSSQL param["folderName"] = folder.name; param["type"] = Convert.ToString(folder.type); param["version"] = Convert.ToString(folder.version); - + try - { + { IDbCommand result = database.Query(sql, param); result.ExecuteNonQuery(); result.Dispose(); @@ -567,16 +572,15 @@ namespace OpenSim.Framework.Data.MSSQL /// Updates an inventory folder /// /// Folder to update - public void updateInventoryFolder(InventoryFolderBase folder) { SqlCommand command = new SqlCommand("UPDATE inventoryfolders set folderID = @folderID, " + - "agentID = @agentID, " + - "parentFolderID = @parentFolderID," + - "folderName = @folderName," + - "type = @type," + - "version = @version where " + - "folderID = @keyFolderID;", database.getConnection()); + "agentID = @agentID, " + + "parentFolderID = @parentFolderID," + + "folderName = @folderName," + + "type = @type," + + "version = @version where " + + "folderID = @keyFolderID;", database.getConnection()); SqlParameter param1 = new SqlParameter("@folderID", folder.folderID.ToString()); SqlParameter param2 = new SqlParameter("@agentID", folder.agentID.ToString()); SqlParameter param3 = new SqlParameter("@parentFolderID", folder.parentID.ToString()); @@ -600,20 +604,17 @@ namespace OpenSim.Framework.Data.MSSQL { MainLog.Instance.Error(e.ToString()); } - - } /// /// Updates an inventory folder /// /// Folder to update - public void moveInventoryFolder(InventoryFolderBase folder) { SqlCommand command = new SqlCommand("UPDATE inventoryfolders set folderID = @folderID, " + - "parentFolderID = @parentFolderID," + - "folderID = @keyFolderID;", database.getConnection()); + "parentFolderID = @parentFolderID," + + "folderID = @keyFolderID;", database.getConnection()); SqlParameter param1 = new SqlParameter("@folderID", folder.folderID.ToString()); SqlParameter param2 = new SqlParameter("@parentFolderID", folder.parentID.ToString()); SqlParameter param3 = new SqlParameter("@keyFolderID", folder.folderID.ToString()); @@ -629,8 +630,6 @@ namespace OpenSim.Framework.Data.MSSQL { MainLog.Instance.Error(e.ToString()); } - - } /// @@ -645,7 +644,7 @@ namespace OpenSim.Framework.Data.MSSQL foreach (InventoryFolderBase f in subfolderList) folders.Add(f); } - + /// /// Returns all child folders in the hierarchy from the parent folder and down /// @@ -672,7 +671,6 @@ namespace OpenSim.Framework.Data.MSSQL IDbCommand cmd = database.Query("DELETE FROM inventoryfolders WHERE folderID=@folderID", param); cmd.ExecuteNonQuery(); cmd.Dispose(); - } catch (SqlException e) { @@ -689,7 +687,8 @@ namespace OpenSim.Framework.Data.MSSQL param["parentFolderID"] = folderID.ToString(); - IDbCommand cmd = database.Query("DELETE FROM inventoryitems WHERE parentFolderID=@parentFolderID", param); + IDbCommand cmd = + database.Query("DELETE FROM inventoryitems WHERE parentFolderID=@parentFolderID", param); cmd.ExecuteNonQuery(); cmd.Dispose(); } @@ -724,4 +723,4 @@ namespace OpenSim.Framework.Data.MSSQL } } } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Data.MSSQL/MSSQLLogData.cs b/OpenSim/Framework/Data.MSSQL/MSSQLLogData.cs index a5b33ec..c3ec7c6 100644 --- a/OpenSim/Framework/Data.MSSQL/MSSQLLogData.cs +++ b/OpenSim/Framework/Data.MSSQL/MSSQLLogData.cs @@ -25,14 +25,12 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ -using System; - namespace OpenSim.Framework.Data.MSSQL { /// /// An interface to the log database for MySQL /// - class MSSQLLogData : ILogData + internal class MSSQLLogData : ILogData { /// /// The database manager @@ -51,7 +49,9 @@ namespace OpenSim.Framework.Data.MSSQL string settingUserId = GridDataMySqlFile.ParseFileReadValue("user_id"); string settingPassword = GridDataMySqlFile.ParseFileReadValue("password"); - database = new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, settingPassword); + database = + new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, + settingPassword); } /// @@ -63,7 +63,8 @@ namespace OpenSim.Framework.Data.MSSQL /// The arguments passed to the method /// How critical is this? /// The message to log - public void saveLog(string serverDaemon, string target, string methodCall, string arguments, int priority, string logMessage) + public void saveLog(string serverDaemon, string target, string methodCall, string arguments, int priority, + string logMessage) { try { @@ -101,4 +102,4 @@ namespace OpenSim.Framework.Data.MSSQL return "0.1"; } } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Data.MSSQL/MSSQLManager.cs b/OpenSim/Framework/Data.MSSQL/MSSQLManager.cs index b009a56..0dc3338 100644 --- a/OpenSim/Framework/Data.MSSQL/MSSQLManager.cs +++ b/OpenSim/Framework/Data.MSSQL/MSSQLManager.cs @@ -25,6 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ + using System; using System.Collections.Generic; using System.Data; @@ -32,7 +33,6 @@ using System.Data.SqlClient; using System.IO; using System.Reflection; using libsecondlife; - using OpenSim.Framework.Console; namespace OpenSim.Framework.Data.MSSQL @@ -40,12 +40,12 @@ namespace OpenSim.Framework.Data.MSSQL /// /// A management class for the MS SQL Storage Engine /// - class MSSQLManager + internal class MSSQLManager { /// /// The database connection object /// - IDbConnection dbcon; + private IDbConnection dbcon; /// /// Connection string for ADO.net @@ -60,12 +60,14 @@ namespace OpenSim.Framework.Data.MSSQL /// The username logging into the database /// The password for the user logging in /// Whether to use connection pooling or not, can be one of the following: 'yes', 'true', 'no' or 'false', if unsure use 'false'. - public MSSQLManager(string dataSource, string initialCatalog, string persistSecurityInfo, string userId, string password) + public MSSQLManager(string dataSource, string initialCatalog, string persistSecurityInfo, string userId, + string password) { try { - - connectionString = "Data Source=" + dataSource + ";Initial Catalog=" + initialCatalog + ";Persist Security Info=" + persistSecurityInfo + ";User ID=" + userId + ";Password=" + password+";"; + connectionString = "Data Source=" + dataSource + ";Initial Catalog=" + initialCatalog + + ";Persist Security Info=" + persistSecurityInfo + ";User ID=" + userId + ";Password=" + + password + ";"; dbcon = new SqlConnection(connectionString); TestTables(dbcon); dbcon.Open(); @@ -78,7 +80,7 @@ namespace OpenSim.Framework.Data.MSSQL private bool TestTables(IDbConnection conn) { - IDbCommand cmd = this.Query("SELECT * FROM regions", new Dictionary()); + IDbCommand cmd = Query("SELECT * FROM regions", new Dictionary()); //SqlCommand cmd = (SqlCommand)dbcon.CreateCommand(); //cmd.CommandText = "SELECT * FROM regions"; try @@ -90,7 +92,7 @@ namespace OpenSim.Framework.Data.MSSQL } catch (Exception) { - MainLog.Instance.Verbose("DATASTORE", "MSSQL Database doesn't exist... creating"); + MainLog.Instance.Verbose("DATASTORE", "MSSQL Database doesn't exist... creating"); InitDB(conn); } return true; @@ -100,66 +102,66 @@ namespace OpenSim.Framework.Data.MSSQL { string createRegions = defineTable(createRegionsTable()); Dictionary param = new Dictionary(); - IDbCommand pcmd = this.Query(createRegions, param); - if (conn.State == ConnectionState.Closed) { + IDbCommand pcmd = Query(createRegions, param); + if (conn.State == ConnectionState.Closed) + { conn.Open(); - } + } pcmd.ExecuteNonQuery(); pcmd.Dispose(); - this.ExecuteResourceSql("Mssql-users.sql"); - this.ExecuteResourceSql("Mssql-agents.sql"); - this.ExecuteResourceSql("Mssql-logs.sql"); + ExecuteResourceSql("Mssql-users.sql"); + ExecuteResourceSql("Mssql-agents.sql"); + ExecuteResourceSql("Mssql-logs.sql"); conn.Close(); - } private DataTable createRegionsTable() { DataTable regions = new DataTable("regions"); - createCol(regions, "regionHandle", typeof(ulong)); - createCol(regions, "regionName", typeof(System.String)); - createCol(regions, "uuid", typeof(System.String)); + createCol(regions, "regionHandle", typeof (ulong)); + createCol(regions, "regionName", typeof (String)); + createCol(regions, "uuid", typeof (String)); - createCol(regions, "regionRecvKey", typeof(System.String)); - createCol(regions, "regionSecret", typeof(System.String)); - createCol(regions, "regionSendKey", typeof(System.String)); + createCol(regions, "regionRecvKey", typeof (String)); + createCol(regions, "regionSecret", typeof (String)); + createCol(regions, "regionSendKey", typeof (String)); - createCol(regions, "regionDataURI", typeof(System.String)); - createCol(regions, "serverIP", typeof(System.String)); - createCol(regions, "serverPort", typeof(System.String)); - createCol(regions, "serverURI", typeof(System.String)); + createCol(regions, "regionDataURI", typeof (String)); + createCol(regions, "serverIP", typeof (String)); + createCol(regions, "serverPort", typeof (String)); + createCol(regions, "serverURI", typeof (String)); - createCol(regions, "locX", typeof(uint)); - createCol(regions, "locY", typeof(uint)); - createCol(regions, "locZ", typeof(uint)); + createCol(regions, "locX", typeof (uint)); + createCol(regions, "locY", typeof (uint)); + createCol(regions, "locZ", typeof (uint)); - createCol(regions, "eastOverrideHandle", typeof(ulong)); - createCol(regions, "westOverrideHandle", typeof(ulong)); - createCol(regions, "southOverrideHandle", typeof(ulong)); - createCol(regions, "northOverrideHandle", typeof(ulong)); + createCol(regions, "eastOverrideHandle", typeof (ulong)); + createCol(regions, "westOverrideHandle", typeof (ulong)); + createCol(regions, "southOverrideHandle", typeof (ulong)); + createCol(regions, "northOverrideHandle", typeof (ulong)); - createCol(regions, "regionAssetURI", typeof(System.String)); - createCol(regions, "regionAssetRecvKey", typeof(System.String)); - createCol(regions, "regionAssetSendKey", typeof(System.String)); + createCol(regions, "regionAssetURI", typeof (String)); + createCol(regions, "regionAssetRecvKey", typeof (String)); + createCol(regions, "regionAssetSendKey", typeof (String)); - createCol(regions, "regionUserURI", typeof(System.String)); - createCol(regions, "regionUserRecvKey", typeof(System.String)); - createCol(regions, "regionUserSendKey", typeof(System.String)); + createCol(regions, "regionUserURI", typeof (String)); + createCol(regions, "regionUserRecvKey", typeof (String)); + createCol(regions, "regionUserSendKey", typeof (String)); - createCol(regions, "regionMapTexture", typeof(System.String)); - createCol(regions, "serverHttpPort", typeof(System.String)); - createCol(regions, "serverRemotingPort", typeof(uint)); + createCol(regions, "regionMapTexture", typeof (String)); + createCol(regions, "serverHttpPort", typeof (String)); + createCol(regions, "serverRemotingPort", typeof (uint)); // Add in contraints - regions.PrimaryKey = new DataColumn[] { regions.Columns["UUID"] }; + regions.PrimaryKey = new DataColumn[] {regions.Columns["UUID"]}; return regions; } - protected static void createCol(DataTable dt, string name, System.Type type) + protected static void createCol(DataTable dt, string name, Type type) { DataColumn col = new DataColumn(name, type); dt.Columns.Add(col); @@ -172,10 +174,11 @@ namespace OpenSim.Framework.Data.MSSQL foreach (DataColumn col in dt.Columns) { if (subsql.Length > 0) - { // a map function would rock so much here + { + // a map function would rock so much here subsql += ",\n"; } - + subsql += col.ColumnName + " " + SqlType(col.DataType); if (col == dt.PrimaryKey[0]) { @@ -192,19 +195,19 @@ namespace OpenSim.Framework.Data.MSSQL // slightly differently. private static string SqlType(Type type) { - if (type == typeof(System.String)) + if (type == typeof (String)) { return "varchar(255)"; } - else if (type == typeof(System.Int32)) + else if (type == typeof (Int32)) { return "integer"; } - else if (type == typeof(System.Double)) + else if (type == typeof (Double)) { return "float"; } - else if (type == typeof(System.Byte[])) + else if (type == typeof (Byte[])) { return "image"; } @@ -254,14 +257,14 @@ namespace OpenSim.Framework.Data.MSSQL /// A Sql DB Command public IDbCommand Query(string sql, Dictionary parameters) { - SqlCommand dbcommand = (SqlCommand)dbcon.CreateCommand(); - dbcommand.CommandText = sql; + SqlCommand dbcommand = (SqlCommand) dbcon.CreateCommand(); + dbcommand.CommandText = sql; foreach (KeyValuePair param in parameters) { dbcommand.Parameters.AddWithValue(param.Key, param.Value); } - - return (IDbCommand)dbcommand; + + return (IDbCommand) dbcommand; } /// @@ -277,20 +280,20 @@ namespace OpenSim.Framework.Data.MSSQL { // Region Main regionprofile.regionHandle = Convert.ToUInt64(reader["regionHandle"]); - regionprofile.regionName = (string)reader["regionName"]; - regionprofile.UUID = new LLUUID((string)reader["uuid"]); + regionprofile.regionName = (string) reader["regionName"]; + regionprofile.UUID = new LLUUID((string) reader["uuid"]); // Secrets - regionprofile.regionRecvKey = (string)reader["regionRecvKey"]; - regionprofile.regionSecret = (string)reader["regionSecret"]; - regionprofile.regionSendKey = (string)reader["regionSendKey"]; + regionprofile.regionRecvKey = (string) reader["regionRecvKey"]; + regionprofile.regionSecret = (string) reader["regionSecret"]; + regionprofile.regionSendKey = (string) reader["regionSendKey"]; // Region Server - regionprofile.regionDataURI = (string)reader["regionDataURI"]; + regionprofile.regionDataURI = (string) reader["regionDataURI"]; regionprofile.regionOnline = false; // Needs to be pinged before this can be set. - regionprofile.serverIP = (string)reader["serverIP"]; + regionprofile.serverIP = (string) reader["serverIP"]; regionprofile.serverPort = Convert.ToUInt32(reader["serverPort"]); - regionprofile.serverURI = (string)reader["serverURI"]; + regionprofile.serverURI = (string) reader["serverURI"]; regionprofile.httpPort = Convert.ToUInt32(reader["serverHttpPort"]); regionprofile.remotingPort = Convert.ToUInt32(reader["serverRemotingPort"]); @@ -307,14 +310,14 @@ namespace OpenSim.Framework.Data.MSSQL regionprofile.regionNorthOverrideHandle = Convert.ToUInt64(reader["northOverrideHandle"]); // Assets - regionprofile.regionAssetURI = (string)reader["regionAssetURI"]; - regionprofile.regionAssetRecvKey = (string)reader["regionAssetRecvKey"]; - regionprofile.regionAssetSendKey = (string)reader["regionAssetSendKey"]; + regionprofile.regionAssetURI = (string) reader["regionAssetURI"]; + regionprofile.regionAssetRecvKey = (string) reader["regionAssetRecvKey"]; + regionprofile.regionAssetSendKey = (string) reader["regionAssetSendKey"]; // Userserver - regionprofile.regionUserURI = (string)reader["regionUserURI"]; - regionprofile.regionUserRecvKey = (string)reader["regionUserRecvKey"]; - regionprofile.regionUserSendKey = (string)reader["regionUserSendKey"]; + regionprofile.regionUserURI = (string) reader["regionUserURI"]; + regionprofile.regionUserRecvKey = (string) reader["regionUserRecvKey"]; + regionprofile.regionUserSendKey = (string) reader["regionUserSendKey"]; // World Map Addition string tempRegionMap = reader["regionMapTexture"].ToString(); @@ -331,7 +334,6 @@ namespace OpenSim.Framework.Data.MSSQL { reader.Close(); throw new Exception("No rows to return"); - } return regionprofile; } @@ -347,12 +349,12 @@ namespace OpenSim.Framework.Data.MSSQL if (reader.Read()) { - retval.UUID = new LLUUID((string)reader["UUID"]); - retval.username = (string)reader["username"]; - retval.surname = (string)reader["lastname"]; + retval.UUID = new LLUUID((string) reader["UUID"]); + retval.username = (string) reader["username"]; + retval.surname = (string) reader["lastname"]; - retval.passwordHash = (string)reader["passwordHash"]; - retval.passwordSalt = (string)reader["passwordSalt"]; + retval.passwordHash = (string) reader["passwordHash"]; + retval.passwordSalt = (string) reader["passwordSalt"]; retval.homeRegion = Convert.ToUInt64(reader["homeRegion"].ToString()); retval.homeLocation = new LLVector3( @@ -367,18 +369,17 @@ namespace OpenSim.Framework.Data.MSSQL retval.created = Convert.ToInt32(reader["created"].ToString()); retval.lastLogin = Convert.ToInt32(reader["lastLogin"].ToString()); - retval.userInventoryURI = (string)reader["userInventoryURI"]; - retval.userAssetURI = (string)reader["userAssetURI"]; + retval.userInventoryURI = (string) reader["userInventoryURI"]; + retval.userAssetURI = (string) reader["userAssetURI"]; retval.profileCanDoMask = Convert.ToUInt32(reader["profileCanDoMask"].ToString()); retval.profileWantDoMask = Convert.ToUInt32(reader["profileWantDoMask"].ToString()); - retval.profileAboutText = (string)reader["profileAboutText"]; - retval.profileFirstText = (string)reader["profileFirstText"]; - - retval.profileImage = new LLUUID((string)reader["profileImage"]); - retval.profileFirstImage = new LLUUID((string)reader["profileFirstImage"]); + retval.profileAboutText = (string) reader["profileAboutText"]; + retval.profileFirstText = (string) reader["profileFirstText"]; + retval.profileImage = new LLUUID((string) reader["profileImage"]); + retval.profileFirstImage = new LLUUID((string) reader["profileFirstImage"]); } else { @@ -399,12 +400,12 @@ namespace OpenSim.Framework.Data.MSSQL if (reader.Read()) { // Agent IDs - retval.UUID = new LLUUID((string)reader["UUID"]); - retval.sessionID = new LLUUID((string)reader["sessionID"]); - retval.secureSessionID = new LLUUID((string)reader["secureSessionID"]); + retval.UUID = new LLUUID((string) reader["UUID"]); + retval.sessionID = new LLUUID((string) reader["sessionID"]); + retval.secureSessionID = new LLUUID((string) reader["secureSessionID"]); // Agent Who? - retval.agentIP = (string)reader["agentIP"]; + retval.agentIP = (string) reader["agentIP"]; retval.agentPort = Convert.ToUInt32(reader["agentPort"].ToString()); retval.agentOnline = Convert.ToBoolean(reader["agentOnline"].ToString()); @@ -413,9 +414,9 @@ namespace OpenSim.Framework.Data.MSSQL retval.logoutTime = Convert.ToInt32(reader["logoutTime"].ToString()); // Current position - retval.currentRegion = (string)reader["currentRegion"]; + retval.currentRegion = (string) reader["currentRegion"]; retval.currentHandle = Convert.ToUInt64(reader["currentHandle"].ToString()); - LLVector3.TryParse((string)reader["currentPos"], out retval.currentPos); + LLVector3.TryParse((string) reader["currentPos"], out retval.currentPos); } else { @@ -426,20 +427,19 @@ namespace OpenSim.Framework.Data.MSSQL public AssetBase getAssetRow(IDataReader reader) { - AssetBase asset = new AssetBase(); + AssetBase asset = new AssetBase(); if (reader.Read()) { // Region Main asset = new AssetBase(); - asset.Data = (byte[])reader["data"]; - asset.Description = (string)reader["description"]; - asset.FullID = new LLUUID((string)reader["id"]); + asset.Data = (byte[]) reader["data"]; + asset.Description = (string) reader["description"]; + asset.FullID = new LLUUID((string) reader["id"]); asset.InvType = Convert.ToSByte(reader["invType"]); asset.Local = Convert.ToBoolean(reader["local"]); // ((sbyte)reader["local"]) != 0 ? true : false; - asset.Name = (string)reader["name"]; + asset.Name = (string) reader["name"]; asset.Type = Convert.ToSByte(reader["assetType"]); - } else { @@ -455,15 +455,19 @@ namespace OpenSim.Framework.Data.MSSQL /// Successful? public bool insertRegionRow(RegionProfileData profile) { - //Insert new region - string sql = "INSERT INTO regions ([regionHandle], [regionName], [uuid], [regionRecvKey], [regionSecret], [regionSendKey], [regionDataURI], "; - sql += "[serverIP], [serverPort], [serverURI], [locX], [locY], [locZ], [eastOverrideHandle], [westOverrideHandle], [southOverrideHandle], [northOverrideHandle], [regionAssetURI], [regionAssetRecvKey], "; - sql += "[regionAssetSendKey], [regionUserURI], [regionUserRecvKey], [regionUserSendKey], [regionMapTexture], [serverHttpPort], [serverRemotingPort]) VALUES "; + string sql = + "INSERT INTO regions ([regionHandle], [regionName], [uuid], [regionRecvKey], [regionSecret], [regionSendKey], [regionDataURI], "; + sql += + "[serverIP], [serverPort], [serverURI], [locX], [locY], [locZ], [eastOverrideHandle], [westOverrideHandle], [southOverrideHandle], [northOverrideHandle], [regionAssetURI], [regionAssetRecvKey], "; + sql += + "[regionAssetSendKey], [regionUserURI], [regionUserRecvKey], [regionUserSendKey], [regionMapTexture], [serverHttpPort], [serverRemotingPort]) VALUES "; sql += "(@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI, "; - sql += "@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle, @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, "; - sql += "@regionAssetSendKey, @regionUserURI, @regionUserRecvKey, @regionUserSendKey, @regionMapTexture, @serverHttpPort, @serverRemotingPort);"; + sql += + "@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle, @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, "; + sql += + "@regionAssetSendKey, @regionUserURI, @regionUserRecvKey, @regionUserSendKey, @regionMapTexture, @serverHttpPort, @serverRemotingPort);"; Dictionary parameters = new Dictionary(); @@ -498,9 +502,9 @@ namespace OpenSim.Framework.Data.MSSQL bool returnval = false; try - { + { IDbCommand result = Query(sql, parameters); - + if (result.ExecuteNonQuery() == 1) returnval = true; @@ -509,15 +513,12 @@ namespace OpenSim.Framework.Data.MSSQL catch (Exception e) { MainLog.Instance.Error("MSSQLManager : " + e.ToString()); - } return returnval; - } - /// /// Inserts a new row into the log database /// @@ -528,7 +529,8 @@ namespace OpenSim.Framework.Data.MSSQL /// How critical is this? /// Extra message info /// Saved successfully? - public bool insertLogRow(string serverDaemon, string target, string methodCall, string arguments, int priority, string logMessage) + public bool insertLogRow(string serverDaemon, string target, string methodCall, string arguments, int priority, + string logMessage) { string sql = "INSERT INTO logs ([target], [server], [method], [arguments], [priority], [message]) VALUES "; sql += "(@target, @server, @method, @arguments, @priority, @message);"; @@ -588,19 +590,26 @@ namespace OpenSim.Framework.Data.MSSQL /// UUID for profile image /// UUID for firstlife image /// Success? - public bool insertUserRow(libsecondlife.LLUUID uuid, string username, string lastname, string passwordHash, string passwordSalt, UInt64 homeRegion, float homeLocX, float homeLocY, float homeLocZ, - float homeLookAtX, float homeLookAtY, float homeLookAtZ, int created, int lastlogin, string inventoryURI, string assetURI, uint canDoMask, uint wantDoMask, string aboutText, string firstText, - libsecondlife.LLUUID profileImage, libsecondlife.LLUUID firstImage) + public bool insertUserRow(LLUUID uuid, string username, string lastname, string passwordHash, + string passwordSalt, UInt64 homeRegion, float homeLocX, float homeLocY, float homeLocZ, + float homeLookAtX, float homeLookAtY, float homeLookAtZ, int created, int lastlogin, + string inventoryURI, string assetURI, uint canDoMask, uint wantDoMask, + string aboutText, string firstText, + LLUUID profileImage, LLUUID firstImage) { string sql = "INSERT INTO users "; sql += "([UUID], [username], [lastname], [passwordHash], [passwordSalt], [homeRegion], "; - sql += "[homeLocationX], [homeLocationY], [homeLocationZ], [homeLookAtX], [homeLookAtY], [homeLookAtZ], [created], "; - sql += "[lastLogin], [userInventoryURI], [userAssetURI], [profileCanDoMask], [profileWantDoMask], [profileAboutText], "; + sql += + "[homeLocationX], [homeLocationY], [homeLocationZ], [homeLookAtX], [homeLookAtY], [homeLookAtZ], [created], "; + sql += + "[lastLogin], [userInventoryURI], [userAssetURI], [profileCanDoMask], [profileWantDoMask], [profileAboutText], "; sql += "[profileFirstText], [profileImage], [profileFirstImage]) VALUES "; sql += "(@UUID, @username, @lastname, @passwordHash, @passwordSalt, @homeRegion, "; - sql += "@homeLocationX, @homeLocationY, @homeLocationZ, @homeLookAtX, @homeLookAtY, @homeLookAtZ, @created, "; - sql += "@lastLogin, @userInventoryURI, @userAssetURI, @profileCanDoMask, @profileWantDoMask, @profileAboutText, "; + sql += + "@homeLocationX, @homeLocationY, @homeLocationZ, @homeLookAtX, @homeLookAtY, @homeLookAtZ, @created, "; + sql += + "@lastLogin, @userInventoryURI, @userAssetURI, @profileCanDoMask, @profileWantDoMask, @profileAboutText, "; sql += "@profileFirstText, @profileImage, @profileFirstImage);"; Dictionary parameters = new Dictionary(); @@ -624,13 +633,13 @@ namespace OpenSim.Framework.Data.MSSQL parameters["profileWantDoMask"] = "0"; parameters["profileAboutText"] = ""; parameters["profileFirstText"] = ""; - parameters["profileImage"] = libsecondlife.LLUUID.Zero.ToString(); - parameters["profileFirstImage"] = libsecondlife.LLUUID.Zero.ToString(); + parameters["profileImage"] = LLUUID.Zero.ToString(); + parameters["profileFirstImage"] = LLUUID.Zero.ToString(); bool returnval = false; try - { + { IDbCommand result = Query(sql, parameters); if (result.ExecuteNonQuery() == 1) @@ -655,8 +664,7 @@ namespace OpenSim.Framework.Data.MSSQL { try { - - SqlCommand cmd = new SqlCommand(getResourceString(name), (SqlConnection)dbcon); + SqlCommand cmd = new SqlCommand(getResourceString(name), (SqlConnection) dbcon); cmd.ExecuteNonQuery(); cmd.Dispose(); } @@ -668,7 +676,7 @@ namespace OpenSim.Framework.Data.MSSQL public SqlConnection getConnection() { - return (SqlConnection)dbcon; + return (SqlConnection) dbcon; } /// @@ -681,14 +689,15 @@ namespace OpenSim.Framework.Data.MSSQL { Dictionary param = new Dictionary(); param["dbname"] = dbcon.Database; - IDbCommand tablesCmd = this.Query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_CATALOG=@dbname", param); + IDbCommand tablesCmd = + Query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_CATALOG=@dbname", param); using (IDataReader tables = tablesCmd.ExecuteReader()) { while (tables.Read()) { try { - string tableName = (string)tables["TABLE_NAME"]; + string tableName = (string) tables["TABLE_NAME"]; if (tableList.ContainsKey(tableName)) tableList[tableName] = tableName; } @@ -704,7 +713,7 @@ namespace OpenSim.Framework.Data.MSSQL private string getResourceString(string name) { - Assembly assem = this.GetType().Assembly; + Assembly assem = GetType().Assembly; string[] names = assem.GetManifestResourceNames(); foreach (string s in names) @@ -726,16 +735,14 @@ namespace OpenSim.Framework.Data.MSSQL /// A string containing the DB provider public string getVersion() { - System.Reflection.Module module = this.GetType().Module; + Module module = GetType().Module; string dllName = module.Assembly.ManifestModule.Name; Version dllVersion = module.Assembly.GetName().Version; - return string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, dllVersion.Revision); + return + string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, + dllVersion.Revision); } - } - - - -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs b/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs index eac9826..01ef559 100644 --- a/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs +++ b/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs @@ -37,7 +37,7 @@ namespace OpenSim.Framework.Data.MSSQL /// /// A database interface class to a user profile storage system /// - class MSSQLUserData : IUserData + internal class MSSQLUserData : IUserData { /// /// Database manager for MySQL @@ -58,7 +58,9 @@ namespace OpenSim.Framework.Data.MSSQL string settingUserId = GridDataMySqlFile.ParseFileReadValue("user_id"); string settingPassword = GridDataMySqlFile.ParseFileReadValue("password"); - database = new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, settingPassword); + database = + new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, + settingPassword); } /// @@ -77,11 +79,12 @@ namespace OpenSim.Framework.Data.MSSQL param["first"] = user; param["second"] = last; - IDbCommand result = database.Query("SELECT * FROM users WHERE username = @first AND lastname = @second", param); + IDbCommand result = + database.Query("SELECT * FROM users WHERE username = @first AND lastname = @second", param); IDataReader reader = result.ExecuteReader(); UserProfileData row = database.readUserRow(reader); - + reader.Close(); result.Dispose(); @@ -96,9 +99,9 @@ namespace OpenSim.Framework.Data.MSSQL } } - public List GeneratePickerResults(LLUUID queryID, string query) + public List GeneratePickerResults(LLUUID queryID, string query) { - List returnlist = new List(); + List returnlist = new List(); string[] querysplit; querysplit = query.Split(' '); if (querysplit.Length == 2) @@ -112,18 +115,19 @@ namespace OpenSim.Framework.Data.MSSQL param["second"] = querysplit[1]; IDbCommand result = - database.Query("SELECT UUID,username,surname FROM users WHERE username = @first AND lastname = @second", param); + database.Query( + "SELECT UUID,username,surname FROM users WHERE username = @first AND lastname = @second", + param); IDataReader reader = result.ExecuteReader(); while (reader.Read()) { - OpenSim.Framework.AvatarPickerAvatar user = new OpenSim.Framework.AvatarPickerAvatar(); - user.AvatarID = new LLUUID((string)reader["UUID"]); - user.firstName = (string)reader["username"]; - user.lastName = (string)reader["surname"]; + Framework.AvatarPickerAvatar user = new Framework.AvatarPickerAvatar(); + user.AvatarID = new LLUUID((string) reader["UUID"]); + user.firstName = (string) reader["username"]; + user.lastName = (string) reader["surname"]; returnlist.Add(user); - } reader.Close(); result.Dispose(); @@ -135,13 +139,9 @@ namespace OpenSim.Framework.Data.MSSQL MainLog.Instance.Error(e.ToString()); return returnlist; } - - - } else if (querysplit.Length == 1) { - try { lock (database) @@ -151,18 +151,19 @@ namespace OpenSim.Framework.Data.MSSQL param["second"] = querysplit[1]; IDbCommand result = - database.Query("SELECT UUID,username,surname FROM users WHERE username = @first OR lastname = @second", param); + database.Query( + "SELECT UUID,username,surname FROM users WHERE username = @first OR lastname = @second", + param); IDataReader reader = result.ExecuteReader(); while (reader.Read()) { - OpenSim.Framework.AvatarPickerAvatar user = new OpenSim.Framework.AvatarPickerAvatar(); - user.AvatarID = new LLUUID((string)reader["UUID"]); - user.firstName = (string)reader["username"]; - user.lastName = (string)reader["surname"]; + Framework.AvatarPickerAvatar user = new Framework.AvatarPickerAvatar(); + user.AvatarID = new LLUUID((string) reader["UUID"]); + user.firstName = (string) reader["username"]; + user.lastName = (string) reader["surname"]; returnlist.Add(user); - } reader.Close(); result.Dispose(); @@ -268,21 +269,25 @@ namespace OpenSim.Framework.Data.MSSQL /// The user profile to create public void AddNewUserProfile(UserProfileData user) { - try - { - lock (database) - { - database.insertUserRow(user.UUID, user.username, user.surname, user.passwordHash, user.passwordSalt, user.homeRegion, user.homeLocation.X, user.homeLocation.Y, user.homeLocation.Z, - user.homeLookAt.X, user.homeLookAt.Y, user.homeLookAt.Z, user.created, user.lastLogin, user.userInventoryURI, user.userAssetURI, user.profileCanDoMask, user.profileWantDoMask, - user.profileAboutText, user.profileFirstText, user.profileImage, user.profileFirstImage); - } - } - catch (Exception e) - { - database.Reconnect(); - MainLog.Instance.Error(e.ToString()); - } - + try + { + lock (database) + { + database.insertUserRow(user.UUID, user.username, user.surname, user.passwordHash, user.passwordSalt, + user.homeRegion, user.homeLocation.X, user.homeLocation.Y, + user.homeLocation.Z, + user.homeLookAt.X, user.homeLookAt.Y, user.homeLookAt.Z, user.created, + user.lastLogin, user.userInventoryURI, user.userAssetURI, + user.profileCanDoMask, user.profileWantDoMask, + user.profileAboutText, user.profileFirstText, user.profileImage, + user.profileFirstImage); + } + } + catch (Exception e) + { + database.Reconnect(); + MainLog.Instance.Error(e.ToString()); + } } /// @@ -293,34 +298,33 @@ namespace OpenSim.Framework.Data.MSSQL { // Do nothing. } - - + + public bool UpdateUserProfile(UserProfileData user) { - SqlCommand command = new SqlCommand("UPDATE users set UUID = @uuid, " + - "username = @username, " + - "lastname = @lastname," + - "passwordHash = @passwordHash," + - "passwordSalt = @passwordSalt," + - "homeRegion = @homeRegion," + - "homeLocationX = @homeLocationX," + - "homeLocationY = @homeLocationY," + - "homeLocationZ = @homeLocationZ," + - "homeLookAtX = @homeLookAtX," + - "homeLookAtY = @homeLookAtY," + - "homeLookAtZ = @homeLookAtZ," + - "created = @created," + - "lastLogin = @lastLogin," + - "userInventoryURI = @userInventoryURI," + - "userAssetURI = @userAssetURI," + - "profileCanDoMask = @profileCanDoMask," + - "profileWantDoMask = @profileWantDoMask," + - "profileAboutText = @profileAboutText," + - "profileFirstText = @profileFirstText," + - "profileImage = @profileImage," + - "profileFirstImage = @profileFirstImage where " + - "UUID = @keyUUUID;", database.getConnection()); + "username = @username, " + + "lastname = @lastname," + + "passwordHash = @passwordHash," + + "passwordSalt = @passwordSalt," + + "homeRegion = @homeRegion," + + "homeLocationX = @homeLocationX," + + "homeLocationY = @homeLocationY," + + "homeLocationZ = @homeLocationZ," + + "homeLookAtX = @homeLookAtX," + + "homeLookAtY = @homeLookAtY," + + "homeLookAtZ = @homeLookAtZ," + + "created = @created," + + "lastLogin = @lastLogin," + + "userInventoryURI = @userInventoryURI," + + "userAssetURI = @userAssetURI," + + "profileCanDoMask = @profileCanDoMask," + + "profileWantDoMask = @profileWantDoMask," + + "profileAboutText = @profileAboutText," + + "profileFirstText = @profileFirstText," + + "profileImage = @profileImage," + + "profileFirstImage = @profileFirstImage where " + + "UUID = @keyUUUID;", database.getConnection()); SqlParameter param1 = new SqlParameter("@uuid", user.UUID.ToString()); SqlParameter param2 = new SqlParameter("@username", user.username); SqlParameter param3 = new SqlParameter("@lastname", user.surname); @@ -341,8 +345,8 @@ namespace OpenSim.Framework.Data.MSSQL SqlParameter param18 = new SqlParameter("@profileWantDoMask", Convert.ToInt32(user.profileWantDoMask)); SqlParameter param19 = new SqlParameter("@profileAboutText", user.profileAboutText); SqlParameter param20 = new SqlParameter("@profileFirstText", user.profileFirstText); - SqlParameter param21 = new SqlParameter("@profileImage", libsecondlife.LLUUID.Zero.ToString()); - SqlParameter param22 = new SqlParameter("@profileFirstImage", libsecondlife.LLUUID.Zero.ToString()); + SqlParameter param21 = new SqlParameter("@profileImage", LLUUID.Zero.ToString()); + SqlParameter param22 = new SqlParameter("@profileFirstImage", LLUUID.Zero.ToString()); SqlParameter param23 = new SqlParameter("@keyUUUID", user.UUID.ToString()); command.Parameters.Add(param1); command.Parameters.Add(param2); @@ -370,9 +374,12 @@ namespace OpenSim.Framework.Data.MSSQL try { int affected = command.ExecuteNonQuery(); - if (affected != 0) { + if (affected != 0) + { return true; - } else { + } + else + { return false; } } @@ -433,6 +440,5 @@ namespace OpenSim.Framework.Data.MSSQL public void runQuery(string query) { } - } -} +} \ No newline at end of file -- cgit v1.1