aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2010-04-30 17:54:00 +0100
committerJustin Clark-Casey (justincc)2010-04-30 17:54:00 +0100
commit89e79c11335d55ae8131d6fa92218bf387e6c48e (patch)
treebb96e1093123b21e41f52e61000398f82f83f23b /OpenSim/Data
parentrename SQLiteNG to SQLite and SQLite to SQLiteLegacy (diff)
parentFix some symbol errors (diff)
downloadopensim-SC-89e79c11335d55ae8131d6fa92218bf387e6c48e.zip
opensim-SC-89e79c11335d55ae8131d6fa92218bf387e6c48e.tar.gz
opensim-SC-89e79c11335d55ae8131d6fa92218bf387e6c48e.tar.bz2
opensim-SC-89e79c11335d55ae8131d6fa92218bf387e6c48e.tar.xz
Merge branch 'master' of ssh://justincc@opensimulator.org/var/git/opensim
Diffstat (limited to 'OpenSim/Data')
-rw-r--r--OpenSim/Data/Migration.cs112
-rw-r--r--OpenSim/Data/MySQL/MySQLInventoryData.cs4
2 files changed, 60 insertions, 56 deletions
diff --git a/OpenSim/Data/Migration.cs b/OpenSim/Data/Migration.cs
index 0fb9e78..06defe4 100644
--- a/OpenSim/Data/Migration.cs
+++ b/OpenSim/Data/Migration.cs
@@ -53,8 +53,8 @@ namespace OpenSim.Data
53 /// When a database driver starts up, it specifies a resource that 53 /// When a database driver starts up, it specifies a resource that
54 /// needs to be brought up to the current revision. For instance: 54 /// needs to be brought up to the current revision. For instance:
55 /// 55 ///
56 /// Migration um = new Migration(Assembly, DbConnection, "Users"); 56 /// Migration um = new Migration(DbConnection, Assembly, "Users");
57 /// um.Upgrade(); 57 /// um.Update();
58 /// 58 ///
59 /// This works out which version Users is at, and applies all the 59 /// This works out which version Users is at, and applies all the
60 /// revisions past it to it. If there is no users table, all 60 /// revisions past it to it. If there is no users table, all
@@ -110,10 +110,11 @@ namespace OpenSim.Data
110 return; 110 return;
111 111
112 // If not, create the migration tables 112 // If not, create the migration tables
113 DbCommand cmd = _conn.CreateCommand(); 113 using (DbCommand cmd = _conn.CreateCommand())
114 cmd.CommandText = _migrations_create; 114 {
115 cmd.ExecuteNonQuery(); 115 cmd.CommandText = _migrations_create;
116 cmd.Dispose(); 116 cmd.ExecuteNonQuery();
117 }
117 118
118 InsertVersion("migrations", 1); 119 InsertVersion("migrations", 1);
119 } 120 }
@@ -131,37 +132,37 @@ namespace OpenSim.Data
131 m_log.InfoFormat("[MIGRATIONS] Upgrading {0} to latest revision {1}.", _type, migrations.Keys[migrations.Count - 1]); 132 m_log.InfoFormat("[MIGRATIONS] Upgrading {0} to latest revision {1}.", _type, migrations.Keys[migrations.Count - 1]);
132 m_log.Info("[MIGRATIONS] NOTE: this may take a while, don't interupt this process!"); 133 m_log.Info("[MIGRATIONS] NOTE: this may take a while, don't interupt this process!");
133 134
134 DbCommand cmd = _conn.CreateCommand(); 135 using (DbCommand cmd = _conn.CreateCommand())
135 foreach (KeyValuePair<int, string> kvp in migrations)
136 { 136 {
137 int newversion = kvp.Key; 137 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 try
142 {
143 cmd.ExecuteNonQuery();
144 }
145 catch (Exception e)
146 { 138 {
147 m_log.DebugFormat("[MIGRATIONS] Cmd was {0}", cmd.CommandText); 139 int newversion = kvp.Key;
148 m_log.DebugFormat("[MIGRATIONS]: An error has occurred in the migration {0}.\n This may mean you could see errors trying to run OpenSim. If you see database related errors, you will need to fix the issue manually. Continuing.", e.Message); 140 cmd.CommandText = kvp.Value;
149 cmd.CommandText = "ROLLBACK;"; 141 // we need to up the command timeout to infinite as we might be doing long migrations.
150 cmd.ExecuteNonQuery(); 142 cmd.CommandTimeout = 0;
151 } 143 try
144 {
145 cmd.ExecuteNonQuery();
146 }
147 catch (Exception e)
148 {
149 m_log.DebugFormat("[MIGRATIONS] Cmd was {0}", cmd.CommandText);
150 m_log.DebugFormat("[MIGRATIONS]: An error has occurred in the migration {0}.\n This may mean you could see errors trying to run OpenSim. If you see database related errors, you will need to fix the issue manually. Continuing.", e.Message);
151 cmd.CommandText = "ROLLBACK;";
152 cmd.ExecuteNonQuery();
153 }
152 154
153 if (version == 0) 155 if (version == 0)
154 { 156 {
155 InsertVersion(_type, newversion); 157 InsertVersion(_type, newversion);
156 } 158 }
157 else 159 else
158 { 160 {
159 UpdateVersion(_type, newversion); 161 UpdateVersion(_type, newversion);
162 }
163 version = newversion;
160 } 164 }
161 version = newversion;
162 } 165 }
163
164 cmd.Dispose();
165 } 166 }
166 167
167 // private int MaxVersion() 168 // private int MaxVersion()
@@ -200,43 +201,46 @@ namespace OpenSim.Data
200 protected virtual int FindVersion(DbConnection conn, string type) 201 protected virtual int FindVersion(DbConnection conn, string type)
201 { 202 {
202 int version = 0; 203 int version = 0;
203 DbCommand cmd = conn.CreateCommand(); 204 using (DbCommand cmd = conn.CreateCommand())
204 try
205 { 205 {
206 cmd.CommandText = "select version from migrations where name='" + type +"' order by version desc"; 206 try
207 using (IDataReader reader = cmd.ExecuteReader())
208 { 207 {
209 if (reader.Read()) 208 cmd.CommandText = "select version from migrations where name='" + type + "' order by version desc";
209 using (IDataReader reader = cmd.ExecuteReader())
210 { 210 {
211 version = Convert.ToInt32(reader["version"]); 211 if (reader.Read())
212 {
213 version = Convert.ToInt32(reader["version"]);
214 }
215 reader.Close();
212 } 216 }
213 reader.Close(); 217 }
218 catch
219 {
220 // Something went wrong, so we're version 0
214 } 221 }
215 } 222 }
216 catch
217 {
218 // Something went wrong, so we're version 0
219 }
220 cmd.Dispose();
221 return version; 223 return version;
222 } 224 }
223 225
224 private void InsertVersion(string type, int version) 226 private void InsertVersion(string type, int version)
225 { 227 {
226 DbCommand cmd = _conn.CreateCommand(); 228 using (DbCommand cmd = _conn.CreateCommand())
227 cmd.CommandText = "insert into migrations(name, version) values('" + type + "', " + version + ")"; 229 {
228 m_log.InfoFormat("[MIGRATIONS]: Creating {0} at version {1}", type, version); 230 cmd.CommandText = "insert into migrations(name, version) values('" + type + "', " + version + ")";
229 cmd.ExecuteNonQuery(); 231 m_log.InfoFormat("[MIGRATIONS]: Creating {0} at version {1}", type, version);
230 cmd.Dispose(); 232 cmd.ExecuteNonQuery();
233 }
231 } 234 }
232 235
233 private void UpdateVersion(string type, int version) 236 private void UpdateVersion(string type, int version)
234 { 237 {
235 DbCommand cmd = _conn.CreateCommand(); 238 using (DbCommand cmd = _conn.CreateCommand())
236 cmd.CommandText = "update migrations set version=" + version + " where name='" + type + "'"; 239 {
237 m_log.InfoFormat("[MIGRATIONS]: Updating {0} to version {1}", type, version); 240 cmd.CommandText = "update migrations set version=" + version + " where name='" + type + "'";
238 cmd.ExecuteNonQuery(); 241 m_log.InfoFormat("[MIGRATIONS]: Updating {0} to version {1}", type, version);
239 cmd.Dispose(); 242 cmd.ExecuteNonQuery();
243 }
240 } 244 }
241 245
242 // private SortedList<int, string> GetAllMigrations() 246 // private SortedList<int, string> GetAllMigrations()
diff --git a/OpenSim/Data/MySQL/MySQLInventoryData.cs b/OpenSim/Data/MySQL/MySQLInventoryData.cs
index 192deb2..e0e9b9c 100644
--- a/OpenSim/Data/MySQL/MySQLInventoryData.cs
+++ b/OpenSim/Data/MySQL/MySQLInventoryData.cs
@@ -145,7 +145,7 @@ namespace OpenSim.Data.MySQL
145 /// <summary> 145 /// <summary>
146 /// Returns a list of the root folders within a users inventory 146 /// Returns a list of the root folders within a users inventory
147 /// </summary> 147 /// </summary>
148 /// <param name="user">The user whos inventory is to be searched</param> 148 /// <param name="user">The user whose inventory is to be searched</param>
149 /// <returns>A list of folder objects</returns> 149 /// <returns>A list of folder objects</returns>
150 public List<InventoryFolderBase> getUserRootFolders(UUID user) 150 public List<InventoryFolderBase> getUserRootFolders(UUID user)
151 { 151 {
@@ -284,7 +284,7 @@ namespace OpenSim.Data.MySQL
284 { 284 {
285 InventoryItemBase item = new InventoryItemBase(); 285 InventoryItemBase item = new InventoryItemBase();
286 286
287 // TODO: this is to handle a case where NULLs creep in there, which we are not sure is indemic to the system, or legacy. It would be nice to live fix these. 287 // TODO: this is to handle a case where NULLs creep in there, which we are not sure is endemic to the system, or legacy. It would be nice to live fix these.
288 if (reader["creatorID"] == null) 288 if (reader["creatorID"] == null)
289 { 289 {
290 item.CreatorId = UUID.Zero.ToString(); 290 item.CreatorId = UUID.Zero.ToString();