Reverting the memory leak patch for MySQL. Problems have been reported with the grid server after running for several hours

0.6.8-post-fixes
John Hurliman 2009-11-02 11:19:55 -08:00
parent f4e9809b7d
commit 6309fcc5b4
15 changed files with 932 additions and 893 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -131,26 +131,25 @@ 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!");
using (DbCommand cmd = _conn.CreateCommand())
DbCommand cmd = _conn.CreateCommand();
foreach (KeyValuePair<int, string> kvp in migrations)
{
foreach (KeyValuePair<int, string> kvp in migrations)
{
int newversion = kvp.Key;
cmd.CommandText = kvp.Value;
// we need to up the command timeout to infinite as we might be doing long migrations.
cmd.CommandTimeout = 0;
cmd.ExecuteNonQuery();
int newversion = kvp.Key;
cmd.CommandText = kvp.Value;
// we need to up the command timeout to infinite as we might be doing long migrations.
cmd.CommandTimeout = 0;
cmd.ExecuteNonQuery();
if (version == 0)
{
InsertVersion(_type, newversion);
}
else
{
UpdateVersion(_type, newversion);
}
version = newversion;
if (version == 0)
{
InsertVersion(_type, newversion);
}
else
{
UpdateVersion(_type, newversion);
}
version = newversion;
cmd.Dispose();
}
}
@ -190,45 +189,43 @@ namespace OpenSim.Data
protected virtual int FindVersion(DbConnection conn, string type)
{
int version = 0;
using (DbCommand cmd = conn.CreateCommand())
DbCommand cmd = conn.CreateCommand();
try
{
try
cmd.CommandText = "select version from migrations where name='" + type +"' order by version desc";
using (IDataReader reader = cmd.ExecuteReader())
{
cmd.CommandText = "select version from migrations where name='" + type + "' order by version desc";
using (IDataReader reader = cmd.ExecuteReader())
if (reader.Read())
{
if (reader.Read())
version = Convert.ToInt32(reader["version"]);
version = Convert.ToInt32(reader["version"]);
}
}
catch
{
// Something went wrong, so we're version 0
reader.Close();
}
}
catch
{
// Something went wrong, so we're version 0
}
cmd.Dispose();
return version;
}
private void InsertVersion(string type, int version)
{
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();
}
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)
{
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();
}
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

@ -139,42 +139,45 @@ namespace OpenSim.Data.MySQL
{
_dbConnection.CheckConnection();
using (MySqlCommand cmd = new MySqlCommand(
"SELECT name, description, assetType, local, temporary, data FROM assets WHERE id=?id",
_dbConnection.Connection))
MySqlCommand cmd =
new MySqlCommand(
"SELECT name, description, assetType, local, temporary, data FROM assets WHERE id=?id",
_dbConnection.Connection);
cmd.Parameters.AddWithValue("?id", assetID.ToString());
try
{
cmd.Parameters.AddWithValue("?id", assetID.ToString());
try
using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
{
using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
if (dbReader.Read())
{
if (dbReader.Read())
{
asset = new AssetBase();
asset.Data = (byte[])dbReader["data"];
asset.Description = (string)dbReader["description"];
asset.FullID = assetID;
asset = new AssetBase();
asset.Data = (byte[]) dbReader["data"];
asset.Description = (string) dbReader["description"];
asset.FullID = assetID;
string local = dbReader["local"].ToString();
if (local.Equals("1") || local.Equals("true", StringComparison.InvariantCultureIgnoreCase))
asset.Local = true;
else
asset.Local = false;
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"]);
}
asset.Name = (string) dbReader["name"];
asset.Type = (sbyte) dbReader["assetType"];
asset.Temporary = Convert.ToBoolean(dbReader["temporary"]);
}
dbReader.Close();
cmd.Dispose();
}
catch (Exception e)
{
m_log.ErrorFormat(
"[ASSETS DB]: MySql failure fetching asset {0}" + Environment.NewLine + e.ToString()
+ Environment.NewLine + "Reconnecting", assetID);
_dbConnection.Reconnect();
}
if (asset != null)
UpdateAccessTime(asset);
}
catch (Exception e)
{
m_log.ErrorFormat(
"[ASSETS DB]: MySql failure fetching asset {0}" + Environment.NewLine + e.ToString()
+ Environment.NewLine + "Reconnecting", assetID);
_dbConnection.Reconnect();
}
}
return asset;
@ -291,27 +294,32 @@ namespace OpenSim.Data.MySQL
{
_dbConnection.CheckConnection();
using (MySqlCommand cmd = new MySqlCommand(
"SELECT id FROM assets WHERE id=?id",
_dbConnection.Connection))
{
cmd.Parameters.AddWithValue("?id", uuid.ToString());
MySqlCommand cmd =
new MySqlCommand(
"SELECT id FROM assets WHERE id=?id",
_dbConnection.Connection);
try
cmd.Parameters.AddWithValue("?id", uuid.ToString());
try
{
using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
{
using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
if (dbReader.Read())
{
if (dbReader.Read())
assetExists = true;
assetExists = true;
}
dbReader.Close();
cmd.Dispose();
}
catch (Exception e)
{
m_log.ErrorFormat(
"[ASSETS DB]: MySql failure fetching asset {0}" + Environment.NewLine + e.ToString()
+ Environment.NewLine + "Attempting reconnection", uuid);
_dbConnection.Reconnect();
}
}
catch (Exception e)
{
m_log.ErrorFormat(
"[ASSETS DB]: MySql failure fetching asset {0}" + Environment.NewLine + e.ToString()
+ Environment.NewLine + "Attempting reconnection", uuid);
_dbConnection.Reconnect();
}
}

View File

@ -55,7 +55,9 @@ 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");
MySqlCommand cmd = new MySqlCommand(
"select * from `"+m_Realm+"` where UUID = ?principalID"
);
cmd.Parameters.AddWithValue("?principalID", principalID.ToString());
@ -82,14 +84,16 @@ namespace OpenSim.Data.MySQL
ret.Data[s] = result[s].ToString();
}
CloseDBConnection(result, cmd);
result.Close();
CloseReaderCommand(cmd);
return ret;
}
else
{
CloseDBConnection(result, cmd);
return null;
}
result.Close();
CloseReaderCommand(cmd);
return null;
}
public bool Store(AuthenticationData data)

View File

