aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/Migration.cs
diff options
context:
space:
mode:
authorDiva Canto2009-10-04 14:06:28 -0700
committerDiva Canto2009-10-04 14:06:28 -0700
commit08d3650138c106529dedd4659472868097e85ecc (patch)
tree7b63f4a8bdb03e1654abb8bf0f449d0fe39ad78a /OpenSim/Data/Migration.cs
parentReduced locking. (diff)
parentMerge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff)
downloadopensim-SC_OLD-08d3650138c106529dedd4659472868097e85ecc.zip
opensim-SC_OLD-08d3650138c106529dedd4659472868097e85ecc.tar.gz
opensim-SC_OLD-08d3650138c106529dedd4659472868097e85ecc.tar.bz2
opensim-SC_OLD-08d3650138c106529dedd4659472868097e85ecc.tar.xz
Merge branch 'master' of ssh://diva@opensimulator.org/var/git/opensim
Diffstat (limited to 'OpenSim/Data/Migration.cs')
-rw-r--r--OpenSim/Data/Migration.cs79
1 files changed, 41 insertions, 38 deletions
diff --git a/OpenSim/Data/Migration.cs b/OpenSim/Data/Migration.cs
index e51dc22..7a99d4a 100644
--- a/OpenSim/Data/Migration.cs
+++ b/OpenSim/Data/Migration.cs
@@ -131,25 +131,26 @@ 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 DbCommand cmd = _conn.CreateCommand(); 134 using (DbCommand cmd = _conn.CreateCommand())
135 foreach (KeyValuePair<int, string> kvp in migrations)
136 { 135 {
137 int newversion = kvp.Key; 136 foreach (KeyValuePair<int, string> kvp in migrations)
138 cmd.CommandText = kvp.Value;
139 // we need to up the command timeout to infinite as we might be doing long migrations.
140 cmd.CommandTimeout = 0;
141 cmd.ExecuteNonQuery();
142
143 if (version == 0)
144 {
145 InsertVersion(_type, newversion);
146 }
147 else
148 { 137 {
149 UpdateVersion(_type, newversion); 138 int newversion = kvp.Key;
139 cmd.CommandText = kvp.Value;
140 // we need to up the command timeout to infinite as we might be doing long migrations.
141 cmd.CommandTimeout = 0;
142 cmd.ExecuteNonQuery();
143
144 if (version == 0)
145 {
146 InsertVersion(_type, newversion);
147 }
148 else
149 {
150 UpdateVersion(_type, newversion);
151 }
152 version = newversion;
150 } 153 }
151 version = newversion;
152 cmd.Dispose();
153 } 154 }
154 } 155 }
155 156
@@ -189,43 +190,45 @@ namespace OpenSim.Data
189 protected virtual int FindVersion(DbConnection conn, string type) 190 protected virtual int FindVersion(DbConnection conn, string type)
190 { 191 {
191 int version = 0; 192 int version = 0;
192 DbCommand cmd = conn.CreateCommand(); 193
193 try 194 using (DbCommand cmd = conn.CreateCommand())
194 { 195 {
195 cmd.CommandText = "select version from migrations where name='" + type +"' order by version desc"; 196 try
196 using (IDataReader reader = cmd.ExecuteReader())
197 { 197 {
198 if (reader.Read()) 198 cmd.CommandText = "select version from migrations where name='" + type + "' order by version desc";
199 using (IDataReader reader = cmd.ExecuteReader())
199 { 200 {
200 version = Convert.ToInt32(reader["version"]); 201 if (reader.Read())
202 version = Convert.ToInt32(reader["version"]);
201 } 203 }
202 reader.Close(); 204 }
205 catch
206 {
207 // Something went wrong, so we're version 0
203 } 208 }
204 } 209 }
205 catch 210
206 {
207 // Something went wrong, so we're version 0
208 }
209 cmd.Dispose();
210 return version; 211 return version;
211 } 212 }
212 213
213 private void InsertVersion(string type, int version) 214 private void InsertVersion(string type, int version)
214 { 215 {
215 DbCommand cmd = _conn.CreateCommand(); 216 using (DbCommand cmd = _conn.CreateCommand())
216 cmd.CommandText = "insert into migrations(name, version) values('" + type + "', " + version + ")"; 217 {
217 m_log.InfoFormat("[MIGRATIONS]: Creating {0} at version {1}", type, version); 218 cmd.CommandText = "insert into migrations(name, version) values('" + type + "', " + version + ")";
218 cmd.ExecuteNonQuery(); 219 m_log.InfoFormat("[MIGRATIONS]: Creating {0} at version {1}", type, version);
219 cmd.Dispose(); 220 cmd.ExecuteNonQuery();
221 }
220 } 222 }
221 223
222 private void UpdateVersion(string type, int version) 224 private void UpdateVersion(string type, int version)
223 { 225 {
224 DbCommand cmd = _conn.CreateCommand(); 226 using (DbCommand cmd = _conn.CreateCommand())
225 cmd.CommandText = "update migrations set version=" + version + " where name='" + type + "'"; 227 {
226 m_log.InfoFormat("[MIGRATIONS]: Updating {0} to version {1}", type, version); 228 cmd.CommandText = "update migrations set version=" + version + " where name='" + type + "'";
227 cmd.ExecuteNonQuery(); 229 m_log.InfoFormat("[MIGRATIONS]: Updating {0} to version {1}", type, version);
228 cmd.Dispose(); 230 cmd.ExecuteNonQuery();
231 }
229 } 232 }
230 233
231 // private SortedList<int, string> GetAllMigrations() 234 // private SortedList<int, string> GetAllMigrations()