aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL/MySQLManager.cs
diff options
context:
space:
mode:
authorJohn Hurliman2009-10-04 13:57:51 -0700
committerJohn Hurliman2009-10-04 13:57:51 -0700
commit29a4614529bbda02b9c690d2d1812be1d1e7bbae (patch)
tree89725829b37d502158a114c862a56a075b005b1b /OpenSim/Data/MySQL/MySQLManager.cs
parentGuarding a line that is sometimes throwing a null pointer exception. (diff)
downloadopensim-SC-29a4614529bbda02b9c690d2d1812be1d1e7bbae.zip
opensim-SC-29a4614529bbda02b9c690d2d1812be1d1e7bbae.tar.gz
opensim-SC-29a4614529bbda02b9c690d2d1812be1d1e7bbae.tar.bz2
opensim-SC-29a4614529bbda02b9c690d2d1812be1d1e7bbae.tar.xz
* 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)
Diffstat (limited to '')
-rw-r--r--OpenSim/Data/MySQL/MySQLManager.cs60
1 files changed, 28 insertions, 32 deletions
diff --git a/OpenSim/Data/MySQL/MySQLManager.cs b/OpenSim/Data/MySQL/MySQLManager.cs
index a6cce57..a724a50 100644
--- a/OpenSim/Data/MySQL/MySQLManager.cs
+++ b/OpenSim/Data/MySQL/MySQLManager.cs
@@ -134,18 +134,16 @@ namespace OpenSim.Data.MySQL
134 /// </summary> 134 /// </summary>
135 protected void GetWaitTimeout() 135 protected void GetWaitTimeout()
136 { 136 {
137 MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect, dbcon); 137 using (MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect, dbcon))
138
139 using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
140 { 138 {
141 if (dbReader.Read()) 139 using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
142 { 140 {
143 m_waitTimeout 141 if (dbReader.Read())
144 = Convert.ToInt32(dbReader["@@wait_timeout"]) * TimeSpan.TicksPerSecond + m_waitTimeoutLeeway; 142 {
143 m_waitTimeout
144 = Convert.ToInt32(dbReader["@@wait_timeout"]) * TimeSpan.TicksPerSecond + m_waitTimeoutLeeway;
145 }
145 } 146 }
146
147 dbReader.Close();
148 cmd.Dispose();
149 } 147 }
150 148
151 m_lastConnectionUse = DateTime.Now.Ticks; 149 m_lastConnectionUse = DateTime.Now.Ticks;
@@ -303,31 +301,31 @@ namespace OpenSim.Data.MySQL
303 { 301 {
304 CheckConnection(); 302 CheckConnection();
305 303
306 MySqlCommand tablesCmd = 304 using (MySqlCommand tablesCmd = new MySqlCommand(
307 new MySqlCommand( 305 "SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=?dbname",
308 "SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=?dbname", 306 dbcon))
309 dbcon);
310 tablesCmd.Parameters.AddWithValue("?dbname", dbcon.Database);
311
312 using (MySqlDataReader tables = tablesCmd.ExecuteReader())
313 { 307 {
314 while (tables.Read()) 308 tablesCmd.Parameters.AddWithValue("?dbname", dbcon.Database);
309
310 using (MySqlDataReader tables = tablesCmd.ExecuteReader())
315 { 311 {
316 try 312 while (tables.Read())
317 { 313 {
318 string tableName = (string) tables["TABLE_NAME"]; 314 try
319 string comment = (string) tables["TABLE_COMMENT"];
320 if (tableList.ContainsKey(tableName))
321 { 315 {
322 tableList[tableName] = comment; 316 string tableName = (string)tables["TABLE_NAME"];
317 string comment = (string)tables["TABLE_COMMENT"];
318 if (tableList.ContainsKey(tableName))
319 {
320 tableList[tableName] = comment;
321 }
322 }
323 catch (Exception e)
324 {
325 m_log.Error(e.Message, e);
323 } 326 }
324 }
325 catch (Exception e)
326 {
327 m_log.Error(e.ToString());
328 } 327 }
329 } 328 }
330 tables.Close();
331 } 329 }
332 } 330 }
333 } 331 }
@@ -346,19 +344,19 @@ namespace OpenSim.Data.MySQL
346 { 344 {
347 CheckConnection(); // Not sure if this one is necessary 345 CheckConnection(); // Not sure if this one is necessary
348 346
349 MySqlCommand dbcommand = (MySqlCommand) dbcon.CreateCommand(); 347 MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand();
350 dbcommand.CommandText = sql; 348 dbcommand.CommandText = sql;
351 foreach (KeyValuePair<string, object> param in parameters) 349 foreach (KeyValuePair<string, object> param in parameters)
352 { 350 {
353 dbcommand.Parameters.AddWithValue(param.Key, param.Value); 351 dbcommand.Parameters.AddWithValue(param.Key, param.Value);
354 } 352 }
355 353
356 return (IDbCommand) dbcommand; 354 return (IDbCommand)dbcommand;
357 } 355 }
358 catch (Exception e) 356 catch (Exception e)
359 { 357 {
360 // Return null if it fails. 358 // Return null if it fails.
361 m_log.Error("Failed during Query generation: " + e.ToString()); 359 m_log.Error("Failed during Query generation: " + e.Message, e);
362 return null; 360 return null;
363 } 361 }
364 } 362 }
@@ -694,8 +692,6 @@ namespace OpenSim.Data.MySQL
694 ret.Add(attachpoint, item); 692 ret.Add(attachpoint, item);
695 } 693 }
696 694
697 r.Close();
698
699 return ret; 695 return ret;
700 } 696 }
701 697