* 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)
prioritization
John Hurliman 2009-10-04 13:57:51 -07:00
parent d93e0a0503
commit 29a4614529
18 changed files with 1193 additions and 1312 deletions

View File

@ -95,16 +95,15 @@ namespace OpenSim.Client.VWoHTTP.ClientStack
ManagedImage tmp;
Image imgData;
byte[] jpegdata;
OpenJPEG.DecodeToImage(asset.Data, out tmp, out imgData);
MemoryStream ms = new MemoryStream();
using (MemoryStream ms = new MemoryStream())
{
imgData.Save(ms, ImageFormat.Jpeg);
byte[] jpegdata = ms.GetBuffer();
ms.Close();
jpegdata = ms.GetBuffer();
}
resp.ContentType = "image/jpeg";
resp.ContentLength = jpegdata.Length;

View File

@ -197,20 +197,11 @@ namespace OpenSim.Data.MSSQL
public void Dispose()
{
SqlConnection conn = realCommand.Connection;
try
{
realCommand.Dispose();
}
try { realCommand.Dispose(); }
finally
{
try
{
conn.Close();
}
finally
{
conn.Dispose();
}
try { conn.Dispose(); }
finally { }
}
}

View File

@ -348,8 +348,6 @@ namespace OpenSim.Data.MSSQL
//Delete the actual row
DeleteOneFolder(folderID, connection);
DeleteItemsInFolder(folderID, connection);
connection.Close();
}
}

View File

@ -340,8 +340,6 @@ namespace OpenSim.Data.MSSQL
MSSQLMigration migration = new MSSQLMigration(connection, assem, migrationStore);
migration.Update();
connection.Close();
}
}
@ -385,9 +383,7 @@ namespace OpenSim.Data.MSSQL
m_log.Error(e.ToString());
}
}
tables.Close();
}
}
/// <summary>

View File

@ -56,7 +56,6 @@ namespace OpenSim.Data.MSSQL
{
version = Convert.ToInt32(reader["version"]);
}
reader.Close();
}
}
catch

View File

@ -131,7 +131,8 @@ namespace OpenSim.Data
m_log.InfoFormat("[MIGRATIONS] Upgrading {0} to latest revision.", _type);
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;
@ -149,7 +150,7 @@ namespace OpenSim.Data
UpdateVersion(_type, newversion);
}
version = newversion;
cmd.Dispose();
}
}
}
@ -189,43 +190,45 @@ 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";
using (IDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())
{
version = Convert.ToInt32(reader["version"]);
}
reader.Close();
}
}
catch
{
// 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()

View File

@ -142,10 +142,10 @@ namespace OpenSim.Data.MySQL
{
_dbConnection.CheckConnection();
MySqlCommand cmd =
new MySqlCommand(
using (MySqlCommand cmd = new MySqlCommand(
"SELECT name, description, assetType, local, temporary, data FROM assets WHERE id=?id",
_dbConnection.Connection);
_dbConnection.Connection))
{
cmd.Parameters.AddWithValue("?id", assetID.ToString());
try
@ -158,21 +158,19 @@ namespace OpenSim.Data.MySQL
asset.Data = (byte[])dbReader["data"];
asset.Description = (string)dbReader["description"];
asset.FullID = assetID;
try
{
asset.Local = (bool)dbReader["local"];
}
catch (InvalidCastException)
{
string local = dbReader["local"].ToString();
if (local.Equals("1") || local.Equals("true", StringComparison.InvariantCultureIgnoreCase))
asset.Local = true;
else
asset.Local = false;
}
asset.Name = (string)dbReader["name"];
asset.Type = (sbyte)dbReader["assetType"];
asset.Temporary = Convert.ToBoolean(dbReader["temporary"]);
}
dbReader.Close();
cmd.Dispose();
}
if (asset != null)
UpdateAccessTime(asset);
}
@ -184,6 +182,7 @@ namespace OpenSim.Data.MySQL
_dbConnection.Reconnect();
}
}
}
return asset;
}
@ -297,11 +296,10 @@ namespace OpenSim.Data.MySQL
{
_dbConnection.CheckConnection();
MySqlCommand cmd =
new MySqlCommand(
using (MySqlCommand cmd = new MySqlCommand(
"SELECT id FROM assets WHERE id=?id",
_dbConnection.Connection);
_dbConnection.Connection))
{
cmd.Parameters.AddWithValue("?id", uuid.ToString());
try
@ -309,13 +307,8 @@ namespace OpenSim.Data.MySQL
using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
{
if (dbReader.Read())
{
assetExists = true;
}
dbReader.Close();
cmd.Dispose();
}
}
catch (Exception e)
{
@ -325,6 +318,7 @@ namespace OpenSim.Data.MySQL
_dbConnection.Reconnect();
}
}
}
return assetExists;
}

View File

@ -55,14 +55,12 @@ namespace OpenSim.Data.MySQL
AuthenticationData ret = new AuthenticationData();
ret.Data = new Dictionary<string, object>();
MySqlCommand cmd = new MySqlCommand(
"select * from `"+m_Realm+"` where UUID = ?principalID"
);
using (MySqlCommand cmd = new MySqlCommand("select * from `" + m_Realm + "` where UUID = ?principalID"))
{
cmd.Parameters.AddWithValue("?principalID", principalID.ToString());
IDataReader result = ExecuteReader(cmd);
using (IDataReader result = ExecuteReader(cmd))
{
if (result.Read())
{
ret.PrincipalID = principalID;
@ -84,14 +82,10 @@ namespace OpenSim.Data.MySQL
ret.Data[s] = result[s].ToString();
}
result.Close();
CloseReaderCommand(cmd);
return ret;
}
result.Close();
CloseReaderCommand(cmd);
}
}
return null;
}

View File

