Refactoring in Migration.cs: "using()" instead of explicit Dispose()
This ensures that 'cmd' gets disposed on errorsslimupdates
parent
b49e9eff56
commit
be1141f0f7
|
@ -110,10 +110,11 @@ namespace OpenSim.Data
|
|||
return;
|
||||
|
||||
// If not, create the migration tables
|
||||
DbCommand cmd = _conn.CreateCommand();
|
||||
using (DbCommand cmd = _conn.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = _migrations_create;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Dispose();
|
||||
}
|
||||
|
||||
InsertVersion("migrations", 1);
|
||||
}
|
||||
|
@ -131,7 +132,8 @@ namespace OpenSim.Data
|
|||
m_log.InfoFormat("[MIGRATIONS] Upgrading {0} to latest revision {1}.", _type, migrations.Keys[migrations.Count - 1]);
|
||||
m_log.Info("[MIGRATIONS] NOTE: this may take a while, don't interupt this process!");
|
||||
|
||||
DbCommand cmd = _conn.CreateCommand();
|
||||
using (DbCommand cmd = _conn.CreateCommand())
|
||||
{
|
||||
foreach (KeyValuePair<int, string> kvp in migrations)
|
||||
{
|
||||
int newversion = kvp.Key;
|
||||
|
@ -160,8 +162,7 @@ namespace OpenSim.Data
|
|||
}
|
||||
version = newversion;
|
||||
}
|
||||
|
||||
cmd.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
// private int MaxVersion()
|
||||
|
@ -200,10 +201,11 @@ namespace OpenSim.Data
|
|||
protected virtual int FindVersion(DbConnection conn, string type)
|
||||
{
|
||||
int version = 0;
|
||||
DbCommand cmd = conn.CreateCommand();
|
||||
using (DbCommand cmd = conn.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandText = "select version from migrations where name='" + type +"' order by version desc";
|
||||
cmd.CommandText = "select version from migrations where name='" + type + "' order by version desc";
|
||||
using (IDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
if (reader.Read())
|
||||
|
@ -217,26 +219,28 @@ namespace OpenSim.Data
|
|||
{
|
||||
// Something went wrong, so we're version 0
|
||||
}
|
||||
cmd.Dispose();
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
private void InsertVersion(string type, int version)
|
||||
{
|
||||
DbCommand cmd = _conn.CreateCommand();
|
||||
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();
|
||||
cmd.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateVersion(string type, int version)
|
||||
{
|
||||
DbCommand cmd = _conn.CreateCommand();
|
||||
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();
|
||||
cmd.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
// private SortedList<int, string> GetAllMigrations()
|
||||
|
|
Loading…
Reference in New Issue