@ -95,17 +95,21 @@ namespace OpenSim.Data.MySQL
protected void GetWaitTimeout()
{
using (MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect, m_connection))
MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect,
m_connection);
using (MySqlDataReader dbReader =
cmd.ExecuteReader(CommandBehavior.SingleRow))
{
using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
if (dbReader.Read())
{
if (dbReader.Read())
{
m_waitTimeout
= Convert.ToInt32(dbReader["@@wait_timeout"]) *
TimeSpan.TicksPerSecond + m_waitTimeoutLeeway;
}
m_waitTimeout
= Convert.ToInt32(dbReader["@@wait_timeout"]) *
TimeSpan.TicksPerSecond + m_waitTimeoutLeeway;
}
dbReader.Close();
cmd.Dispose();
}
m_lastConnectionUse = DateTime.Now.Ticks;
@ -143,122 +147,53 @@ namespace OpenSim.Data.MySQL
CheckConnection();
bool migration = true;
MySqlCommand cmd = m_connection.CreateCommand();
using (MySqlCommand cmd = m_connection.CreateCommand())
cmd.CommandText = sql;
cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
IDataReader r = cmd.ExecuteReader();
if (r.Read())
{
cmd.CommandText = sql;
cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
using (IDataReader r = cmd.ExecuteReader())
foreach (string name in FieldList)
{
if (r.Read())
if (m_FieldMap[name].GetValue(es) is bool)
{
migration = false;
int v = Convert.ToInt32(r[name]);
if (v != 0)
m_FieldMap[name].SetValue(es, true);
else
m_FieldMap[name].SetValue(es, false);
}
else if (m_FieldMap[name].GetValue(es) is UUID)
{
UUID uuid = UUID.Zero;
foreach (string name in FieldList)
{
if (m_FieldMap[name].GetValue(es) is bool)
{
int v = Convert.ToInt32(r[name]);
if (v != 0)
m_FieldMap[name].SetValue(es, true);
else
m_FieldMap[name].SetValue(es, false);
}
else if (m_FieldMap[name].GetValue(es) is UUID)
{
UUID uuid = UUID.Zero;
UUID.TryParse(r[name].ToString(), out uuid);
m_FieldMap[name].SetValue(es, uuid);
}
else
{
m_FieldMap[name].SetValue(es, r[name]);
}
}
UUID.TryParse(r[name].ToString(), out uuid);
m_FieldMap[name].SetValue(es, uuid);
}
else
{
m_FieldMap[name].SetValue(es, r[name]);
}
}
r.Close();
}
if (migration)
else
{
// 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();
foreach (string name in FieldList)
{
if (m_FieldMap[name].GetValue(es) is bool)
{
if ((bool)m_FieldMap[name].GetValue(es))
cmd.Parameters.AddWithValue("?" + name, "1");
else
cmd.Parameters.AddWithValue("?" + name, "0");
}
else
{
cmd.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString());
}
}
cmd.ExecuteNonQuery();
cmd.CommandText = "select LAST_INSERT_ID() as id";
cmd.Parameters.Clear();
using (IDataReader r = cmd.ExecuteReader())
{
r.Read();
es.EstateID = Convert.ToUInt32(r["id"]);
}
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) { }
// 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) { }
es.Save();
}
}
LoadBanList(es);
es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers");
es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users");
es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups");
return es;
}
public void StoreEstateSettings(EstateSettings es)
{
string sql = "replace into estate_settings (" + String.Join(",", FieldList) + ") values ( ?" + String.Join(", ?", FieldList) + ")";
CheckConnection();
using (MySqlCommand cmd = m_connection.CreateCommand())
{
cmd.CommandText = sql;
cmd.Parameters.Clear();
foreach (string name in FieldList)
{
@ -276,8 +211,83 @@ namespace OpenSim.Data.MySQL
}
cmd.ExecuteNonQuery();
cmd.CommandText = "select LAST_INSERT_ID() as id";
cmd.Parameters.Clear();
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)
{
}
// 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)
{
}
es.Save();
}
LoadBanList(es);
es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers");
es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users");
es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups");
return es;
}
public void StoreEstateSettings(EstateSettings es)
{
string sql = "replace into estate_settings (" + String.Join(",", FieldList) + ") values ( ?" + String.Join(", ?", FieldList) + ")";
CheckConnection();
MySqlCommand cmd = m_connection.CreateCommand();
cmd.CommandText = sql;
foreach (string name in FieldList)
{
if (m_FieldMap[name].GetValue(es) is bool)
{
if ((bool)m_FieldMap[name].GetValue(es))
cmd.Parameters.AddWithValue("?" + name, "1");
else
cmd.Parameters.AddWithValue("?" + name, "0");
}
else
{
cmd.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString());
}
}
cmd.ExecuteNonQuery();
SaveBanList(es);
SaveUUIDList(es.EstateID, "estate_managers", es.EstateManagers);
SaveUUIDList(es.EstateID, "estate_users", es.EstateAccess);
@ -290,52 +300,50 @@ namespace OpenSim.Data.MySQL
CheckConnection();
using (MySqlCommand cmd = m_connection.CreateCommand())
MySqlCommand cmd = m_connection.CreateCommand();
cmd.CommandText = "select bannedUUID from estateban where EstateID = ?EstateID";
cmd.Parameters.AddWithValue("?EstateID", es.EstateID);
IDataReader r = cmd.ExecuteReader();
while (r.Read())
{
cmd.CommandText = "select bannedUUID from estateban where EstateID = ?EstateID";
cmd.Parameters.AddWithValue("?EstateID", es.EstateID);
EstateBan eb = new EstateBan();
using (IDataReader r = cmd.ExecuteReader())
{
while (r.Read())
{
EstateBan eb = new EstateBan();
UUID uuid = new UUID();
UUID.TryParse(r["bannedUUID"].ToString(), out uuid);
UUID uuid = new UUID();
UUID.TryParse(r["bannedUUID"].ToString(), out uuid);
eb.BannedUserID = uuid;
eb.BannedHostAddress = "0.0.0.0";
eb.BannedHostIPMask = "0.0.0.0";
es.AddBan(eb);
}
}
eb.BannedUserID = uuid;
eb.BannedHostAddress = "0.0.0.0";
eb.BannedHostIPMask = "0.0.0.0";
es.AddBan(eb);
}
r.Close();
}
private void SaveBanList(EstateSettings es)
{
CheckConnection();
using (MySqlCommand cmd = m_connection.CreateCommand())
MySqlCommand cmd = m_connection.CreateCommand();
cmd.CommandText = "delete from estateban where EstateID = ?EstateID";
cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString());
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
cmd.CommandText = "insert into estateban (EstateID, bannedUUID, bannedIp, bannedIpHostMask, bannedNameMask) values ( ?EstateID, ?bannedUUID, '', '', '' )";
foreach (EstateBan b in es.EstateBans)
{
cmd.CommandText = "delete from estateban where EstateID = ?EstateID";
cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString());
cmd.Parameters.AddWithValue("?bannedUUID", b.BannedUserID.ToString());
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
cmd.CommandText = "insert into estateban (EstateID, bannedUUID, bannedIp, bannedIpHostMask, bannedNameMask) values ( ?EstateID, ?bannedUUID, '', '', '' )";
foreach (EstateBan b in es.EstateBans)
{
cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString());
cmd.Parameters.AddWithValue("?bannedUUID", b.BannedUserID.ToString());
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
}
}
}
@ -343,25 +351,24 @@ namespace OpenSim.Data.MySQL
{
CheckConnection();
using (MySqlCommand cmd = m_connection.CreateCommand())
MySqlCommand cmd = m_connection.CreateCommand();
cmd.CommandText = "delete from " + table + " where EstateID = ?EstateID";
cmd.Parameters.AddWithValue("?EstateID", EstateID.ToString());
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
cmd.CommandText = "insert into " + table + " (EstateID, uuid) values ( ?EstateID, ?uuid )";
foreach (UUID uuid in data)
{
cmd.CommandText = "delete from " + table + " where EstateID = ?EstateID";
cmd.Parameters.AddWithValue("?EstateID", EstateID.ToString());
cmd.Parameters.AddWithValue("?uuid", uuid.ToString());
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
cmd.CommandText = "insert into " + table + " (EstateID, uuid) values ( ?EstateID, ?uuid )";
foreach (UUID uuid in data)
{
cmd.Parameters.AddWithValue("?EstateID", EstateID.ToString());
cmd.Parameters.AddWithValue("?uuid", uuid.ToString());
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
}
}
}
@ -371,24 +378,23 @@ namespace OpenSim.Data.MySQL
CheckConnection();
using (MySqlCommand cmd = m_connection.CreateCommand())
MySqlCommand cmd = m_connection.CreateCommand();
cmd.CommandText = "select uuid from " + table + " where EstateID = ?EstateID";
cmd.Parameters.AddWithValue("?EstateID", EstateID);
IDataReader r = cmd.ExecuteReader();
while (r.Read())
{
cmd.CommandText = "select uuid from " + table + " where EstateID = ?EstateID";
cmd.Parameters.AddWithValue("?EstateID", EstateID);
// EstateBan eb = new EstateBan();
using (IDataReader r = cmd.ExecuteReader())
{
while (r.Read())
{
// EstateBan eb = new EstateBan();
UUID uuid = new UUID();
UUID.TryParse(r["uuid"].ToString(), out uuid);
UUID uuid = new UUID();
UUID.TryParse(r["uuid"].ToString(), out uuid);
uuids.Add(uuid);
}
}
uuids.Add(uuid);
}
r.Close();
return uuids.ToArray();
}