@ -95,11 +95,9 @@ namespace OpenSim.Data.MySQL
protected void GetWaitTimeout()
{
MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect,
m_connection);
using (MySqlDataReader dbReader =
cmd.ExecuteReader(CommandBehavior.SingleRow))
using (MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect, m_connection))
{
using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
{
if (dbReader.Read())
{
@ -107,9 +105,7 @@ namespace OpenSim.Data.MySQL
= Convert.ToInt32(dbReader["@@wait_timeout"]) *
TimeSpan.TicksPerSecond + m_waitTimeoutLeeway;
}
dbReader.Close();
cmd.Dispose();
}
}
m_lastConnectionUse = DateTime.Now.Ticks;
@ -147,15 +143,19 @@ namespace OpenSim.Data.MySQL
CheckConnection();
MySqlCommand cmd = m_connection.CreateCommand();
bool migration = true;
using (MySqlCommand cmd = m_connection.CreateCommand())
{
cmd.CommandText = sql;
cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
IDataReader r = cmd.ExecuteReader();
using (IDataReader r = cmd.ExecuteReader())
{
if (r.Read())
{
migration = false;
foreach (string name in FieldList)
{
if (m_FieldMap[name].GetValue(es) is bool)
@ -178,20 +178,21 @@ namespace OpenSim.Data.MySQL
m_FieldMap[name].SetValue(es, r[name]);
}
}
r.Close();
}
else
}
}
if (migration)
{
// Migration case
//
r.Close();
List<string> names = new List<string>(FieldList);
names.Remove("EstateID");
sql = "insert into estate_settings (" + String.Join(",", names.ToArray()) + ") values ( ?" + String.Join(", ?", names.ToArray()) + ")";
using (MySqlCommand cmd = m_connection.CreateCommand())
{
cmd.CommandText = sql;
cmd.Parameters.Clear();
@ -215,43 +216,31 @@ namespace OpenSim.Data.MySQL
cmd.CommandText = "select LAST_INSERT_ID() as id";
cmd.Parameters.Clear();
r = cmd.ExecuteReader();
using (IDataReader r = cmd.ExecuteReader())
{
r.Read();
es.EstateID = Convert.ToUInt32(r["id"]);
r.Close();
}
cmd.CommandText = "insert into estate_map values (?RegionID, ?EstateID)";
cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString());
// This will throw on dupe key
try
{
cmd.ExecuteNonQuery();
}
catch (Exception)
{
}
try { cmd.ExecuteNonQuery(); }
catch (Exception) { }
// Munge and transfer the ban list
//
cmd.Parameters.Clear();
cmd.CommandText = "insert into estateban select " + es.EstateID.ToString() + ", bannedUUID, bannedIp, bannedIpHostMask, '' from regionban where regionban.regionUUID = ?UUID";
cmd.Parameters.AddWithValue("?UUID", regionID.ToString());
try
{
cmd.ExecuteNonQuery();
}
catch (Exception)
{
}
try { cmd.ExecuteNonQuery(); }
catch (Exception) { }
es.Save();
}
}
LoadBanList(es);
@ -267,8 +256,8 @@ namespace OpenSim.Data.MySQL
CheckConnection();
MySqlCommand cmd = m_connection.CreateCommand();
using (MySqlCommand cmd = m_connection.CreateCommand())
{
cmd.CommandText = sql;
foreach (string name in FieldList)
@ -287,6 +276,7 @@ namespace OpenSim.Data.MySQL
}
cmd.ExecuteNonQuery();
}
SaveBanList(es);
SaveUUIDList(es.EstateID, "estate_managers", es.EstateManagers);
@ -300,13 +290,13 @@ namespace OpenSim.Data.MySQL
CheckConnection();
MySqlCommand cmd = m_connection.CreateCommand();
using (MySqlCommand cmd = m_connection.CreateCommand())
{
cmd.CommandText = "select bannedUUID from estateban where EstateID = ?EstateID";
cmd.Parameters.AddWithValue("?EstateID", es.EstateID);
IDataReader r = cmd.ExecuteReader();
using (IDataReader r = cmd.ExecuteReader())
{
while (r.Read())
{
EstateBan eb = new EstateBan();
@ -319,15 +309,16 @@ namespace OpenSim.Data.MySQL
eb.BannedHostIPMask = "0.0.0.0";
es.AddBan(eb);
}
r.Close();
}
}
}
private void SaveBanList(EstateSettings es)
{
CheckConnection();
MySqlCommand cmd = m_connection.CreateCommand();
using (MySqlCommand cmd = m_connection.CreateCommand())
{
cmd.CommandText = "delete from estateban where EstateID = ?EstateID";
cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString());
@ -346,13 +337,14 @@ namespace OpenSim.Data.MySQL
cmd.Parameters.Clear();
}
}
}
void SaveUUIDList(uint EstateID, string table, UUID[] data)
{
CheckConnection();
MySqlCommand cmd = m_connection.CreateCommand();
using (MySqlCommand cmd = m_connection.CreateCommand())
{
cmd.CommandText = "delete from " + table + " where EstateID = ?EstateID";
cmd.Parameters.AddWithValue("?EstateID", EstateID.ToString());
@ -371,6 +363,7 @@ namespace OpenSim.Data.MySQL
cmd.Parameters.Clear();
}
}
}
UUID[] LoadUUIDList(uint EstateID, string table)
{
@ -378,13 +371,13 @@ namespace OpenSim.Data.MySQL
CheckConnection();
MySqlCommand cmd = m_connection.CreateCommand();
using (MySqlCommand cmd = m_connection.CreateCommand())
{
cmd.CommandText = "select uuid from " + table + " where EstateID = ?EstateID";
cmd.Parameters.AddWithValue("?EstateID", EstateID);
IDataReader r = cmd.ExecuteReader();
using (IDataReader r = cmd.ExecuteReader())
{
while (r.Read())
{
// EstateBan eb = new EstateBan();
@ -394,7 +387,8 @@ namespace OpenSim.Data.MySQL
uuids.Add(uuid);
}
r.Close();
}
}
return uuids.ToArray();
}

View File

@ -40,6 +40,8 @@ namespace OpenSim.Data.MySQL
/// </summary>
public class MySqlFramework
{
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
protected MySqlConnection m_Connection;
protected MySqlFramework(string connectionString)
@ -70,12 +72,11 @@ namespace OpenSim.Data.MySQL
}
catch (MySqlException e)
{
Console.WriteLine(e.ToString());
m_log.Error(e.Message, e);
if (errorSeen)
throw;
// This is "Server has gone away" and "Server lost"
//
if (e.Number == 2006 || e.Number == 2013)
{
errorSeen = true;
@ -94,7 +95,7 @@ Console.WriteLine(e.ToString());
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
m_log.Error(e.Message, e);
return 0;
}
}
@ -112,12 +113,5 @@ Console.WriteLine(e.ToString());
return cmd.ExecuteReader();
}
protected void CloseReaderCommand(MySqlCommand cmd)
{
cmd.Connection.Close();
cmd.Connection.Dispose();
cmd.Dispose();
}
}
}

View File

@ -197,29 +197,27 @@ namespace OpenSim.Data.MySQL
param["?xmax"] = xmax.ToString();
param["?ymax"] = ymax.ToString();
IDbCommand result =
dbm.Manager.Query(
using (IDbCommand result = dbm.Manager.Query(
"SELECT * FROM regions WHERE locX >= ?xmin AND locX <= ?xmax AND locY >= ?ymin AND locY <= ?ymax",
param);
IDataReader reader = result.ExecuteReader();
param))
{
using (IDataReader reader = result.ExecuteReader())
{
RegionProfileData row;
List<RegionProfileData> rows = new List<RegionProfileData>();
while ((row = dbm.Manager.readSimRow(reader)) != null)
{
rows.Add(row);
}
reader.Close();
result.Dispose();
return rows.ToArray();
}
}
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return null;
}
finally
@ -243,29 +241,27 @@ namespace OpenSim.Data.MySQL
Dictionary<string, object> param = new Dictionary<string, object>();
param["?name"] = namePrefix + "%";
IDbCommand result =
dbm.Manager.Query(
using (IDbCommand result = dbm.Manager.Query(
"SELECT * FROM regions WHERE regionName LIKE ?name",
param);
IDataReader reader = result.ExecuteReader();
param))
{
using (IDataReader reader = result.ExecuteReader())
{
RegionProfileData row;
List<RegionProfileData> rows = new List<RegionProfileData>();
while (rows.Count < maxNum && (row = dbm.Manager.readSimRow(reader)) != null)
{
rows.Add(row);
}
reader.Close();
result.Dispose();
return rows;
}
}
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return null;
}
finally
@ -288,19 +284,19 @@ namespace OpenSim.Data.MySQL
Dictionary<string, object> param = new Dictionary<string, object>();
param["?handle"] = handle.ToString();
IDbCommand result = dbm.Manager.Query("SELECT * FROM regions WHERE regionHandle = ?handle", param);
IDataReader reader = result.ExecuteReader();
using (IDbCommand result = dbm.Manager.Query("SELECT * FROM regions WHERE regionHandle = ?handle", param))
{
using (IDataReader reader = result.ExecuteReader())
{
RegionProfileData row = dbm.Manager.readSimRow(reader);
reader.Close();
result.Dispose();
return row;
}
}
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return null;
}
finally
@ -323,21 +319,22 @@ namespace OpenSim.Data.MySQL
Dictionary<string, object> param = new Dictionary<string, object>();
param["?uuid"] = uuid.ToString();
IDbCommand result = dbm.Manager.Query("SELECT * FROM regions WHERE uuid = ?uuid", param);
IDataReader reader = result.ExecuteReader();
using (IDbCommand result = dbm.Manager.Query("SELECT * FROM regions WHERE uuid = ?uuid", param))
{
using (IDataReader reader = result.ExecuteReader())
{
RegionProfileData row = dbm.Manager.readSimRow(reader);
reader.Close();
result.Dispose();
return row;
}
}
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return null;
} finally
}
finally
{
dbm.Release();
}
@ -359,22 +356,21 @@ namespace OpenSim.Data.MySQL
// Add % because this is a like query.
param["?regionName"] = regionName + "%";
// Order by statement will return shorter matches first. Only returns one record or no record.
IDbCommand result =
dbm.Manager.Query(
using (IDbCommand result = dbm.Manager.Query(
"SELECT * FROM regions WHERE regionName like ?regionName order by LENGTH(regionName) asc LIMIT 1",
param);
IDataReader reader = result.ExecuteReader();
param))
{
using (IDataReader reader = result.ExecuteReader())
{
RegionProfileData row = dbm.Manager.readSimRow(reader);
reader.Close();
result.Dispose();
return row;
}
}
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return null;
}
finally
@ -382,6 +378,7 @@ namespace OpenSim.Data.MySQL
dbm.Release();
}
}
m_log.Error("[GRID DB]: Searched for a Region Name shorter then 3 characters");
return null;
}
@ -394,11 +391,11 @@ namespace OpenSim.Data.MySQL
override public DataResponse StoreProfile(RegionProfileData profile)
{
MySQLSuperManager dbm = GetLockedConnection();
try {
if (dbm.Manager.insertRegion(profile))
try
{
if (dbm.Manager.insertRegion(profile))
return DataResponse.RESPONSE_OK;
}
else
return DataResponse.RESPONSE_ERROR;
}
finally
@ -417,14 +414,14 @@ namespace OpenSim.Data.MySQL
{
MySQLSuperManager dbm = GetLockedConnection();
try {
if (dbm.Manager.deleteRegion(uuid))
try
{
if (dbm.Manager.deleteRegion(uuid))
return DataResponse.RESPONSE_OK;
}
else
return DataResponse.RESPONSE_ERROR;
} finally
}
finally
{
dbm.Release();
}
@ -484,24 +481,24 @@ namespace OpenSim.Data.MySQL
Dictionary<string, object> param = new Dictionary<string, object>();
param["?x"] = x.ToString();
param["?y"] = y.ToString();
IDbCommand result =
dbm.Manager.Query(
using (IDbCommand result = dbm.Manager.Query(
"SELECT * FROM reservations WHERE resXMin <= ?x AND resXMax >= ?x AND resYMin <= ?y AND resYMax >= ?y",
param);
IDataReader reader = result.ExecuteReader();
param))
{
using (IDataReader reader = result.ExecuteReader())
{
ReservationData row = dbm.Manager.readReservationRow(reader);
reader.Close();
result.Dispose();
return row;
}
}
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return null;
} finally
}
finally
{
dbm.Release();
}

