aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/Migration.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/Migration.cs')
-rw-r--r--OpenSim/Data/Migration.cs79
1 files changed, 38 insertions, 41 deletions
diff --git a/OpenSim/Data/Migration.cs b/OpenSim/Data/Migration.cs
index 7a99d4a..e51dc22 100644
--- a/OpenSim/Data/Migration.cs
+++ b/OpenSim/Data/Migration.cs
@@ -131,26 +131,25 @@ namespace OpenSim.Data
131 m_log.InfoFormat("[MIGRATIONS] Upgrading {0} to latest revision.", _type); 131 m_log.InfoFormat("[MIGRATIONS] Upgrading {0} to latest revision.", _type);
132 m_log.Info("[MIGRATIONS] NOTE: this may take a while, don't interupt this process!"); 132 m_log.Info("[MIGRATIONS] NOTE: this may take a while, don't interupt this process!");
133 133
134 using (DbCommand cmd = _conn.CreateCommand()) 134 DbCommand cmd = _conn.CreateCommand();
135 foreach (KeyValuePair<int, string> kvp in migrations)
135 { 136 {
136 foreach (KeyValuePair<int, string> kvp in migrations) 137 int newversion = kvp.Key;
137 { 138 cmd.CommandText = kvp.Value;
138 int newversion = kvp.Key; 139 // we need to up the command timeout to infinite as we might be doing long migrations.
139 cmd.CommandText = kvp.Value; 140 cmd.CommandTimeout = 0;
140 // we need to up the command timeout to infinite as we might be doing long migrations. 141 cmd.ExecuteNonQuery();
141 cmd.CommandTimeout = 0;
142 cmd.ExecuteNonQuery();
143 142
144 if (version == 0) 143 if (version == 0)
145 { 144 {
146 InsertVersion(_type, newversion); 145 InsertVersion(_type, newversion);
147 }
148 else
149 {
150 UpdateVersion(_type, newversion);
151 }
152 version = newversion;
153 } 146 }
147 else
148 {
149 UpdateVersion(_type, newversion);
150 }
151 version = newversion;
152 cmd.Dispose();
154 } 153 }
155 } 154 }
156 155
@@ -190,45 +189,43 @@ namespace OpenSim.Data
190 protected virtual int FindVersion(DbConnection conn, string type) 189 protected virtual int FindVersion(DbConnection conn, string type)
191 { 190 {
192 int version = 0; 191 int version = 0;
193 192 DbCommand cmd = conn.CreateCommand();
194 using (DbCommand cmd = conn.CreateCommand()) 193 try
195 { 194 {
196 try 195 cmd.CommandText = "select version from migrations where name='" + type +"' order by version desc";
196 using (IDataReader reader = cmd.ExecuteReader())
197 { 197 {
198 cmd.CommandText = "select version from migrations where name='" + type + "' order by version desc"; 198 if (reader.Read())
199 using (IDataReader reader = cmd.ExecuteReader())
200 { 199 {
201 if (reader.Read()) 200 version = Convert.ToInt32(reader["version"]);
202 version = Convert.ToInt32(reader["version"]);
203 } 201 }
204 } 202 reader.Close();
205 catch
206 {
207 // Something went wrong, so we're version 0
208 } 203 }
209 } 204 }
210 205 catch
206 {
207 // Something went wrong, so we're version 0
208 }
209 cmd.Dispose();
211 return version; 210 return version;
212 } 211 }
213 212
214 private void InsertVersion(string type, int version) 213 private void InsertVersion(string type, int version)
215 { 214 {
216 using (DbCommand cmd = _conn.CreateCommand()) 215 DbCommand cmd = _conn.CreateCommand();
217 { 216 cmd.CommandText = "insert into migrations(name, version) values('" + type + "', " + version + ")";
218 cmd.CommandText = "insert into migrations(name, version) values('" + type + "', " + version + ")"; 217 m_log.InfoFormat("[MIGRATIONS]: Creating {0} at version {1}", type, version);
219 m_log.InfoFormat("[MIGRATIONS]: Creating {0} at version {1}", type, version); 218 cmd.ExecuteNonQuery();
220 cmd.ExecuteNonQuery(); 219 cmd.Dispose();
221 }
222 } 220 }
223 221
224 private void UpdateVersion(string type, int version) 222 private void UpdateVersion(string type, int version)
225 { 223 {
226 using (DbCommand cmd = _conn.CreateCommand()) 224 DbCommand cmd = _conn.CreateCommand();
227 { 225 cmd.CommandText = "update migrations set version=" + version + " where name='" + type + "'";
228 cmd.CommandText = "update migrations set version=" + version + " where name='" + type + "'"; 226 m_log.InfoFormat("[MIGRATIONS]: Updating {0} to version {1}", type, version);
229 m_log.InfoFormat("[MIGRATIONS]: Updating {0} to version {1}", type, version); 227 cmd.ExecuteNonQuery();
230 cmd.ExecuteNonQuery(); 228 cmd.Dispose();
231 }
232 } 229 }
233 230
234 // private SortedList<int, string> GetAllMigrations() 231 // private SortedList<int, string> GetAllMigrations()