View File

@ -40,10 +40,6 @@ 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)
@ -73,11 +69,12 @@ namespace OpenSim.Data.MySQL
}
catch (MySqlException e)
{
m_log.Error(e.Message, e);
Console.WriteLine(e.ToString());
if (errorSeen)
throw;
// This is "Server has gone away" and "Server lost"
//
if (e.Number == 2006 || e.Number == 2013)
{
errorSeen = true;
@ -96,7 +93,7 @@ namespace OpenSim.Data.MySQL
}
catch (Exception e)
{
m_log.Error(e.Message, e);
Console.WriteLine(e.ToString());
return 0;
}
}
@ -113,11 +110,11 @@ namespace OpenSim.Data.MySQL
return cmd.ExecuteReader();
}
protected void CloseDBConnection(IDataReader reader, MySqlCommand cmd)
protected void CloseReaderCommand(MySqlCommand cmd)
{
reader.Close();
cmd.Connection.Close();
cmd.Connection.Dispose();
cmd.Dispose();
}
}
}

View File

@ -197,27 +197,29 @@ namespace OpenSim.Data.MySQL
param["?xmax"] = xmax.ToString();
param["?ymax"] = ymax.ToString();
using (IDbCommand result = dbm.Manager.Query(
IDbCommand result =
dbm.Manager.Query(
"SELECT * FROM regions WHERE locX >= ?xmin AND locX <= ?xmax AND locY >= ?ymin AND locY <= ?ymax",
param))
param);
IDataReader reader = result.ExecuteReader();
RegionProfileData row;
List<RegionProfileData> rows = new List<RegionProfileData>();
while ((row = dbm.Manager.readSimRow(reader)) != null)
{
using (IDataReader reader = result.ExecuteReader())
{
RegionProfileData row;
List<RegionProfileData> rows = new List<RegionProfileData>();
while ((row = dbm.Manager.readSimRow(reader)) != null)
rows.Add(row);
return rows.ToArray();
}
rows.Add(row);
}
reader.Close();
result.Dispose();
return rows.ToArray();
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
return null;
}
finally
@ -241,27 +243,29 @@ namespace OpenSim.Data.MySQL
Dictionary<string, object> param = new Dictionary<string, object>();
param["?name"] = namePrefix + "%";
using (IDbCommand result = dbm.Manager.Query(
"SELECT * FROM regions WHERE regionName LIKE ?name",
param))
IDbCommand result =
dbm.Manager.Query(
"SELECT * FROM regions WHERE regionName LIKE ?name",
param);
IDataReader reader = result.ExecuteReader();
RegionProfileData row;
List<RegionProfileData> rows = new List<RegionProfileData>();
while (rows.Count < maxNum && (row = dbm.Manager.readSimRow(reader)) != null)
{
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);
return rows;
}
rows.Add(row);
}
reader.Close();
result.Dispose();
return rows;
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
return null;
}
finally
@ -282,21 +286,21 @@ namespace OpenSim.Data.MySQL
try
{
Dictionary<string, object> param = new Dictionary<string, object>();
param["?handle"] = handle.ToString();
param["?handle"] = handle.ToString();
using (IDbCommand result = dbm.Manager.Query("SELECT * FROM regions WHERE regionHandle = ?handle", param))
{
using (IDataReader reader = result.ExecuteReader())
{
RegionProfileData row = dbm.Manager.readSimRow(reader);
return row;
}
IDbCommand result = dbm.Manager.Query("SELECT * FROM regions WHERE regionHandle = ?handle", param);
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.Message, e);
m_log.Error(e.ToString());
return null;
}
finally
@ -317,24 +321,23 @@ namespace OpenSim.Data.MySQL
try
{
Dictionary<string, object> param = new Dictionary<string, object>();
param["?uuid"] = uuid.ToString();
param["?uuid"] = uuid.ToString();
using (IDbCommand result = dbm.Manager.Query("SELECT * FROM regions WHERE uuid = ?uuid", param))
{
using (IDataReader reader = result.ExecuteReader())
{
RegionProfileData row = dbm.Manager.readSimRow(reader);
return row;
}
IDbCommand result = dbm.Manager.Query("SELECT * FROM regions WHERE uuid = ?uuid", param);
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.Message, e);
m_log.Error(e.ToString());
return null;
}
finally
} finally
{
dbm.Release();
}
@ -356,21 +359,22 @@ 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.
using (IDbCommand result = dbm.Manager.Query(
"SELECT * FROM regions WHERE regionName like ?regionName order by LENGTH(regionName) asc LIMIT 1",
param))
{
using (IDataReader reader = result.ExecuteReader())
{
RegionProfileData row = dbm.Manager.readSimRow(reader);
return row;
}
}
IDbCommand result =
dbm.Manager.Query(
"SELECT * FROM regions WHERE regionName like ?regionName order by LENGTH(regionName) asc LIMIT 1",
param);
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.Message, e);
m_log.Error(e.ToString());
return null;
}
finally
@ -378,7 +382,6 @@ namespace OpenSim.Data.MySQL
dbm.Release();
}
}
m_log.Error("[GRID DB]: Searched for a Region Name shorter then 3 characters");
return null;
}
@ -391,12 +394,12 @@ namespace OpenSim.Data.MySQL
override public DataResponse StoreProfile(RegionProfileData profile)
{
MySQLSuperManager dbm = GetLockedConnection();
try
{
try {
if (dbm.Manager.insertRegion(profile))
{
return DataResponse.RESPONSE_OK;
else
return DataResponse.RESPONSE_ERROR;
}
return DataResponse.RESPONSE_ERROR;
}
finally
{
@ -414,14 +417,14 @@ namespace OpenSim.Data.MySQL
{
MySQLSuperManager dbm = GetLockedConnection();
try
{
try {
if (dbm.Manager.deleteRegion(uuid))
{
return DataResponse.RESPONSE_OK;
else
return DataResponse.RESPONSE_ERROR;
}
finally
}
return DataResponse.RESPONSE_ERROR;
} finally
{
dbm.Release();
}
@ -479,26 +482,26 @@ namespace OpenSim.Data.MySQL
try
{
Dictionary<string, object> param = new Dictionary<string, object>();
param["?x"] = x.ToString();
param["?y"] = y.ToString();
using (IDbCommand result = dbm.Manager.Query(
"SELECT * FROM reservations WHERE resXMin <= ?x AND resXMax >= ?x AND resYMin <= ?y AND resYMax >= ?y",
param))
{
using (IDataReader reader = result.ExecuteReader())
{
ReservationData row = dbm.Manager.readReservationRow(reader);
return row;
}
}
param["?x"] = x.ToString();
param["?y"] = y.ToString();
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();
ReservationData row = dbm.Manager.readReservationRow(reader);
reader.Close();
result.Dispose();
return row;
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
return null;
}
finally
} finally
{
dbm.Release();
}

View File

@ -135,30 +135,30 @@ namespace OpenSim.Data.MySQL
database.CheckConnection();
using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE parentFolderID = ?uuid",
database.Connection))
MySqlCommand result =
new MySqlCommand("SELECT * FROM inventoryitems WHERE parentFolderID = ?uuid",
database.Connection);
result.Parameters.AddWithValue("?uuid", folderID.ToString());
MySqlDataReader reader = result.ExecuteReader();
while (reader.Read())
{
result.Parameters.AddWithValue("?uuid", folderID.ToString());
using (MySqlDataReader reader = result.ExecuteReader())
{
while (reader.Read())
{
// A null item (because something went wrong) breaks everything in the folder
InventoryItemBase item = readInventoryItem(reader);
if (item != null)
items.Add(item);
}
return items;
}
// A null item (because something went wrong) breaks everything in the folder
InventoryItemBase item = readInventoryItem(reader);
if (item != null)
items.Add(item);
}
reader.Close();
result.Dispose();
return items;
}
}
catch (Exception e)
{
database.Reconnect();
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
return null;
}
}
@ -176,28 +176,29 @@ namespace OpenSim.Data.MySQL
{
database.CheckConnection();
using (MySqlCommand result = new MySqlCommand(
"SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid",
database.Connection))
{
result.Parameters.AddWithValue("?uuid", user.ToString());
result.Parameters.AddWithValue("?zero", UUID.Zero.ToString());
MySqlCommand result =
new MySqlCommand(
"SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid",
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));
List<InventoryFolderBase> items = new List<InventoryFolderBase>();
while (reader.Read())
items.Add(readInventoryFolder(reader));
return items;
}
}
reader.Close();
result.Dispose();
return items;
}
}
catch (Exception e)
{
database.Reconnect();
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
return null;
}
}
@ -216,38 +217,41 @@ namespace OpenSim.Data.MySQL
{
database.CheckConnection();
using (MySqlCommand result = new MySqlCommand(
"SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid",
database.Connection))
MySqlCommand result =
new MySqlCommand(
"SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid",
database.Connection);
result.Parameters.AddWithValue("?uuid", user.ToString());
result.Parameters.AddWithValue("?zero", UUID.Zero.ToString());
MySqlDataReader reader = result.ExecuteReader();
List<InventoryFolderBase> items = new List<InventoryFolderBase>();
while (reader.Read())
items.Add(readInventoryFolder(reader));
InventoryFolderBase rootFolder = null;
// There should only ever be one root folder for a user. However, if there's more
// than one we'll simply use the first one rather than failing. It would be even
// nicer to print some message to this effect, but this feels like it's too low a
// to put such a message out, and it's too minor right now to spare the time to
// suitably refactor.
if (items.Count > 0)
{
result.Parameters.AddWithValue("?uuid", user.ToString());
result.Parameters.AddWithValue("?zero", UUID.Zero.ToString());
using (MySqlDataReader reader = result.ExecuteReader())
{
List<InventoryFolderBase> items = new List<InventoryFolderBase>();
while (reader.Read())
items.Add(readInventoryFolder(reader));
InventoryFolderBase rootFolder = null;
// There should only ever be one root folder for a user. However, if there's more
// than one we'll simply use the first one rather than failing. It would be even
// nicer to print some message to this effect, but this feels like it's too low a
// 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];
return rootFolder;
}
rootFolder = items[0];
}
reader.Close();
result.Dispose();
return rootFolder;
}
}
catch (Exception e)
{
database.Reconnect();
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
return null;
}
}
@ -267,26 +271,27 @@ namespace OpenSim.Data.MySQL
{
database.CheckConnection();
using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?uuid",
database.Connection))
{
result.Parameters.AddWithValue("?uuid", parentID.ToString());
using (MySqlDataReader reader = result.ExecuteReader())
{
List<InventoryFolderBase> items = new List<InventoryFolderBase>();
MySqlCommand result =
new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?uuid",
database.Connection);
result.Parameters.AddWithValue("?uuid", parentID.ToString());
MySqlDataReader reader = result.ExecuteReader();
while (reader.Read())
items.Add(readInventoryFolder(reader));
List<InventoryFolderBase> items = new List<InventoryFolderBase>();
return items;
}
}
while (reader.Read())
items.Add(readInventoryFolder(reader));
reader.Close();
result.Dispose();
return items;
}
}
catch (Exception e)
{
database.Reconnect();
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
return null;
}
}
@ -365,25 +370,25 @@ namespace OpenSim.Data.MySQL
{
database.CheckConnection();
using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE inventoryID = ?uuid", database.Connection))
{
result.Parameters.AddWithValue("?uuid", itemID.ToString());
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);
InventoryItemBase item = null;
if (reader.Read())
item = readInventoryItem(reader);
return item;
}
}
reader.Close();
result.Dispose();
return item;
}
}
catch (Exception e)
{
database.Reconnect();
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
}
return null;
}
@ -408,7 +413,7 @@ namespace OpenSim.Data.MySQL
}
catch (Exception e)
{
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
}
return null;
@ -428,25 +433,24 @@ namespace OpenSim.Data.MySQL
{
database.CheckConnection();
using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", database.Connection))
{
result.Parameters.AddWithValue("?uuid", folderID.ToString());
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);
InventoryFolderBase folder = null;
if (reader.Read())
folder = readInventoryFolder(reader);
reader.Close();
result.Dispose();
return folder;
}
}
return folder;
}
}
catch (Exception e)
{
database.Reconnect();
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
return null;
}
}
@ -694,73 +698,69 @@ 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>();
bool buildResultsFromHashTable = false;
lock (database)
{
MySqlCommand result;
MySqlDataReader reader;
bool buildResultsFromHashTable = false;
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 */
using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", database.Connection))
{
result.Parameters.AddWithValue("?uuid", parentID.ToString());
using (MySqlDataReader reader = result.ExecuteReader())
{
// Should be at most 1 result
while (reader.Read())
parentFolder.Add(readInventoryFolder(reader));
}
}
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
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 */
using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE agentID = ?uuid", database.Connection))
result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE agentID = ?uuid",
database.Connection);
result.Parameters.AddWithValue("?uuid", parentFolder[0].Owner.ToString());
reader = result.ExecuteReader();
while (reader.Read())
{
result.Parameters.AddWithValue("?uuid", parentFolder[0].Owner.ToString());
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);
}
}
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 */
using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE agentID = ?uuid", database.Connection))
result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE agentID = ?uuid",
database.Connection);
result.Parameters.AddWithValue("?uuid", parentFolder[0].Owner.ToString());
reader = result.ExecuteReader();
while (reader.Read())
{
result.Parameters.AddWithValue("?uuid", parentFolder[0].Owner.ToString());
using (MySqlDataReader reader = result.ExecuteReader())
InventoryFolderBase curFolder = readInventoryFolder(reader);
if (hashtable.ContainsKey(curFolder.ParentID)) // Current folder already has a sibling
hashtable[curFolder.ParentID].Add(curFolder); // append to sibling list
else // else current folder has no known (yet) siblings
{
while (reader.Read())
{
InventoryFolderBase curFolder = readInventoryFolder(reader);
if (hashtable.ContainsKey(curFolder.ParentID)) // Current folder already has a sibling
hashtable[curFolder.ParentID].Add(curFolder); // append to sibling list
else // else current folder has no known (yet) siblings
{
List<InventoryFolderBase> siblingList = new List<InventoryFolderBase>();
siblingList.Add(curFolder);
// Current folder has no known (yet) siblings
hashtable.Add(curFolder.ParentID, siblingList);
}
} // while more items to read from the database
List<InventoryFolderBase> siblingList = new List<InventoryFolderBase>();
siblingList.Add(curFolder);
// Current folder has no known (yet) siblings
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,13 +781,12 @@ namespace OpenSim.Data.MySQL
folders.AddRange(hashtable[folders[i].ID]);
}
} // lock (database)
return folders;
}
catch (Exception e)
{
database.Reconnect();
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
return null;
}
}
@ -802,18 +801,19 @@ namespace OpenSim.Data.MySQL
{
database.CheckConnection();
using (MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryfolders WHERE folderID=?uuid", database.Connection))
{
cmd.Parameters.AddWithValue("?uuid", folderID.ToString());
MySqlCommand cmd =
new MySqlCommand("DELETE FROM inventoryfolders WHERE folderID=?uuid", database.Connection);
cmd.Parameters.AddWithValue("?uuid", folderID.ToString());
lock (database)
cmd.ExecuteNonQuery();
lock (database)
{
cmd.ExecuteNonQuery();
}
}
catch (MySqlException e)
{
database.Reconnect();
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
}
}
@ -827,12 +827,13 @@ namespace OpenSim.Data.MySQL
{
database.CheckConnection();
using (MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryitems WHERE parentFolderID=?uuid", database.Connection))
{
cmd.Parameters.AddWithValue("?uuid", folderID.ToString());
MySqlCommand cmd =
new MySqlCommand("DELETE FROM inventoryitems WHERE parentFolderID=?uuid", database.Connection);
cmd.Parameters.AddWithValue("?uuid", folderID.ToString());
lock (database)
cmd.ExecuteNonQuery();
lock (database)
{
cmd.ExecuteNonQuery();
}
}
catch (MySqlException e)
@ -864,38 +865,40 @@ namespace OpenSim.Data.MySQL
public List<InventoryItemBase> fetchActiveGestures(UUID avatarID)
{
MySqlDataReader result = null;
MySqlCommand sqlCmd = null;
lock (database)
{
try
{
database.CheckConnection();
using (MySqlCommand sqlCmd = new MySqlCommand(
sqlCmd = new MySqlCommand(
"SELECT * FROM inventoryitems WHERE avatarId = ?uuid AND assetType = ?type and flags = 1",
database.Connection))
{
sqlCmd.Parameters.AddWithValue("?uuid", avatarID.ToString());
sqlCmd.Parameters.AddWithValue("?type", (int)AssetType.Gesture);
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())
{
InventoryItemBase item = readInventoryItem(result);
if (item != null)
list.Add(item);
}
return list;
}
List<InventoryItemBase> list = new List<InventoryItemBase>();
while (result.Read())
{
InventoryItemBase item = readInventoryItem(result);
if (item != null)
list.Add(item);
}
return list;
}
catch (Exception e)
{
database.Reconnect();
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
return null;
}
finally
{
if (result != null) result.Close();
if (sqlCmd != null) sqlCmd.Dispose();
}
}
}
}

View File

@ -134,16 +134,18 @@ namespace OpenSim.Data.MySQL
/// </summary>
protected void GetWaitTimeout()
{
using (MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect, dbcon))
MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect, dbcon);
using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
{
using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
if (dbReader.Read())
{
if (dbReader.Read())
{
m_waitTimeout
= Convert.ToInt32(dbReader["@@wait_timeout"]) * TimeSpan.TicksPerSecond + m_waitTimeoutLeeway;
}
m_waitTimeout
= Convert.ToInt32(dbReader["@@wait_timeout"]) * TimeSpan.TicksPerSecond + m_waitTimeoutLeeway;
}
dbReader.Close();
cmd.Dispose();
}
m_lastConnectionUse = DateTime.Now.Ticks;
@ -301,31 +303,31 @@ namespace OpenSim.Data.MySQL
{
CheckConnection();
using (MySqlCommand tablesCmd = new MySqlCommand(
"SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=?dbname",
dbcon))
{
tablesCmd.Parameters.AddWithValue("?dbname", dbcon.Database);
MySqlCommand tablesCmd =
new MySqlCommand(
"SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=?dbname",
dbcon);
tablesCmd.Parameters.AddWithValue("?dbname", dbcon.Database);
using (MySqlDataReader tables = tablesCmd.ExecuteReader())
using (MySqlDataReader tables = tablesCmd.ExecuteReader())
{
while (tables.Read())
{
while (tables.Read())
try
{
try
string tableName = (string) tables["TABLE_NAME"];
string comment = (string) tables["TABLE_COMMENT"];
if (tableList.ContainsKey(tableName))
{
string tableName = (string)tables["TABLE_NAME"];
string comment = (string)tables["TABLE_COMMENT"];
if (tableList.ContainsKey(tableName))
{
tableList[tableName] = comment;
}
}
catch (Exception e)
{
m_log.Error(e.Message, e);
tableList[tableName] = comment;
}
}
catch (Exception e)
{
m_log.Error(e.ToString());
}
}
tables.Close();
}
}
}
@ -344,19 +346,19 @@ namespace OpenSim.Data.MySQL
{
CheckConnection(); // Not sure if this one is necessary
MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand();
MySqlCommand dbcommand = (MySqlCommand) dbcon.CreateCommand();
dbcommand.CommandText = sql;
foreach (KeyValuePair<string, object> param in parameters)
{
dbcommand.Parameters.AddWithValue(param.Key, param.Value);
}
return (IDbCommand)dbcommand;
return (IDbCommand) dbcommand;
}
catch (Exception e)
{
// Return null if it fails.
m_log.Error("Failed during Query generation: " + e.Message, e);
m_log.Error("Failed during Query generation: " + e.ToString());
return null;
}
}
@ -692,6 +694,8 @@ namespace OpenSim.Data.MySQL
ret.Add(attachpoint, item);
}
r.Close();
return ret;
}

