Remove the using() constructs from the new style database modules; they caused

the underlying connection of a reader or command to be closed before the
reader or command itself. Added the proper logic to Close and dispose items
in CloseDBConnection. Readers and Connections need Close(), Commands need
Dispose(), in the order Reader, Command, Connection.
Also reinstated 80-column-friendly formatting
prioritization
Melanie 2009-10-06 14:30:25 +01:00
parent 0c46df973a
commit 8a7a947faa
4 changed files with 75 additions and 73 deletions

View File

@ -55,12 +55,12 @@ namespace OpenSim.Data.MySQL
AuthenticationData ret = new AuthenticationData();
ret.Data = new Dictionary<string, object>();
using (MySqlCommand cmd = new MySqlCommand("select * from `" + m_Realm + "` where UUID = ?principalID"))
{
MySqlCommand cmd = new MySqlCommand("select * from `" + m_Realm + "` where UUID = ?principalID");
cmd.Parameters.AddWithValue("?principalID", principalID.ToString());
using (IDataReader result = ExecuteReader(cmd))
{
IDataReader result = ExecuteReader(cmd);
if (result.Read())
{
ret.PrincipalID = principalID;
@ -82,17 +82,15 @@ namespace OpenSim.Data.MySQL
ret.Data[s] = result[s].ToString();
}
CloseDBConnection(cmd);
CloseDBConnection(result, cmd);
return ret;
}
else
{
CloseDBConnection(cmd);
CloseDBConnection(result, cmd);
return null;
}
}
}
}
public bool Store(AuthenticationData data)
{

View File

@ -40,7 +40,9 @@ namespace OpenSim.Data.MySQL
/// </summary>
public class MySqlFramework
{
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private static readonly log4net.ILog m_log =
log4net.LogManager.GetLogger(
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
protected MySqlConnection m_Connection;
@ -81,7 +83,8 @@ namespace OpenSim.Data.MySQL
errorSeen = true;
m_Connection.Close();
MySqlConnection newConnection = (MySqlConnection)((ICloneable)m_Connection).Clone();
MySqlConnection newConnection =
(MySqlConnection)((ICloneable)m_Connection).Clone();
m_Connection.Dispose();
m_Connection = newConnection;
m_Connection.Open();
@ -102,15 +105,18 @@ namespace OpenSim.Data.MySQL
protected IDataReader ExecuteReader(MySqlCommand cmd)
{
MySqlConnection newConnection = (MySqlConnection)((ICloneable)m_Connection).Clone();
MySqlConnection newConnection =
(MySqlConnection)((ICloneable)m_Connection).Clone();
newConnection.Open();
cmd.Connection = newConnection;
return cmd.ExecuteReader();
}
protected void CloseDBConnection(MySqlCommand cmd)
protected void CloseDBConnection(IDataReader reader, MySqlCommand cmd)
{
reader.Close();
cmd.Connection.Close();
cmd.Connection.Dispose();
}
}

View File

@ -173,7 +173,7 @@ namespace OpenSim.Data.MySQL
retList.Add(ret);
}
CloseDBConnection(cmd);
CloseDBConnection(result, cmd);
}
return retList;

View File

@ -64,13 +64,13 @@ namespace OpenSim.Data.MySQL
if (scopeID != UUID.Zero)
command += " and ScopeID = ?scopeID";
using (MySqlCommand cmd = new MySqlCommand(command))
{
MySqlCommand cmd = new MySqlCommand(command);
cmd.Parameters.AddWithValue("?principalID", principalID.ToString());
cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
using (IDataReader result = ExecuteReader(cmd))
{
IDataReader result = ExecuteReader(cmd);
if (result.Read())
{
ret.PrincipalID = principalID;
@ -97,17 +97,15 @@ namespace OpenSim.Data.MySQL
ret.Data[s] = result[s].ToString();
}
CloseDBConnection(cmd);
CloseDBConnection(result, cmd);
return ret;
}
else
{
CloseDBConnection(cmd);
CloseDBConnection(result, cmd);
return null;
}
}
}
}
public bool Store(UserAccountData data)
{