View File

@ -135,12 +135,13 @@ namespace OpenSim.Data.MySQL
database.CheckConnection();
MySqlCommand result =
new MySqlCommand("SELECT * FROM inventoryitems WHERE parentFolderID = ?uuid",
database.Connection);
using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE parentFolderID = ?uuid",
database.Connection))
{
result.Parameters.AddWithValue("?uuid", folderID.ToString());
MySqlDataReader reader = result.ExecuteReader();
using (MySqlDataReader reader = result.ExecuteReader())
{
while (reader.Read())
{
// A null item (because something went wrong) breaks everything in the folder
@ -149,16 +150,15 @@ namespace OpenSim.Data.MySQL
items.Add(item);
}
reader.Close();
result.Dispose();
return items;
}
}
}
}
catch (Exception e)
{
database.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return null;
}
}
@ -176,29 +176,28 @@ namespace OpenSim.Data.MySQL
{
database.CheckConnection();
MySqlCommand result =
new MySqlCommand(
using (MySqlCommand result = new MySqlCommand(
"SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid",
database.Connection);
database.Connection))
{
result.Parameters.AddWithValue("?uuid", user.ToString());
result.Parameters.AddWithValue("?zero", UUID.Zero.ToString());
MySqlDataReader reader = result.ExecuteReader();
using (MySqlDataReader reader = result.ExecuteReader())
{
List<InventoryFolderBase> items = new List<InventoryFolderBase>();
while (reader.Read())
items.Add(readInventoryFolder(reader));
reader.Close();
result.Dispose();
return items;
}
}
}
}
catch (Exception e)
{
database.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return null;
}
}
@ -217,15 +216,15 @@ namespace OpenSim.Data.MySQL
{
database.CheckConnection();
MySqlCommand result =
new MySqlCommand(
using (MySqlCommand result = new MySqlCommand(
"SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid",
database.Connection);
database.Connection))
{
result.Parameters.AddWithValue("?uuid", user.ToString());
result.Parameters.AddWithValue("?zero", UUID.Zero.ToString());
MySqlDataReader reader = result.ExecuteReader();
using (MySqlDataReader reader = result.ExecuteReader())
{
List<InventoryFolderBase> items = new List<InventoryFolderBase>();
while (reader.Read())
items.Add(readInventoryFolder(reader));
@ -238,20 +237,17 @@ namespace OpenSim.Data.MySQL
// to put such a message out, and it's too minor right now to spare the time to
// suitably refactor.
if (items.Count > 0)
{
rootFolder = items[0];
}
reader.Close();
result.Dispose();
return rootFolder;
}
}
}
}
catch (Exception e)
{
database.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return null;
}
}
@ -271,27 +267,26 @@ namespace OpenSim.Data.MySQL
{
database.CheckConnection();
MySqlCommand result =
new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?uuid",
database.Connection);
using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?uuid",
database.Connection))
{
result.Parameters.AddWithValue("?uuid", parentID.ToString());
MySqlDataReader reader = result.ExecuteReader();
using (MySqlDataReader reader = result.ExecuteReader())
{
List<InventoryFolderBase> items = new List<InventoryFolderBase>();
while (reader.Read())
items.Add(readInventoryFolder(reader));
reader.Close();
result.Dispose();
return items;
}
}
}
}
catch (Exception e)
{
database.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return null;
}
}
@ -370,25 +365,25 @@ namespace OpenSim.Data.MySQL
{
database.CheckConnection();
MySqlCommand result =
new MySqlCommand("SELECT * FROM inventoryitems WHERE inventoryID = ?uuid", database.Connection);
using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE inventoryID = ?uuid", database.Connection))
{
result.Parameters.AddWithValue("?uuid", itemID.ToString());
MySqlDataReader reader = result.ExecuteReader();
using (MySqlDataReader reader = result.ExecuteReader())
{
InventoryItemBase item = null;
if (reader.Read())
item = readInventoryItem(reader);
reader.Close();
result.Dispose();
return item;
}
}
}
}
catch (Exception e)
{
database.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
}
return null;
}
@ -413,7 +408,7 @@ namespace OpenSim.Data.MySQL
}
catch (Exception e)
{
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
}
return null;
@ -433,24 +428,25 @@ namespace OpenSim.Data.MySQL
{
database.CheckConnection();
MySqlCommand result =
new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", database.Connection);
using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", database.Connection))
{
result.Parameters.AddWithValue("?uuid", folderID.ToString());
MySqlDataReader reader = result.ExecuteReader();
using (MySqlDataReader reader = result.ExecuteReader())
{
InventoryFolderBase folder = null;
if (reader.Read())
folder = readInventoryFolder(reader);
reader.Close();
result.Dispose();
return folder;
}
}
}
}
catch (Exception e)
{
database.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return null;
}
}
@ -698,54 +694,58 @@ namespace OpenSim.Data.MySQL
try
{
List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
Dictionary<UUID, List<InventoryFolderBase>> hashtable
= new Dictionary<UUID, List<InventoryFolderBase>>(); ;
Dictionary<UUID, List<InventoryFolderBase>> hashtable = new Dictionary<UUID, List<InventoryFolderBase>>(); ;
List<InventoryFolderBase> parentFolder = new List<InventoryFolderBase>();
lock (database)
{
MySqlCommand result;
MySqlDataReader reader;
bool buildResultsFromHashTable = false;
lock (database)
{
database.CheckConnection();
/* Fetch the parent folder from the database to determine the agent ID, and if
* we're querying the root of the inventory folder tree */
result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid",
database.Connection);
using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", database.Connection))
{
result.Parameters.AddWithValue("?uuid", parentID.ToString());
reader = result.ExecuteReader();
while (reader.Read()) // Should be at most 1 result
using (MySqlDataReader reader = result.ExecuteReader())
{
// Should be at most 1 result
while (reader.Read())
parentFolder.Add(readInventoryFolder(reader));
reader.Close();
result.Dispose();
}
}
if (parentFolder.Count >= 1) // No result means parent folder does not exist
{
if (parentFolder[0].ParentID == UUID.Zero) // We are querying the root folder
{
/* Get all of the agent's folders from the database, put them in a list and return it */
result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE agentID = ?uuid",
database.Connection);
using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE agentID = ?uuid", database.Connection))
{
result.Parameters.AddWithValue("?uuid", parentFolder[0].Owner.ToString());
reader = result.ExecuteReader();
using (MySqlDataReader reader = result.ExecuteReader())
{
while (reader.Read())
{
InventoryFolderBase curFolder = readInventoryFolder(reader);
if (curFolder.ID != parentID) // Do not need to add the root node of the tree to the list
folders.Add(curFolder);
}
reader.Close();
result.Dispose();
}
}
} // if we are querying the root folder
else // else we are querying a subtree of the inventory folder tree
{
/* Get all of the agent's folders from the database, put them all in a hash table
* indexed by their parent ID */
result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE agentID = ?uuid",
database.Connection);
using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE agentID = ?uuid", database.Connection))
{
result.Parameters.AddWithValue("?uuid", parentFolder[0].Owner.ToString());
reader = result.ExecuteReader();
using (MySqlDataReader reader = result.ExecuteReader())
{
while (reader.Read())
{
InventoryFolderBase curFolder = readInventoryFolder(reader);
@ -759,8 +759,8 @@ namespace OpenSim.Data.MySQL
hashtable.Add(curFolder.ParentID, siblingList);
}
} // while more items to read from the database
reader.Close();
result.Dispose();
}
}
// Set flag so we know we need to build the results from the hash table after
// we unlock the database
@ -781,12 +781,13 @@ namespace OpenSim.Data.MySQL
folders.AddRange(hashtable[folders[i].ID]);
}
} // lock (database)
return folders;
}
catch (Exception e)
{
database.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return null;
}
}
@ -801,19 +802,18 @@ namespace OpenSim.Data.MySQL
{
database.CheckConnection();
MySqlCommand cmd =
new MySqlCommand("DELETE FROM inventoryfolders WHERE folderID=?uuid", database.Connection);
using (MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryfolders WHERE folderID=?uuid", database.Connection))
{
cmd.Parameters.AddWithValue("?uuid", folderID.ToString());
lock (database)
{
cmd.ExecuteNonQuery();
}
}
catch (MySqlException e)
{
database.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
}
}
@ -827,12 +827,11 @@ namespace OpenSim.Data.MySQL
{
database.CheckConnection();
MySqlCommand cmd =
new MySqlCommand("DELETE FROM inventoryitems WHERE parentFolderID=?uuid", database.Connection);
using (MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryitems WHERE parentFolderID=?uuid", database.Connection))
{
cmd.Parameters.AddWithValue("?uuid", folderID.ToString());
lock (database)
{
cmd.ExecuteNonQuery();
}
}
@ -865,20 +864,21 @@ namespace OpenSim.Data.MySQL
public List<InventoryItemBase> fetchActiveGestures(UUID avatarID)
{
MySqlDataReader result = null;
MySqlCommand sqlCmd = null;
lock (database)
{
try
{
database.CheckConnection();
sqlCmd = new MySqlCommand(
using (MySqlCommand sqlCmd = new MySqlCommand(
"SELECT * FROM inventoryitems WHERE avatarId = ?uuid AND assetType = ?type and flags = 1",
database.Connection);
database.Connection))
{
sqlCmd.Parameters.AddWithValue("?uuid", avatarID.ToString());
sqlCmd.Parameters.AddWithValue("?type", (int)AssetType.Gesture);
result = sqlCmd.ExecuteReader();
using (MySqlDataReader result = sqlCmd.ExecuteReader())
{
List<InventoryItemBase> list = new List<InventoryItemBase>();
while (result.Read())
{
@ -888,17 +888,14 @@ namespace OpenSim.Data.MySQL
}
return list;
}
}
}
catch (Exception e)
{
database.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return null;
}
finally
{
if (result != null) result.Close();
if (sqlCmd != null) sqlCmd.Dispose();
}
}
}
}

View File

@ -268,6 +268,8 @@ namespace OpenSim.Data.MySQL
public void RemoveObject(UUID obj, UUID regionUUID)
{
List<UUID> uuids = new List<UUID>();
// Formerly, this used to check the region UUID.
// That makes no sense, as we remove the contents of a prim
// unconditionally, but the prim dependent on the region ID.
@ -278,33 +280,22 @@ namespace OpenSim.Data.MySQL
//
lock (m_Connection)
{
MySqlCommand cmd = m_Connection.CreateCommand();
cmd.CommandText = "select UUID from prims where "+
"SceneGroupID= ?UUID";
using (MySqlCommand cmd = m_Connection.CreateCommand())
{
cmd.CommandText = "select UUID from prims where SceneGroupID= ?UUID";
cmd.Parameters.AddWithValue("UUID", obj.ToString());
List<UUID> uuids = new List<UUID>();
IDataReader reader = ExecuteReader(cmd);
try
using (IDataReader reader = ExecuteReader(cmd))
{
while (reader.Read())
{
uuids.Add(new UUID(reader["UUID"].ToString()));
}
}
finally
{
reader.Close();
}
// delete the main prims
cmd.CommandText = "delete from prims where SceneGroupID= ?UUID";
ExecuteNonQuery(cmd);
cmd.Dispose();
}
}
// there is no way this should be < 1 unless there is
// a very corrupt database, but in that case be extra
@ -315,7 +306,6 @@ namespace OpenSim.Data.MySQL
RemoveItems(uuids);
}
}
}
/// <summary>
/// Remove all persisted items of the given prim.
@ -326,18 +316,15 @@ namespace OpenSim.Data.MySQL
{
lock (m_Connection)
{
MySqlCommand cmd = m_Connection.CreateCommand();
cmd.CommandText = "delete from primitems where " +
"PrimID = ?PrimID";
using (MySqlCommand cmd = m_Connection.CreateCommand())
{
cmd.CommandText = "delete from primitems where PrimID = ?PrimID";
cmd.Parameters.AddWithValue("PrimID", uuid.ToString());
ExecuteNonQuery(cmd);
cmd.Dispose();
}
}
}
/// <summary>
/// Remove all persisted shapes for a list of prims
@ -349,8 +336,9 @@ namespace OpenSim.Data.MySQL
lock (m_Connection)
{
string sql = "delete from primshapes where ";
MySqlCommand cmd = m_Connection.CreateCommand();
using (MySqlCommand cmd = m_Connection.CreateCommand())
{
for (int i = 0; i < uuids.Count; i++)
{
if ((i + 1) == uuids.Count)
@ -365,12 +353,10 @@ namespace OpenSim.Data.MySQL
cmd.CommandText = sql;
for (int i = 0; i < uuids.Count; i++)
{
cmd.Parameters.AddWithValue("UUID" + i, uuids[i].ToString());
}
ExecuteNonQuery(cmd);
cmd.Dispose();
}
}
}
@ -384,12 +370,14 @@ namespace OpenSim.Data.MySQL
lock (m_Connection)
{
string sql = "delete from primitems where ";
MySqlCommand cmd = m_Connection.CreateCommand();
using (MySqlCommand cmd = m_Connection.CreateCommand())
{
for (int i = 0; i < uuids.Count; i++)
{
if ((i + 1) == uuids.Count)
{// end of the list
{
// end of the list
sql += "(PrimID = ?PrimID" + i + ")";
}
else
@ -400,12 +388,10 @@ namespace OpenSim.Data.MySQL
cmd.CommandText = sql;
for (int i = 0; i < uuids.Count; i++)
{
cmd.Parameters.AddWithValue("PrimID" + i, uuids[i].ToString());
}
ExecuteNonQuery(cmd);
cmd.Dispose();
}
}
}
@ -418,8 +404,8 @@ namespace OpenSim.Data.MySQL
lock (m_Connection)
{
MySqlCommand cmd = m_Connection.CreateCommand();
using (MySqlCommand cmd = m_Connection.CreateCommand())
{
cmd.CommandText = "select *, " +
"case when prims.UUID = SceneGroupID " +
"then 0 else 1 end as sort from prims " +
@ -429,9 +415,7 @@ namespace OpenSim.Data.MySQL
cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
IDataReader reader = ExecuteReader(cmd);
try
using (IDataReader reader = ExecuteReader(cmd))
{
while (reader.Read())
{
@ -481,14 +465,10 @@ namespace OpenSim.Data.MySQL
}
}
}
finally
{
reader.Close();
}
if (grp != null)
objects[grp.UUID] = grp;
cmd.Dispose();
}
}
// Instead of attempting to LoadItems on every prim,
@ -498,10 +478,10 @@ namespace OpenSim.Data.MySQL
List<SceneObjectPart> primsWithInventory = new List<SceneObjectPart>();
lock (m_Connection)
{
MySqlCommand itemCmd = m_Connection.CreateCommand();
using (MySqlCommand itemCmd = m_Connection.CreateCommand())
{
itemCmd.CommandText = "select distinct primID from primitems";
IDataReader itemReader = ExecuteReader(itemCmd);
try
using (IDataReader itemReader = ExecuteReader(itemCmd))
{
while (itemReader.Read())
{
@ -515,17 +495,12 @@ namespace OpenSim.Data.MySQL
}
}
}
finally
{
itemReader.Close();
}
itemCmd.Dispose();
}
foreach (SceneObjectPart prim in primsWithInventory)
{
LoadItems(prim);
}
m_log.DebugFormat("[REGION DB]: Loaded {0} objects using {1} prims", objects.Count, prims.Count);
return new List<SceneObjectGroup>(objects.Values);
}
@ -538,34 +513,25 @@ namespace OpenSim.Data.MySQL
{
lock (m_Connection)
{
MySqlCommand cmd = m_Connection.CreateCommand();
cmd.CommandText = "select * from primitems where "+
"PrimID = ?PrimID";
List<TaskInventoryItem> inventory = new List<TaskInventoryItem>();
using (MySqlCommand cmd = m_Connection.CreateCommand())
{
cmd.CommandText = "select * from primitems where PrimID = ?PrimID";
cmd.Parameters.AddWithValue("PrimID", prim.UUID.ToString());
IDataReader reader = ExecuteReader(cmd);
List<TaskInventoryItem> inventory =
new List<TaskInventoryItem>();
try
using (IDataReader reader = ExecuteReader(cmd))
{
while (reader.Read())
{
TaskInventoryItem item = BuildItem(reader);
item.ParentID = prim.UUID; // Values in database are
// often wrong
item.ParentID = prim.UUID; // Values in database are often wrong
inventory.Add(item);
}
}
finally
{
reader.Close();
}
cmd.Dispose();
prim.Inventory.RestoreInventoryItems(inventory);
}
}
@ -576,10 +542,9 @@ namespace OpenSim.Data.MySQL
lock (m_Connection)
{
MySqlCommand cmd = m_Connection.CreateCommand();
cmd.CommandText = "delete from terrain where " +
"RegionUUID = ?RegionUUID";
using (MySqlCommand cmd = m_Connection.CreateCommand())
{
cmd.CommandText = "delete from terrain where RegionUUID = ?RegionUUID";
cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
ExecuteNonQuery(cmd);
@ -588,11 +553,10 @@ namespace OpenSim.Data.MySQL
"Revision, Heightfield) values (?RegionUUID, " +
"1, ?Heightfield)";
cmd.Parameters.AddWithValue("Heightfield",
SerializeTerrain(ter));
cmd.Parameters.AddWithValue("Heightfield", SerializeTerrain(ter));
ExecuteNonQuery(cmd);
cmd.Dispose();
}
}
}
@ -602,42 +566,40 @@ namespace OpenSim.Data.MySQL
lock (m_Connection)
{
MySqlCommand cmd = m_Connection.CreateCommand();
using (MySqlCommand cmd = m_Connection.CreateCommand())
{
cmd.CommandText = "select RegionUUID, Revision, Heightfield " +
"from terrain where RegionUUID = ?RegionUUID " +
"order by Revision desc limit 1";
cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
IDataReader reader = ExecuteReader(cmd);
try
using (IDataReader reader = ExecuteReader(cmd))
{
while (reader.Read())
{
int rev = Convert.ToInt32(reader["Revision"]);
terrain = new double[(int)Constants.RegionSize, (int)Constants.RegionSize];
terrain.Initialize();
MemoryStream mstr = new MemoryStream((byte[]) reader["Heightfield"]);
int rev = 0;
BinaryReader br = new BinaryReader(mstr);
using (MemoryStream mstr = new MemoryStream((byte[])reader["Heightfield"]))
{
using (BinaryReader br = new BinaryReader(mstr))
{
for (int x = 0; x < (int)Constants.RegionSize; x++)
{
for (int y = 0; y < (int)Constants.RegionSize; y++)
{
terrain[x, y] = br.ReadDouble();
}
rev = Convert.ToInt32(reader["Revision"]);
}
m_log.InfoFormat("[REGION DB]: Loaded terrain " +
"revision r{0}", rev);
}
}
finally
{
reader.Close();
m_log.InfoFormat("[REGION DB]: Loaded terrain revision r{0}", rev);
}
}
}
}
cmd.Dispose();
}
return terrain;
@ -647,14 +609,13 @@ namespace OpenSim.Data.MySQL
{
lock (m_Connection)
{
MySqlCommand cmd = m_Connection.CreateCommand();
using (MySqlCommand cmd = m_Connection.CreateCommand())
{
cmd.CommandText = "delete from land where UUID = ?UUID";
cmd.Parameters.AddWithValue("UUID", globalID.ToString());
ExecuteNonQuery(cmd);
cmd.Dispose();
}
}
}
@ -662,8 +623,8 @@ namespace OpenSim.Data.MySQL
{
lock (m_Connection)
{
MySqlCommand cmd = m_Connection.CreateCommand();
using (MySqlCommand cmd = m_Connection.CreateCommand())
{
cmd.CommandText = "replace into land (UUID, RegionUUID, " +
"LocalLandID, Bitmap, Name, Description, " +
"OwnerUUID, IsGroupOwned, Area, AuctionID, " +
@ -689,8 +650,7 @@ namespace OpenSim.Data.MySQL
ExecuteNonQuery(cmd);
cmd.CommandText = "delete from landaccesslist where " +
"LandUUID = ?UUID";
cmd.CommandText = "delete from landaccesslist where LandUUID = ?UUID";
ExecuteNonQuery(cmd);
@ -699,14 +659,13 @@ namespace OpenSim.Data.MySQL
"AccessUUID, Flags) values (?LandUUID, ?AccessUUID, " +
"?Flags)";
foreach (ParcelManager.ParcelAccessEntry entry in
parcel.LandData.ParcelAccessList)
foreach (ParcelManager.ParcelAccessEntry entry in parcel.LandData.ParcelAccessList)
{
FillLandAccessCommand(cmd, entry, parcel.LandData.GlobalID);
ExecuteNonQuery(cmd);
cmd.Parameters.Clear();
}
cmd.Dispose();
}
}
}
@ -716,15 +675,12 @@ namespace OpenSim.Data.MySQL
lock (m_Connection)
{
MySqlCommand cmd = m_Connection.CreateCommand();
cmd.CommandText = "select * from regionsettings where " +
"regionUUID = ?RegionUUID";
using (MySqlCommand cmd = m_Connection.CreateCommand())
{
cmd.CommandText = "select * from regionsettings where regionUUID = ?RegionUUID";
cmd.Parameters.AddWithValue("regionUUID", regionUUID);
IDataReader reader = ExecuteReader(cmd);
try
using (IDataReader reader = ExecuteReader(cmd))
{
if (reader.Read())
{
@ -740,11 +696,7 @@ namespace OpenSim.Data.MySQL
StoreRegionSettings(rs);
}
}
finally
{
reader.Close();
}
cmd.Dispose();
}
return rs;
@ -754,8 +706,8 @@ namespace OpenSim.Data.MySQL
{
lock (m_Connection)
{
MySqlCommand cmd = m_Connection.CreateCommand();
using (MySqlCommand cmd = m_Connection.CreateCommand())
{
cmd.CommandText = "replace into regionsettings (regionUUID, " +
"block_terraform, block_fly, allow_damage, " +
"restrict_pushing, allow_land_resell, " +
@ -792,8 +744,7 @@ namespace OpenSim.Data.MySQL
FillRegionSettingsCommand(cmd, rs);
ExecuteNonQuery(cmd);
cmd.Dispose();
}
}
}
@ -803,16 +754,12 @@ namespace OpenSim.Data.MySQL
lock (m_Connection)
{
MySqlCommand cmd = m_Connection.CreateCommand();
cmd.CommandText = "select * from land where " +
"RegionUUID = ?RegionUUID";
using (MySqlCommand cmd = m_Connection.CreateCommand())
{
cmd.CommandText = "select * from land where RegionUUID = ?RegionUUID";
cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
IDataReader reader = ExecuteReader(cmd);
try
using (IDataReader reader = ExecuteReader(cmd))
{
while (reader.Read())
{
@ -820,35 +767,25 @@ namespace OpenSim.Data.MySQL
landData.Add(newLand);
}
}
finally
{
reader.Close();
}
using (MySqlCommand cmd = m_Connection.CreateCommand())
{
foreach (LandData land in landData)
{
cmd.Parameters.Clear();
cmd.CommandText = "select * from landaccesslist " +
"where LandUUID = ?LandUUID";
cmd.CommandText = "select * from landaccesslist where LandUUID = ?LandUUID";
cmd.Parameters.AddWithValue("LandUUID", land.GlobalID.ToString());
reader = ExecuteReader(cmd);
try
using (IDataReader reader = ExecuteReader(cmd))
{
while (reader.Read())
{
land.ParcelAccessList.Add(BuildLandAccessData(reader));
}
}
finally
{
reader.Close();
}
}
cmd.Dispose();
}
return landData;

View File

@ -134,8 +134,8 @@ namespace OpenSim.Data.MySQL
/// </summary>
protected void GetWaitTimeout()
{
MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect, dbcon);
using (MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect, dbcon))
{
using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
{
if (dbReader.Read())
@ -143,9 +143,7 @@ namespace OpenSim.Data.MySQL
m_waitTimeout
= Convert.ToInt32(dbReader["@@wait_timeout"]) * TimeSpan.TicksPerSecond + m_waitTimeoutLeeway;
}
dbReader.Close();
cmd.Dispose();
}
}
m_lastConnectionUse = DateTime.Now.Ticks;
@ -303,10 +301,10 @@ namespace OpenSim.Data.MySQL
{
CheckConnection();
MySqlCommand tablesCmd =
new MySqlCommand(
using (MySqlCommand tablesCmd = new MySqlCommand(
"SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=?dbname",
dbcon);
dbcon))
{
tablesCmd.Parameters.AddWithValue("?dbname", dbcon.Database);
using (MySqlDataReader tables = tablesCmd.ExecuteReader())
@ -324,10 +322,10 @@ namespace OpenSim.Data.MySQL
}
catch (Exception e)
{
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
}
}
}
tables.Close();
}
}
}
@ -358,7 +356,7 @@ namespace OpenSim.Data.MySQL
catch (Exception e)
{
// Return null if it fails.
m_log.Error("Failed during Query generation: " + e.ToString());
m_log.Error("Failed during Query generation: " + e.Message, e);
return null;
}
}
@ -694,8 +692,6 @@ namespace OpenSim.Data.MySQL
ret.Add(attachpoint, item);
}
r.Close();
return ret;
}