View File

@ -56,13 +56,12 @@ namespace OpenSim.Data.MySQL
if (scopeID != UUID.Zero)
command += " and ScopeID = ?scopeID";
using (MySqlCommand cmd = new MySqlCommand(command))
{
cmd.Parameters.AddWithValue("?regionName", regionName);
cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
MySqlCommand cmd = new MySqlCommand(command);
return RunCommand(cmd);
}
cmd.Parameters.AddWithValue("?regionName", regionName);
cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
return RunCommand(cmd);
}
public RegionData Get(int posX, int posY, UUID scopeID)
@ -71,18 +70,17 @@ namespace OpenSim.Data.MySQL
if (scopeID != UUID.Zero)
command += " and ScopeID = ?scopeID";
using (MySqlCommand cmd = new MySqlCommand(command))
{
cmd.Parameters.AddWithValue("?posX", posX.ToString());
cmd.Parameters.AddWithValue("?posY", posY.ToString());
cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
MySqlCommand cmd = new MySqlCommand(command);
List<RegionData> ret = RunCommand(cmd);
if (ret.Count == 0)
return null;
cmd.Parameters.AddWithValue("?posX", posX.ToString());
cmd.Parameters.AddWithValue("?posY", posY.ToString());
cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
return ret[0];
}
List<RegionData> ret = RunCommand(cmd);
if (ret.Count == 0)
return null;
return ret[0];
}
public RegionData Get(UUID regionID, UUID scopeID)
@ -91,17 +89,16 @@ namespace OpenSim.Data.MySQL
if (scopeID != UUID.Zero)
command += " and ScopeID = ?scopeID";
using (MySqlCommand cmd = new MySqlCommand(command))
{
cmd.Parameters.AddWithValue("?regionID", regionID.ToString());
cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
MySqlCommand cmd = new MySqlCommand(command);
List<RegionData> ret = RunCommand(cmd);
if (ret.Count == 0)
return null;
cmd.Parameters.AddWithValue("?regionID", regionID.ToString());
cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
return ret[0];
}
List<RegionData> ret = RunCommand(cmd);
if (ret.Count == 0)
return null;
return ret[0];
}
public List<RegionData> Get(int startX, int startY, int endX, int endY, UUID scopeID)
@ -110,44 +107,43 @@ namespace OpenSim.Data.MySQL
if (scopeID != UUID.Zero)
command += " and ScopeID = ?scopeID";
using (MySqlCommand cmd = new MySqlCommand(command))
{
cmd.Parameters.AddWithValue("?startX", startX.ToString());
cmd.Parameters.AddWithValue("?startY", startY.ToString());
cmd.Parameters.AddWithValue("?endX", endX.ToString());
cmd.Parameters.AddWithValue("?endY", endY.ToString());
cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
MySqlCommand cmd = new MySqlCommand(command);
return RunCommand(cmd);
}
cmd.Parameters.AddWithValue("?startX", startX.ToString());
cmd.Parameters.AddWithValue("?startY", startY.ToString());
cmd.Parameters.AddWithValue("?endX", endX.ToString());
cmd.Parameters.AddWithValue("?endY", endY.ToString());
cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
return RunCommand(cmd);
}
public List<RegionData> RunCommand(MySqlCommand cmd)
{
List<RegionData> retList = new List<RegionData>();
using (IDataReader result = ExecuteReader(cmd))
IDataReader result = ExecuteReader(cmd);
while (result.Read())
{
while (result.Read())
RegionData ret = new RegionData();
ret.Data = new Dictionary<string, object>();
UUID regionID;
UUID.TryParse(result["uuid"].ToString(), out regionID);
ret.RegionID = regionID;
UUID scope;
UUID.TryParse(result["ScopeID"].ToString(), out scope);
ret.ScopeID = scope;
ret.RegionName = result["regionName"].ToString();
ret.posX = Convert.ToInt32(result["locX"]);
ret.posY = Convert.ToInt32(result["locY"]);
ret.sizeX = Convert.ToInt32(result["sizeX"]);
ret.sizeY = Convert.ToInt32(result["sizeY"]);
if (m_ColumnNames == null)
{
RegionData ret = new RegionData();
ret.Data = new Dictionary<string, object>();
UUID regionID;
UUID.TryParse(result["uuid"].ToString(), out regionID);
ret.RegionID = regionID;
UUID scope;
UUID.TryParse(result["ScopeID"].ToString(), out scope);
ret.ScopeID = scope;
ret.RegionName = result["regionName"].ToString();
ret.posX = Convert.ToInt32(result["locX"]);
ret.posY = Convert.ToInt32(result["locY"]);
ret.sizeX = Convert.ToInt32(result["sizeX"]);
ret.sizeY = Convert.ToInt32(result["sizeY"]);
if (m_ColumnNames == null)
{
m_ColumnNames = new List<string>();
m_ColumnNames = new List<string>();
DataTable schemaTable = result.GetSchemaTable();
foreach (DataRow row in schemaTable.Rows)
@ -157,28 +153,28 @@ namespace OpenSim.Data.MySQL
}
}
foreach (string s in m_ColumnNames)
{
if (s == "uuid")
continue;
if (s == "ScopeID")
continue;
if (s == "regionName")
continue;
if (s == "locX")
continue;
if (s == "locY")
continue;
foreach (string s in m_ColumnNames)
{
if (s == "uuid")
continue;
if (s == "ScopeID")
continue;
if (s == "regionName")
continue;
if (s == "locX")
continue;
if (s == "locY")
continue;
ret.Data[s] = result[s].ToString();
}
retList.Add(ret);
ret.Data[s] = result[s].ToString();
}
CloseDBConnection(result, cmd);
retList.Add(ret);
}
result.Close();
CloseReaderCommand(cmd);
return retList;
}
@ -205,72 +201,76 @@ namespace OpenSim.Data.MySQL
string[] fields = new List<string>(data.Data.Keys).ToArray();
using (MySqlCommand cmd = new MySqlCommand())
MySqlCommand cmd = new MySqlCommand();
string update = "update `"+m_Realm+"` set locX=?posX, locY=?posY, sizeX=?sizeX, sizeY=?sizeY";
foreach (string field in fields)
{
string update = "update `" + m_Realm + "` set locX=?posX, locY=?posY, sizeX=?sizeX, sizeY=?sizeY";
foreach (string field in fields)
{
update += ", ";
update += "`" + field + "` = ?" + field;
update += ", ";
update += "`" + field + "` = ?"+field;
cmd.Parameters.AddWithValue("?" + field, data.Data[field]);
}
cmd.Parameters.AddWithValue("?"+field, data.Data[field]);
}
update += " where uuid = ?regionID";
update += " where uuid = ?regionID";
if (data.ScopeID != UUID.Zero)
update += " and ScopeID = ?scopeID";
if (data.ScopeID != UUID.Zero)
update += " and ScopeID = ?scopeID";
cmd.CommandText = update;
cmd.Parameters.AddWithValue("?regionID", data.RegionID.ToString());
cmd.Parameters.AddWithValue("?regionName", data.RegionName);
cmd.Parameters.AddWithValue("?scopeID", data.ScopeID.ToString());
cmd.Parameters.AddWithValue("?posX", data.posX.ToString());
cmd.Parameters.AddWithValue("?posY", data.posY.ToString());
cmd.Parameters.AddWithValue("?sizeX", data.sizeX.ToString());
cmd.Parameters.AddWithValue("?sizeY", data.sizeY.ToString());
cmd.CommandText = update;
cmd.Parameters.AddWithValue("?regionID", data.RegionID.ToString());
cmd.Parameters.AddWithValue("?regionName", data.RegionName);
cmd.Parameters.AddWithValue("?scopeID", data.ScopeID.ToString());
cmd.Parameters.AddWithValue("?posX", data.posX.ToString());
cmd.Parameters.AddWithValue("?posY", data.posY.ToString());
cmd.Parameters.AddWithValue("?sizeX", data.sizeX.ToString());
cmd.Parameters.AddWithValue("?sizeY", data.sizeY.ToString());
if (ExecuteNonQuery(cmd) < 1)
{
string insert = "insert into `" + m_Realm + "` (`uuid`, `ScopeID`, `locX`, `locY`, `sizeX`, `sizeY`, `regionName`, `" +
String.Join("`, `", fields) +
"`) values ( ?regionID, ?scopeID, ?posX, ?posY, ?sizeX, ?sizeY, ?regionName, ?" + String.Join(", ?", fields) + ")";
cmd.CommandText = insert;
if (ExecuteNonQuery(cmd) < 1)
{
string insert = "insert into `" + m_Realm + "` (`uuid`, `ScopeID`, `locX`, `locY`, `sizeX`, `sizeY`, `regionName`, `" +
String.Join("`, `", fields) +
"`) values ( ?regionID, ?scopeID, ?posX, ?posY, ?sizeX, ?sizeY, ?regionName, ?" + String.Join(", ?", fields) + ")";
cmd.CommandText = insert;
if (ExecuteNonQuery(cmd) < 1)
{
return false;
}
cmd.Dispose();
return false;
}
}
cmd.Dispose();
return true;
}
public bool SetDataItem(UUID regionID, string item, string value)
{
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());
MySqlCommand cmd = new MySqlCommand("update `" + m_Realm +
"` set `" + item + "` = ?" + item + " where uuid = ?UUID");
if (ExecuteNonQuery(cmd) > 0)
return true;
}
cmd.Parameters.AddWithValue("?"+item, value);
cmd.Parameters.AddWithValue("?UUID", regionID.ToString());
if (ExecuteNonQuery(cmd) > 0)
return true;
return false;
}
public bool Delete(UUID regionID)
{
using (MySqlCommand cmd = new MySqlCommand("delete from `" + m_Realm + "` where uuid = ?UUID"))
{
cmd.Parameters.AddWithValue("?UUID", regionID.ToString());
MySqlCommand cmd = new MySqlCommand("delete from `" + m_Realm +
"` where uuid = ?UUID");
if (ExecuteNonQuery(cmd) > 0)
return true;
}
cmd.Parameters.AddWithValue("?UUID", regionID.ToString());
if (ExecuteNonQuery(cmd) > 0)
return true;
return false;
}

