From 29a4614529bbda02b9c690d2d1812be1d1e7bbae Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Sun, 4 Oct 2009 13:57:51 -0700 Subject: * MySQL data tests now pass by fixing a bad fix for a bad cast on the asset Local member in MySQLAssetData * First pass at applying the using(){} pattern to IDisposable objects. Always use the using pattern on IDisposable objects whenever possible, do not manually call .Close() or .Dispose() unless there is no other way to write the code. This pass mostly covers OpenSim.Data.MySQL, and should have no functional change (tests still pass) --- OpenSim/Data/MySQL/MySQLAuthenticationData.cs | 50 ++++++++++++--------------- 1 file changed, 22 insertions(+), 28 deletions(-) (limited to 'OpenSim/Data/MySQL/MySQLAuthenticationData.cs') diff --git a/OpenSim/Data/MySQL/MySQLAuthenticationData.cs b/OpenSim/Data/MySQL/MySQLAuthenticationData.cs index e508b52..e96a123 100644 --- a/OpenSim/Data/MySQL/MySQLAuthenticationData.cs +++ b/OpenSim/Data/MySQL/MySQLAuthenticationData.cs @@ -55,44 +55,38 @@ namespace OpenSim.Data.MySQL AuthenticationData ret = new AuthenticationData(); ret.Data = new Dictionary(); - MySqlCommand cmd = new MySqlCommand( - "select * from `"+m_Realm+"` where UUID = ?principalID" - ); - - cmd.Parameters.AddWithValue("?principalID", principalID.ToString()); - - IDataReader result = ExecuteReader(cmd); - - if (result.Read()) + using (MySqlCommand cmd = new MySqlCommand("select * from `" + m_Realm + "` where UUID = ?principalID")) { - ret.PrincipalID = principalID; + cmd.Parameters.AddWithValue("?principalID", principalID.ToString()); - if (m_ColumnNames == null) + using (IDataReader result = ExecuteReader(cmd)) { - m_ColumnNames = new List(); + if (result.Read()) + { + ret.PrincipalID = principalID; - DataTable schemaTable = result.GetSchemaTable(); - foreach (DataRow row in schemaTable.Rows) - m_ColumnNames.Add(row["ColumnName"].ToString()); - } + if (m_ColumnNames == null) + { + m_ColumnNames = new List(); - foreach (string s in m_ColumnNames) - { - if (s == "UUID") - continue; + DataTable schemaTable = result.GetSchemaTable(); + foreach (DataRow row in schemaTable.Rows) + m_ColumnNames.Add(row["ColumnName"].ToString()); + } - ret.Data[s] = result[s].ToString(); - } + foreach (string s in m_ColumnNames) + { + if (s == "UUID") + continue; - result.Close(); - CloseReaderCommand(cmd); + ret.Data[s] = result[s].ToString(); + } - return ret; + return ret; + } + } } - result.Close(); - CloseReaderCommand(cmd); - return null; } -- cgit v1.1