View File

@ -56,13 +56,14 @@ namespace OpenSim.Data.MySQL
if (scopeID != UUID.Zero)
command += " and ScopeID = ?scopeID";
MySqlCommand cmd = new MySqlCommand(command);
using (MySqlCommand cmd = new MySqlCommand(command))
{
cmd.Parameters.AddWithValue("?regionName", regionName);
cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
return RunCommand(cmd);
}
}
public RegionData Get(int posX, int posY, UUID scopeID)
{
@ -70,8 +71,8 @@ namespace OpenSim.Data.MySQL
if (scopeID != UUID.Zero)
command += " and ScopeID = ?scopeID";
MySqlCommand cmd = new MySqlCommand(command);
using (MySqlCommand cmd = new MySqlCommand(command))
{
cmd.Parameters.AddWithValue("?posX", posX.ToString());
cmd.Parameters.AddWithValue("?posY", posY.ToString());
cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
@ -82,6 +83,7 @@ namespace OpenSim.Data.MySQL
return ret[0];
}
}
public RegionData Get(UUID regionID, UUID scopeID)
{
@ -89,8 +91,8 @@ namespace OpenSim.Data.MySQL
if (scopeID != UUID.Zero)
command += " and ScopeID = ?scopeID";
MySqlCommand cmd = new MySqlCommand(command);
using (MySqlCommand cmd = new MySqlCommand(command))
{
cmd.Parameters.AddWithValue("?regionID", regionID.ToString());
cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
@ -100,6 +102,7 @@ namespace OpenSim.Data.MySQL
return ret[0];
}
}
public List<RegionData> Get(int startX, int startY, int endX, int endY, UUID scopeID)
{
@ -107,8 +110,8 @@ namespace OpenSim.Data.MySQL
if (scopeID != UUID.Zero)
command += " and ScopeID = ?scopeID";
MySqlCommand cmd = new MySqlCommand(command);
using (MySqlCommand cmd = new MySqlCommand(command))
{
cmd.Parameters.AddWithValue("?startX", startX.ToString());
cmd.Parameters.AddWithValue("?startY", startY.ToString());
cmd.Parameters.AddWithValue("?endX", endX.ToString());
@ -117,13 +120,14 @@ namespace OpenSim.Data.MySQL
return RunCommand(cmd);
}
}
public List<RegionData> RunCommand(MySqlCommand cmd)
{
List<RegionData> retList = new List<RegionData>();
IDataReader result = ExecuteReader(cmd);
using (IDataReader result = ExecuteReader(cmd))
{
while (result.Read())
{
RegionData ret = new RegionData();
@ -168,9 +172,7 @@ namespace OpenSim.Data.MySQL
retList.Add(ret);
}
result.Close();
CloseReaderCommand(cmd);
}
return retList;
}
@ -198,8 +200,8 @@ namespace OpenSim.Data.MySQL
string[] fields = new List<string>(data.Data.Keys).ToArray();
MySqlCommand cmd = new MySqlCommand();
using (MySqlCommand cmd = new MySqlCommand())
{
string update = "update `" + m_Realm + "` set locX=?posX, locY=?posY, sizeX=?sizeX, sizeY=?sizeY";
foreach (string field in fields)
{
@ -233,41 +235,37 @@ namespace OpenSim.Data.MySQL
if (ExecuteNonQuery(cmd) < 1)
{
cmd.Dispose();
return false;
}
}
cmd.Dispose();
}
return true;
}
public bool SetDataItem(UUID regionID, string item, string value)
{
MySqlCommand cmd = new MySqlCommand("update `" + m_Realm +
"` set `" + item + "` = ?" + item + " where uuid = ?UUID");
using (MySqlCommand cmd = new MySqlCommand("update `" + m_Realm + "` set `" + item + "` = ?" + item + " where uuid = ?UUID"))
{
cmd.Parameters.AddWithValue("?" + item, value);
cmd.Parameters.AddWithValue("?UUID", regionID.ToString());
if (ExecuteNonQuery(cmd) > 0)
return true;
}
return false;
}
public bool Delete(UUID regionID)
{
MySqlCommand cmd = new MySqlCommand("delete from `" + m_Realm +
"` where uuid = ?UUID");
using (MySqlCommand cmd = new MySqlCommand("delete from `" + m_Realm + "` where uuid = ?UUID"))
{
cmd.Parameters.AddWithValue("?UUID", regionID.ToString());
if (ExecuteNonQuery(cmd) > 0)
return true;
}
return false;
}