View File

@ -97,14 +97,16 @@ namespace OpenSim.Data.MySQL
ret.Data[s] = result[s].ToString();
}
CloseDBConnection(result, cmd);
result.Close();
CloseReaderCommand(cmd);
return ret;
}
else
{
CloseDBConnection(result, cmd);
return null;
}
result.Close();
CloseReaderCommand(cmd);
return null;
}
public bool Store(UserAccountData data)
@ -116,60 +118,61 @@ namespace OpenSim.Data.MySQL
string[] fields = new List<string>(data.Data.Keys).ToArray();
using (MySqlCommand cmd = new MySqlCommand())
MySqlCommand cmd = new MySqlCommand();
string update = "update `"+m_Realm+"` set ";
bool first = true;
foreach (string field in fields)
{
string update = "update `" + m_Realm + "` set ";
bool first = true;
foreach (string field in fields)
{
if (!first)
update += ", ";
update += "`" + field + "` = ?" + field;
if (!first)
update += ", ";
update += "`" + field + "` = ?"+field;
first = false;
first = false;
cmd.Parameters.AddWithValue("?" + field, data.Data[field]);
}
cmd.Parameters.AddWithValue("?"+field, data.Data[field]);
}
update += " where UUID = ?principalID";
update += " where UUID = ?principalID";
if (data.ScopeID != UUID.Zero)
update += " and ScopeID = ?scopeID";
if (data.ScopeID != UUID.Zero)
update += " and ScopeID = ?scopeID";
cmd.CommandText = update;
cmd.Parameters.AddWithValue("?principalID", data.PrincipalID.ToString());
cmd.Parameters.AddWithValue("?scopeID", data.ScopeID.ToString());
cmd.CommandText = update;
cmd.Parameters.AddWithValue("?principalID", data.PrincipalID.ToString());
cmd.Parameters.AddWithValue("?scopeID", data.ScopeID.ToString());
if (ExecuteNonQuery(cmd) < 1)
{
string insert = "insert into `" + m_Realm + "` (`UUID`, `ScopeID`, `" +
String.Join("`, `", fields) +
"`) values (?principalID, ?scopeID, ?" + String.Join(", ?", fields) + ")";
cmd.CommandText = insert;
if (ExecuteNonQuery(cmd) < 1)
{
string insert = "insert into `" + m_Realm + "` (`UUID`, `ScopeID`, `" +
String.Join("`, `", fields) +
"`) values (?principalID, ?scopeID, ?" + String.Join(", ?", fields) + ")";
cmd.CommandText = insert;
if (ExecuteNonQuery(cmd) < 1)
{
cmd.Dispose();
return false;
}
cmd.Dispose();
return false;
}
}
cmd.Dispose();
return true;
}
public bool SetDataItem(UUID principalID, string item, string value)
{
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());
MySqlCommand cmd = new MySqlCommand("update `" + m_Realm +
"` set `" + item + "` = ?" + item + " where UUID = ?UUID");
if (ExecuteNonQuery(cmd) > 0)
return true;
}
cmd.Parameters.AddWithValue("?"+item, value);
cmd.Parameters.AddWithValue("?UUID", principalID.ToString());
if (ExecuteNonQuery(cmd) > 0)
return true;
return false;
}

