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/MySQLManager.cs | 60 ++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 32 deletions(-) (limited to 'OpenSim/Data/MySQL/MySQLManager.cs') diff --git a/OpenSim/Data/MySQL/MySQLManager.cs b/OpenSim/Data/MySQL/MySQLManager.cs index a6cce57..a724a50 100644 --- a/OpenSim/Data/MySQL/MySQLManager.cs +++ b/OpenSim/Data/MySQL/MySQLManager.cs @@ -134,18 +134,16 @@ namespace OpenSim.Data.MySQL /// protected void GetWaitTimeout() { - MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect, dbcon); - - using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow)) + using (MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect, dbcon)) { - if (dbReader.Read()) + using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow)) { - m_waitTimeout - = Convert.ToInt32(dbReader["@@wait_timeout"]) * TimeSpan.TicksPerSecond + m_waitTimeoutLeeway; + if (dbReader.Read()) + { + m_waitTimeout + = Convert.ToInt32(dbReader["@@wait_timeout"]) * TimeSpan.TicksPerSecond + m_waitTimeoutLeeway; + } } - - dbReader.Close(); - cmd.Dispose(); } m_lastConnectionUse = DateTime.Now.Ticks; @@ -303,31 +301,31 @@ namespace OpenSim.Data.MySQL { CheckConnection(); - MySqlCommand tablesCmd = - new MySqlCommand( - "SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=?dbname", - dbcon); - tablesCmd.Parameters.AddWithValue("?dbname", dbcon.Database); - - using (MySqlDataReader tables = tablesCmd.ExecuteReader()) + using (MySqlCommand tablesCmd = new MySqlCommand( + "SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=?dbname", + dbcon)) { - while (tables.Read()) + tablesCmd.Parameters.AddWithValue("?dbname", dbcon.Database); + + using (MySqlDataReader tables = tablesCmd.ExecuteReader()) { - try + while (tables.Read()) { - string tableName = (string) tables["TABLE_NAME"]; - string comment = (string) tables["TABLE_COMMENT"]; - if (tableList.ContainsKey(tableName)) + try { - tableList[tableName] = comment; + string tableName = (string)tables["TABLE_NAME"]; + string comment = (string)tables["TABLE_COMMENT"]; + if (tableList.ContainsKey(tableName)) + { + tableList[tableName] = comment; + } + } + catch (Exception e) + { + m_log.Error(e.Message, e); } - } - catch (Exception e) - { - m_log.Error(e.ToString()); } } - tables.Close(); } } } @@ -346,19 +344,19 @@ namespace OpenSim.Data.MySQL { CheckConnection(); // Not sure if this one is necessary - MySqlCommand dbcommand = (MySqlCommand) dbcon.CreateCommand(); + MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand(); dbcommand.CommandText = sql; foreach (KeyValuePair param in parameters) { dbcommand.Parameters.AddWithValue(param.Key, param.Value); } - return (IDbCommand) dbcommand; + return (IDbCommand)dbcommand; } catch (Exception e) { // Return null if it fails. - m_log.Error("Failed during Query generation: " + e.ToString()); + m_log.Error("Failed during Query generation: " + e.Message, e); return null; } } @@ -694,8 +692,6 @@ namespace OpenSim.Data.MySQL ret.Add(attachpoint, item); } - r.Close(); - return ret; } -- cgit v1.1