View File

@ -64,13 +64,13 @@ namespace OpenSim.Data.MySQL
if (scopeID != UUID.Zero)
command += " and ScopeID = ?scopeID";
MySqlCommand cmd = new MySqlCommand(command);
using (MySqlCommand cmd = new MySqlCommand(command))
{
cmd.Parameters.AddWithValue("?principalID", principalID.ToString());
cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
IDataReader result = ExecuteReader(cmd);
using (IDataReader result = ExecuteReader(cmd))
{
if (result.Read())
{
ret.PrincipalID = principalID;
@ -97,14 +97,10 @@ namespace OpenSim.Data.MySQL
ret.Data[s] = result[s].ToString();
}
result.Close();
CloseReaderCommand(cmd);
return ret;
}
result.Close();
CloseReaderCommand(cmd);
}
}
return null;
}
@ -118,8 +114,8 @@ namespace OpenSim.Data.MySQL
string[] fields = new List<string>(data.Data.Keys).ToArray();
MySqlCommand cmd = new MySqlCommand();
using (MySqlCommand cmd = new MySqlCommand())
{
string update = "update `" + m_Realm + "` set ";
bool first = true;
foreach (string field in fields)
@ -156,23 +152,22 @@ namespace OpenSim.Data.MySQL
return false;
}
}
cmd.Dispose();
}
return true;
}
public bool SetDataItem(UUID principalID, string item, string value)
{
MySqlCommand cmd = new MySqlCommand("update `" + m_Realm +
"` set `" + item + "` = ?" + item + " where UUID = ?UUID");
using (MySqlCommand cmd = new MySqlCommand("update `" + m_Realm + "` set `" +
item + "` = ?" + item + " where UUID = ?UUID"))
{
cmd.Parameters.AddWithValue("?" + item, value);
cmd.Parameters.AddWithValue("?UUID", principalID.ToString());
if (ExecuteNonQuery(cmd) > 0)
return true;
}
return false;
}