View File

@ -181,20 +181,21 @@ namespace OpenSim.Data.MySQL
param["?first"] = user;
param["?second"] = last;
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);
return row;
}
}
IDbCommand result =
dbm.Manager.Query(
"SELECT * FROM " + m_usersTableName + " WHERE username = ?first AND lastname = ?second", param);
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.Message, e);
m_log.Error(e.ToString());
return null;
}
finally
@ -219,30 +220,28 @@ namespace OpenSim.Data.MySQL
try
{
using (IDbCommand adder = dbm.Manager.Query(
"INSERT INTO `" + m_userFriendsTableName + "` " +
"(`ownerID`,`friendID`,`friendPerms`,`datetimestamp`) " +
"VALUES " +
"(?ownerID,?friendID,?friendPerms,?datetimestamp)",
param))
{
adder.ExecuteNonQuery();
}
IDbCommand adder =
dbm.Manager.Query(
"INSERT INTO `" + m_userFriendsTableName + "` " +
"(`ownerID`,`friendID`,`friendPerms`,`datetimestamp`) " +
"VALUES " +
"(?ownerID,?friendID,?friendPerms,?datetimestamp)",
param);
adder.ExecuteNonQuery();
using (IDbCommand adder = dbm.Manager.Query(
"INSERT INTO `" + m_userFriendsTableName + "` " +
"(`ownerID`,`friendID`,`friendPerms`,`datetimestamp`) " +
"VALUES " +
"(?friendID,?ownerID,?friendPerms,?datetimestamp)",
param))
{
adder.ExecuteNonQuery();
}
adder =
dbm.Manager.Query(
"INSERT INTO `" + m_userFriendsTableName + "` " +
"(`ownerID`,`friendID`,`friendPerms`,`datetimestamp`) " +
"VALUES " +
"(?friendID,?ownerID,?friendPerms,?datetimestamp)",
param);
adder.ExecuteNonQuery();
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
return;
}
finally
@ -261,24 +260,22 @@ namespace OpenSim.Data.MySQL
try
{
using (IDbCommand updater = dbm.Manager.Query(
IDbCommand updater =
dbm.Manager.Query(
"delete from " + m_userFriendsTableName + " where ownerID = ?ownerID and friendID = ?friendID",
param))
{
updater.ExecuteNonQuery();
}
param);
updater.ExecuteNonQuery();
using (IDbCommand updater = dbm.Manager.Query(
updater =
dbm.Manager.Query(
"delete from " + m_userFriendsTableName + " where ownerID = ?friendID and friendID = ?ownerID",
param))
{
updater.ExecuteNonQuery();
}
param);
updater.ExecuteNonQuery();
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
return;
}
finally
@ -298,19 +295,18 @@ namespace OpenSim.Data.MySQL
try
{
using (IDbCommand updater = dbm.Manager.Query(
IDbCommand updater =
dbm.Manager.Query(
"update " + m_userFriendsTableName +
" SET friendPerms = ?friendPerms " +
"where ownerID = ?ownerID and friendID = ?friendID",
param))
{
updater.ExecuteNonQuery();
}
param);
updater.ExecuteNonQuery();
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
return;
}
finally
@ -331,33 +327,34 @@ namespace OpenSim.Data.MySQL
try
{
//Left Join userfriends to itself
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))
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();
while (reader.Read())
{
using (IDataReader reader = result.ExecuteReader())
{
while (reader.Read())
{
FriendListItem fli = new FriendListItem();
fli.FriendListOwner = new UUID((string)reader["ownerID"]);
fli.Friend = new UUID((string)reader["friendID"]);
fli.FriendPerms = (uint)Convert.ToInt32(reader["friendPerms"]);
FriendListItem fli = new FriendListItem();
fli.FriendListOwner = new UUID((string) reader["ownerID"]);
fli.Friend = new UUID((string) reader["friendID"]);
fli.FriendPerms = (uint) Convert.ToInt32(reader["friendPerms"]);
// This is not a real column in the database table, it's a joined column from the opposite record
fli.FriendListOwnerPerms = (uint)Convert.ToInt32(reader["ownerperms"]);
// This is not a real column in the database table, it's a joined column from the opposite record
fli.FriendListOwnerPerms = (uint) Convert.ToInt32(reader["ownerperms"]);
Lfli.Add(fli);
}
}
Lfli.Add(fli);
}
reader.Dispose();
result.Dispose();
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
return Lfli;
}
finally
@ -379,29 +376,29 @@ 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);
using (IDbCommand result = dbm.Manager.Query("select agentOnline,currentHandle from " + m_agentsTableName +
" where UUID = ?uuid", param))
IDataReader reader = result.ExecuteReader();
while (reader.Read())
{
using (IDataReader reader = result.ExecuteReader())
{
while (reader.Read())
{
FriendRegionInfo fri = new FriendRegionInfo();
fri.isOnline = (sbyte)reader["agentOnline"] != 0;
fri.regionHandle = (ulong)reader["currentHandle"];
FriendRegionInfo fri = new FriendRegionInfo();
fri.isOnline = (sbyte)reader["agentOnline"] != 0;
fri.regionHandle = (ulong)reader["currentHandle"];
infos[uuid] = fri;
}
}
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.Message, e);
m_log.Error(e.ToString());
}
finally
{
@ -430,28 +427,28 @@ namespace OpenSim.Data.MySQL
try
{
using (IDbCommand result = dbm.Manager.Query(
"SELECT UUID,username,lastname FROM " + m_usersTableName +
" WHERE username like ?first AND lastname like ?second LIMIT 100",
param))
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();
while (reader.Read())
{
using (IDataReader reader = result.ExecuteReader())
{
while (reader.Read())
{
AvatarPickerAvatar user = new AvatarPickerAvatar();
user.AvatarID = new UUID((string)reader["UUID"]);
user.firstName = (string)reader["username"];
user.lastName = (string)reader["lastname"];
returnlist.Add(user);
}
}
AvatarPickerAvatar user = new AvatarPickerAvatar();
user.AvatarID = new UUID((string) reader["UUID"]);
user.firstName = (string) reader["username"];
user.lastName = (string) reader["lastname"];
returnlist.Add(user);
}
reader.Dispose();
result.Dispose();
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
return returnlist;
}
finally
@ -468,28 +465,28 @@ namespace OpenSim.Data.MySQL
Dictionary<string, object> param = new Dictionary<string, object>();
param["?first"] = objAlphaNumericPattern.Replace(querysplit[0], String.Empty) + "%";
using (IDbCommand result = dbm.Manager.Query(
"SELECT UUID,username,lastname FROM " + m_usersTableName +
" WHERE username like ?first OR lastname like ?first LIMIT 100",
param))
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();
while (reader.Read())
{
using (IDataReader reader = result.ExecuteReader())
{
while (reader.Read())
{
AvatarPickerAvatar user = new AvatarPickerAvatar();
user.AvatarID = new UUID((string)reader["UUID"]);
user.firstName = (string)reader["username"];
user.lastName = (string)reader["lastname"];
returnlist.Add(user);
}
}
AvatarPickerAvatar user = new AvatarPickerAvatar();
user.AvatarID = new UUID((string) reader["UUID"]);
user.firstName = (string) reader["username"];
user.lastName = (string) reader["lastname"];
returnlist.Add(user);
}
reader.Dispose();
result.Dispose();
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
return returnlist;
}
finally
@ -513,19 +510,20 @@ namespace OpenSim.Data.MySQL
Dictionary<string, object> param = new Dictionary<string, object>();
param["?uuid"] = uuid.ToString();
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);
return row;
}
}
IDbCommand result = dbm.Manager.Query("SELECT * FROM " + m_usersTableName + " WHERE UUID = ?uuid", param);
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.Message, e);
m_log.Error(e.ToString());
return null;
}
finally
@ -571,15 +569,15 @@ namespace OpenSim.Data.MySQL
try
{
dbm.Manager.ExecuteParameterizedSql(
"update " + m_usersTableName + " SET webLoginKey = ?webLoginKey " +
"where UUID = ?UUID",
param);
dbm.Manager.ExecuteParameterizedSql(
"update " + m_usersTableName + " SET webLoginKey = ?webLoginKey " +
"where UUID = ?UUID",
param);
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
return;
}
finally
@ -602,19 +600,21 @@ namespace OpenSim.Data.MySQL
Dictionary<string, object> param = new Dictionary<string, object>();
param["?uuid"] = uuid.ToString();
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);
return row;
}
}
IDbCommand result = dbm.Manager.Query("SELECT * FROM " + m_agentsTableName + " WHERE UUID = ?uuid",
param);
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.Message, e);
m_log.Error(e.ToString());
return null;
}
finally
@ -638,20 +638,19 @@ namespace OpenSim.Data.MySQL
try
{
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,
user.LastLogin, user.UserInventoryURI, user.UserAssetURI,
user.CanDoMask, user.WantDoMask,
user.AboutText, user.FirstLifeAboutText, user.Image,
user.FirstLifeImage, user.WebLoginKey, user.UserFlags, user.GodLevel, user.CustomType, user.Partner);
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,
user.LastLogin, user.UserInventoryURI, user.UserAssetURI,
user.CanDoMask, user.WantDoMask,
user.AboutText, user.FirstLifeAboutText, user.Image,
user.FirstLifeImage, user.WebLoginKey, user.UserFlags, user.GodLevel, user.CustomType, user.Partner);
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
}
finally
{
@ -677,7 +676,7 @@ namespace OpenSim.Data.MySQL
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
}
finally
{
@ -694,15 +693,14 @@ namespace OpenSim.Data.MySQL
MySQLSuperManager dbm = GetLockedConnection("UpdateUserProfile");
try
{
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,
user.UserInventoryURI,
user.UserAssetURI, user.CanDoMask, user.WantDoMask, user.AboutText,
user.FirstLifeAboutText, user.Image, user.FirstLifeImage, user.WebLoginKey,
user.UserFlags, user.GodLevel, user.CustomType, user.Partner);
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,
user.UserInventoryURI,
user.UserAssetURI, user.CanDoMask, user.WantDoMask, user.AboutText,
user.FirstLifeAboutText, user.Image, user.FirstLifeImage, user.WebLoginKey,
user.UserFlags, user.GodLevel, user.CustomType, user.Partner);
}
finally
{
@ -750,29 +748,29 @@ namespace OpenSim.Data.MySQL
Dictionary<string, object> param = new Dictionary<string, object>();
param["?owner"] = user.ToString();
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);
IDbCommand result = dbm.Manager.Query(
"SELECT * FROM " + m_appearanceTableName + " WHERE owner = ?owner", param);
IDataReader reader = result.ExecuteReader();
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;
}
}
AvatarAppearance appearance = dbm.Manager.readAppearanceRow(reader);
reader.Dispose();
result.Dispose();
if (null == appearance)
{
m_log.WarnFormat("[USER DB] No appearance found for user {0}", user.ToString());
return null;
}
appearance.SetAttachments(GetUserAttachments(user));
return appearance;
}
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
return null;
}
finally
@ -800,7 +798,7 @@ namespace OpenSim.Data.MySQL
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
}
finally
{
@ -835,20 +833,20 @@ namespace OpenSim.Data.MySQL
try
{
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);
return ret;
}
}
IDbCommand result = dbm.Manager.Query(
"SELECT attachpoint, item, asset from " + m_attachmentsTableName + " WHERE UUID = ?uuid", param);
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.Message, e);
m_log.Error(e.ToString());
return null;
}
finally
@ -907,7 +905,7 @@ namespace OpenSim.Data.MySQL
catch (Exception e)
{
dbm.Manager.Reconnect();
m_log.Error(e.Message, e);
m_log.Error(e.ToString());
return;
}
finally