* 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)
This commit is contained in:
John Hurliman
2009-10-04 13:57:51 -07:00
parent d93e0a0503
commit 29a4614529
18 changed files with 1193 additions and 1312 deletions

View File

@@ -131,25 +131,26 @@ namespace OpenSim.Data
m_log.InfoFormat("[MIGRATIONS] Upgrading {0} to latest revision.", _type);
m_log.Info("[MIGRATIONS] NOTE: this may take a while, don't interupt this process!");
DbCommand cmd = _conn.CreateCommand();
foreach (KeyValuePair<int, string> kvp in migrations)
using (DbCommand cmd = _conn.CreateCommand())
{
int newversion = kvp.Key;
cmd.CommandText = kvp.Value;
// we need to up the command timeout to infinite as we might be doing long migrations.
cmd.CommandTimeout = 0;
cmd.ExecuteNonQuery();
foreach (KeyValuePair<int, string> kvp in migrations)
{
int newversion = kvp.Key;
cmd.CommandText = kvp.Value;
// we need to up the command timeout to infinite as we might be doing long migrations.
cmd.CommandTimeout = 0;
cmd.ExecuteNonQuery();
if (version == 0)
{
InsertVersion(_type, newversion);
if (version == 0)
{
InsertVersion(_type, newversion);
}
else
{
UpdateVersion(_type, newversion);
}
version = newversion;
}
else
{
UpdateVersion(_type, newversion);
}
version = newversion;
cmd.Dispose();
}
}
@@ -189,43 +190,45 @@ namespace OpenSim.Data
protected virtual int FindVersion(DbConnection conn, string type)
{
int version = 0;
DbCommand cmd = conn.CreateCommand();
try
using (DbCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select version from migrations where name='" + type +"' order by version desc";
using (IDataReader reader = cmd.ExecuteReader())
try
{
if (reader.Read())
cmd.CommandText = "select version from migrations where name='" + type + "' order by version desc";
using (IDataReader reader = cmd.ExecuteReader())
{
version = Convert.ToInt32(reader["version"]);
if (reader.Read())
version = Convert.ToInt32(reader["version"]);
}
reader.Close();
}
catch
{
// Something went wrong, so we're version 0
}
}
catch
{
// Something went wrong, so we're version 0
}
cmd.Dispose();
return version;
}
private void InsertVersion(string type, int version)
{
DbCommand cmd = _conn.CreateCommand();
cmd.CommandText = "insert into migrations(name, version) values('" + type + "', " + version + ")";
m_log.InfoFormat("[MIGRATIONS]: Creating {0} at version {1}", type, version);
cmd.ExecuteNonQuery();
cmd.Dispose();
using (DbCommand cmd = _conn.CreateCommand())
{
cmd.CommandText = "insert into migrations(name, version) values('" + type + "', " + version + ")";
m_log.InfoFormat("[MIGRATIONS]: Creating {0} at version {1}", type, version);
cmd.ExecuteNonQuery();
}
}
private void UpdateVersion(string type, int version)
{
DbCommand cmd = _conn.CreateCommand();
cmd.CommandText = "update migrations set version=" + version + " where name='" + type + "'";
m_log.InfoFormat("[MIGRATIONS]: Updating {0} to version {1}", type, version);
cmd.ExecuteNonQuery();
cmd.Dispose();
using (DbCommand cmd = _conn.CreateCommand())
{
cmd.CommandText = "update migrations set version=" + version + " where name='" + type + "'";
m_log.InfoFormat("[MIGRATIONS]: Updating {0} to version {1}", type, version);
cmd.ExecuteNonQuery();
}
}
// private SortedList<int, string> GetAllMigrations()