View File

@ -181,21 +181,20 @@ namespace OpenSim.Data.MySQL
param["?first"] = user;
param["?second"] = last;
IDbCommand result =
dbm.Manager.Query(
"SELECT * FROM " + m_usersTableName + " WHERE username = ?first AND lastname = ?second", param);
IDataReader reader = result.ExecuteReader();
using (IDbCommand result = dbm.Manager.Query(
"SELECT * FROM " + m_usersTableName + " WHERE username = ?first AND lastname = ?second", param))
{
using (IDataReader reader = result.ExecuteReader())
{
UserProfileData row = dbm.Manager.readUserRow(reader);
reader.Dispose();
result.Dispose();
return row;
}
}
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return null;
}
finally
@ -220,28 +219,30 @@ namespace OpenSim.Data.MySQL
try
{
IDbCommand adder =
dbm.Manager.Query(
using (IDbCommand adder = dbm.Manager.Query(
"INSERT INTO `" + m_userFriendsTableName + "` " +
"(`ownerID`,`friendID`,`friendPerms`,`datetimestamp`) " +
"VALUES " +
"(?ownerID,?friendID,?friendPerms,?datetimestamp)",
param);
param))
{
adder.ExecuteNonQuery();
}
adder =
dbm.Manager.Query(
using (IDbCommand adder = dbm.Manager.Query(
"INSERT INTO `" + m_userFriendsTableName + "` " +
"(`ownerID`,`friendID`,`friendPerms`,`datetimestamp`) " +
"VALUES " +
"(?friendID,?ownerID,?friendPerms,?datetimestamp)",
param);
param))
{
adder.ExecuteNonQuery();
}
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return;
}
finally
@ -260,22 +261,24 @@ namespace OpenSim.Data.MySQL
try
{
IDbCommand updater =
dbm.Manager.Query(
using (IDbCommand updater = dbm.Manager.Query(
"delete from " + m_userFriendsTableName + " where ownerID = ?ownerID and friendID = ?friendID",
param);
param))
{
updater.ExecuteNonQuery();
}
updater =
dbm.Manager.Query(
using (IDbCommand updater = dbm.Manager.Query(
"delete from " + m_userFriendsTableName + " where ownerID = ?friendID and friendID = ?ownerID",
param);
param))
{
updater.ExecuteNonQuery();
}
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return;
}
finally
@ -295,18 +298,19 @@ namespace OpenSim.Data.MySQL
try
{
IDbCommand updater =
dbm.Manager.Query(
using (IDbCommand updater = dbm.Manager.Query(
"update " + m_userFriendsTableName +
" SET friendPerms = ?friendPerms " +
"where ownerID = ?ownerID and friendID = ?friendID",
param);
param))
{
updater.ExecuteNonQuery();
}
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return;
}
finally
@ -327,14 +331,14 @@ namespace OpenSim.Data.MySQL
try
{
//Left Join userfriends to itself
IDbCommand result =
dbm.Manager.Query(
using (IDbCommand result = dbm.Manager.Query(
"select a.ownerID,a.friendID,a.friendPerms,b.friendPerms as ownerperms from " +
m_userFriendsTableName + " as a, " + m_userFriendsTableName + " as b" +
" where a.ownerID = ?ownerID and b.ownerID = a.friendID and b.friendID = a.ownerID",
param);
IDataReader reader = result.ExecuteReader();
param))
{
using (IDataReader reader = result.ExecuteReader())
{
while (reader.Read())
{
FriendListItem fli = new FriendListItem();
@ -347,14 +351,13 @@ namespace OpenSim.Data.MySQL
Lfli.Add(fli);
}
reader.Dispose();
result.Dispose();
}
}
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return Lfli;
}
finally
@ -376,11 +379,12 @@ namespace OpenSim.Data.MySQL
{
Dictionary<string, object> param = new Dictionary<string, object>();
param["?uuid"] = uuid.ToString();
IDbCommand result =
dbm.Manager.Query("select agentOnline,currentHandle from " + m_agentsTableName +
" where UUID = ?uuid", param);
IDataReader reader = result.ExecuteReader();
using (IDbCommand result = dbm.Manager.Query("select agentOnline,currentHandle from " + m_agentsTableName +
" where UUID = ?uuid", param))
{
using (IDataReader reader = result.ExecuteReader())
{
while (reader.Read())
{
FriendRegionInfo fri = new FriendRegionInfo();
@ -389,16 +393,15 @@ namespace OpenSim.Data.MySQL
infos[uuid] = fri;
}
reader.Dispose();
result.Dispose();
}
}
}
}
catch (Exception e)
{
m_log.Warn("[MYSQL]: Got exception on trying to find friends regions:", e);
dbm.Manager.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
}
finally
{
@ -427,13 +430,13 @@ namespace OpenSim.Data.MySQL
try
{
IDbCommand result =
dbm.Manager.Query(
using (IDbCommand result = dbm.Manager.Query(
"SELECT UUID,username,lastname FROM " + m_usersTableName +
" WHERE username like ?first AND lastname like ?second LIMIT 100",
param);
IDataReader reader = result.ExecuteReader();
param))
{
using (IDataReader reader = result.ExecuteReader())
{
while (reader.Read())
{
AvatarPickerAvatar user = new AvatarPickerAvatar();
@ -442,13 +445,13 @@ namespace OpenSim.Data.MySQL
user.lastName = (string)reader["lastname"];
returnlist.Add(user);
}
reader.Dispose();
result.Dispose();
}
}
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return returnlist;
}
finally
@ -465,13 +468,13 @@ namespace OpenSim.Data.MySQL
Dictionary<string, object> param = new Dictionary<string, object>();
param["?first"] = objAlphaNumericPattern.Replace(querysplit[0], String.Empty) + "%";
IDbCommand result =
dbm.Manager.Query(
using (IDbCommand result = dbm.Manager.Query(
"SELECT UUID,username,lastname FROM " + m_usersTableName +
" WHERE username like ?first OR lastname like ?first LIMIT 100",
param);
IDataReader reader = result.ExecuteReader();
param))
{
using (IDataReader reader = result.ExecuteReader())
{
while (reader.Read())
{
AvatarPickerAvatar user = new AvatarPickerAvatar();
@ -480,13 +483,13 @@ namespace OpenSim.Data.MySQL
user.lastName = (string)reader["lastname"];
returnlist.Add(user);
}
reader.Dispose();
result.Dispose();
}
}
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return returnlist;
}
finally
@ -510,20 +513,19 @@ namespace OpenSim.Data.MySQL
Dictionary<string, object> param = new Dictionary<string, object>();
param["?uuid"] = uuid.ToString();
IDbCommand result = dbm.Manager.Query("SELECT * FROM " + m_usersTableName + " WHERE UUID = ?uuid", param);
IDataReader reader = result.ExecuteReader();
using (IDbCommand result = dbm.Manager.Query("SELECT * FROM " + m_usersTableName + " WHERE UUID = ?uuid", param))
{
using (IDataReader reader = result.ExecuteReader())
{
UserProfileData row = dbm.Manager.readUserRow(reader);
reader.Dispose();
result.Dispose();
return row;
}
}
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return null;
}
finally
@ -577,7 +579,7 @@ namespace OpenSim.Data.MySQL
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return;
}
finally
@ -600,21 +602,19 @@ namespace OpenSim.Data.MySQL
Dictionary<string, object> param = new Dictionary<string, object>();
param["?uuid"] = uuid.ToString();
IDbCommand result = dbm.Manager.Query("SELECT * FROM " + m_agentsTableName + " WHERE UUID = ?uuid",
param);
IDataReader reader = result.ExecuteReader();
using (IDbCommand result = dbm.Manager.Query("SELECT * FROM " + m_agentsTableName + " WHERE UUID = ?uuid", param))
{
using (IDataReader reader = result.ExecuteReader())
{
UserAgentData row = dbm.Manager.readAgentRow(reader);
reader.Dispose();
result.Dispose();
return row;
}
}
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return null;
}
finally
@ -638,7 +638,8 @@ namespace OpenSim.Data.MySQL
try
{
dbm.Manager.insertUserRow(user.ID, user.FirstName, user.SurName, user.Email, user.PasswordHash, user.PasswordSalt,
dbm.Manager.insertUserRow(
user.ID, user.FirstName, user.SurName, user.Email, user.PasswordHash, user.PasswordSalt,
user.HomeRegion, user.HomeRegionID, user.HomeLocation.X, user.HomeLocation.Y,
user.HomeLocation.Z,
user.HomeLookAt.X, user.HomeLookAt.Y, user.HomeLookAt.Z, user.Created,
@ -650,7 +651,7 @@ namespace OpenSim.Data.MySQL
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
}
finally
{
@ -676,7 +677,7 @@ namespace OpenSim.Data.MySQL
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
}
finally
{
@ -693,7 +694,8 @@ namespace OpenSim.Data.MySQL
MySQLSuperManager dbm = GetLockedConnection("UpdateUserProfile");
try
{
dbm.Manager.updateUserRow(user.ID, user.FirstName, user.SurName, user.Email, user.PasswordHash, user.PasswordSalt,
dbm.Manager.updateUserRow(
user.ID, user.FirstName, user.SurName, user.Email, user.PasswordHash, user.PasswordSalt,
user.HomeRegion, user.HomeRegionID, user.HomeLocation.X, user.HomeLocation.Y,
user.HomeLocation.Z, user.HomeLookAt.X,
user.HomeLookAt.Y, user.HomeLookAt.Z, user.Created, user.LastLogin,
@ -748,29 +750,29 @@ namespace OpenSim.Data.MySQL
Dictionary<string, object> param = new Dictionary<string, object>();
param["?owner"] = user.ToString();
IDbCommand result = dbm.Manager.Query(
"SELECT * FROM " + m_appearanceTableName + " WHERE owner = ?owner", param);
IDataReader reader = result.ExecuteReader();
using (IDbCommand result = dbm.Manager.Query("SELECT * FROM " + m_appearanceTableName + " WHERE owner = ?owner", param))
{
using (IDataReader reader = result.ExecuteReader())
{
AvatarAppearance appearance = dbm.Manager.readAppearanceRow(reader);
reader.Dispose();
result.Dispose();
if (null == appearance)
if (appearance == null)
{
m_log.WarnFormat("[USER DB] No appearance found for user {0}", user.ToString());
return null;
}
else
{
appearance.SetAttachments(GetUserAttachments(user));
return appearance;
}
}
}
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return null;
}
finally
@ -798,7 +800,7 @@ namespace OpenSim.Data.MySQL
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
}
finally
{
@ -833,20 +835,20 @@ namespace OpenSim.Data.MySQL
try
{
IDbCommand result = dbm.Manager.Query(
"SELECT attachpoint, item, asset from " + m_attachmentsTableName + " WHERE UUID = ?uuid", param);
IDataReader reader = result.ExecuteReader();
using (IDbCommand result = dbm.Manager.Query(
"SELECT attachpoint, item, asset from " + m_attachmentsTableName + " WHERE UUID = ?uuid", param))
{
using (IDataReader reader = result.ExecuteReader())
{
Hashtable ret = dbm.Manager.readAttachments(reader);
reader.Dispose();
result.Dispose();
return ret;
}
}
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return null;
}
finally
@ -905,7 +907,7 @@ namespace OpenSim.Data.MySQL
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.ToString());
m_log.Error(e.Message, e);
return;
}
finally

View File

@ -205,13 +205,10 @@ namespace OpenSim
Directory.CreateDirectory(m_crashDir);
}
string log = Util.GetUniqueFilename(ex.GetType() + ".txt");
StreamWriter m_crashLog =
new StreamWriter(
Path.Combine(m_crashDir, log)
);
using (StreamWriter m_crashLog = new StreamWriter(Path.Combine(m_crashDir, log)))
{
m_crashLog.WriteLine(msg);
m_crashLog.Close();
}
File.Copy("OpenSim.ini", Path.Combine(m_crashDir, log + "_OpenSim.ini"), true);
}