Updated MySQL connection management to use the MySQL connection pooling. This should accommodate various timeout problems that exist with the current connection pool code in a more general and standard way.
parent
5f1f5c29e9
commit
e1b5c61247
|
@ -43,10 +43,13 @@ namespace OpenSim.Data.MySQL
|
|||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private MySQLManager _dbConnection;
|
||||
private string m_connectionString;
|
||||
private object m_dbLock = new object();
|
||||
|
||||
#region IPlugin Members
|
||||
|
||||
public override string Version { get { return "1.0.0.0"; } }
|
||||
|
||||
/// <summary>
|
||||
/// <para>Initialises Asset interface</para>
|
||||
/// <para>
|
||||
|
@ -58,62 +61,28 @@ namespace OpenSim.Data.MySQL
|
|||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="connect">connect string</param>
|
||||
override public void Initialise(string connect)
|
||||
public override void Initialise(string connect)
|
||||
{
|
||||
// TODO: This will let you pass in the connect string in
|
||||
// the config, though someone will need to write that.
|
||||
if (connect == String.Empty)
|
||||
{
|
||||
// This is old seperate config file
|
||||
m_log.Warn("no connect string, using old mysql_connection.ini instead");
|
||||
Initialise();
|
||||
}
|
||||
else
|
||||
{
|
||||
_dbConnection = new MySQLManager(connect);
|
||||
}
|
||||
m_connectionString = connect;
|
||||
|
||||
// This actually does the roll forward assembly stuff
|
||||
Assembly assem = GetType().Assembly;
|
||||
Migration m = new Migration(_dbConnection.Connection, assem, "AssetStore");
|
||||
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
Migration m = new Migration(dbcon, assem, "AssetStore");
|
||||
m.Update();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Initialises Asset interface</para>
|
||||
/// <para>
|
||||
/// <list type="bullet">
|
||||
/// <item>Loads and initialises the MySQL storage plugin</item>
|
||||
/// <item>uses the obsolete mysql_connection.ini</item>
|
||||
/// </list>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <remarks>DEPRECATED and shouldn't be used</remarks>
|
||||
public override void Initialise()
|
||||
{
|
||||
IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini");
|
||||
string hostname = GridDataMySqlFile.ParseFileReadValue("hostname");
|
||||
string database = GridDataMySqlFile.ParseFileReadValue("database");
|
||||
string username = GridDataMySqlFile.ParseFileReadValue("username");
|
||||
string password = GridDataMySqlFile.ParseFileReadValue("password");
|
||||
string pooling = GridDataMySqlFile.ParseFileReadValue("pooling");
|
||||
string port = GridDataMySqlFile.ParseFileReadValue("port");
|
||||
|
||||
_dbConnection = new MySQLManager(hostname, database, username, password, pooling, port);
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Dispose() { }
|
||||
|
||||
/// <summary>
|
||||
/// Database provider version
|
||||
/// </summary>
|
||||
override public string Version
|
||||
{
|
||||
get { return _dbConnection.getVersion(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The name of this DB provider
|
||||
/// </summary>
|
||||
|
@ -135,14 +104,16 @@ namespace OpenSim.Data.MySQL
|
|||
override public AssetBase GetAsset(UUID assetID)
|
||||
{
|
||||
AssetBase asset = null;
|
||||
lock (_dbConnection)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
_dbConnection.CheckConnection();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
MySqlCommand cmd =
|
||||
new MySqlCommand(
|
||||
using (MySqlCommand cmd = new MySqlCommand(
|
||||
"SELECT name, description, assetType, local, temporary, data FROM assets WHERE id=?id",
|
||||
_dbConnection.Connection);
|
||||
dbcon))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("?id", assetID.ToString());
|
||||
|
||||
try
|
||||
|
@ -152,8 +123,8 @@ namespace OpenSim.Data.MySQL
|
|||
if (dbReader.Read())
|
||||
{
|
||||
asset = new AssetBase(assetID, (string)dbReader["name"], (sbyte)dbReader["assetType"]);
|
||||
asset.Data = (byte[]) dbReader["data"];
|
||||
asset.Description = (string) dbReader["description"];
|
||||
asset.Data = (byte[])dbReader["data"];
|
||||
asset.Description = (string)dbReader["description"];
|
||||
|
||||
string local = dbReader["local"].ToString();
|
||||
if (local.Equals("1") || local.Equals("true", StringComparison.InvariantCultureIgnoreCase))
|
||||
|
@ -163,18 +134,13 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
asset.Temporary = Convert.ToBoolean(dbReader["temporary"]);
|
||||
}
|
||||
dbReader.Close();
|
||||
cmd.Dispose();
|
||||
}
|
||||
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();
|
||||
m_log.Error("[ASSETS DB]: MySql failure fetching asset " + assetID + ": " + e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return asset;
|
||||
|
@ -187,15 +153,17 @@ namespace OpenSim.Data.MySQL
|
|||
/// <remarks>On failure : Throw an exception and attempt to reconnect to database</remarks>
|
||||
override public void StoreAsset(AssetBase asset)
|
||||
{
|
||||
lock (_dbConnection)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
_dbConnection.CheckConnection();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
MySqlCommand cmd =
|
||||
new MySqlCommand(
|
||||
"replace INTO assets(id, name, description, assetType, local, temporary, create_time, access_time, data)" +
|
||||
"VALUES(?id, ?name, ?description, ?assetType, ?local, ?temporary, ?create_time, ?access_time, ?data)",
|
||||
_dbConnection.Connection);
|
||||
dbcon);
|
||||
|
||||
string assetName = asset.Name;
|
||||
if (asset.Name.Length > 64)
|
||||
|
@ -233,9 +201,9 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.ErrorFormat("[ASSET DB]: MySQL failure creating asset {0} with name \"{1}\". Attempting reconnect. Error: {2}",
|
||||
m_log.ErrorFormat("[ASSET DB]: MySQL failure creating asset {0} with name \"{1}\". Error: {2}",
|
||||
asset.FullID, asset.Name, e.Message);
|
||||
_dbConnection.Reconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -245,13 +213,14 @@ namespace OpenSim.Data.MySQL
|
|||
// Writing to the database every time Get() is called on an asset is killing us. Seriously. -jph
|
||||
return;
|
||||
|
||||
lock (_dbConnection)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
_dbConnection.CheckConnection();
|
||||
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
MySqlCommand cmd =
|
||||
new MySqlCommand("update assets set access_time=?access_time where id=?id",
|
||||
_dbConnection.Connection);
|
||||
dbcon);
|
||||
|
||||
// need to ensure we dispose
|
||||
try
|
||||
|
@ -272,7 +241,7 @@ namespace OpenSim.Data.MySQL
|
|||
"[ASSETS DB]: " +
|
||||
"MySql failure updating access_time for asset {0} with name {1}" + Environment.NewLine + e.ToString()
|
||||
+ Environment.NewLine + "Attempting reconnection", asset.FullID, asset.Name);
|
||||
_dbConnection.Reconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -287,15 +256,13 @@ namespace OpenSim.Data.MySQL
|
|||
{
|
||||
bool assetExists = false;
|
||||
|
||||
lock (_dbConnection)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
using (MySqlCommand cmd = new MySqlCommand("SELECT id FROM assets WHERE id=?id", dbcon))
|
||||
{
|
||||
_dbConnection.CheckConnection();
|
||||
|
||||
MySqlCommand cmd =
|
||||
new MySqlCommand(
|
||||
"SELECT id FROM assets WHERE id=?id",
|
||||
_dbConnection.Connection);
|
||||
|
||||
cmd.Parameters.AddWithValue("?id", uuid.ToString());
|
||||
|
||||
try
|
||||
|
@ -303,20 +270,15 @@ namespace OpenSim.Data.MySQL
|
|||
using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
|
||||
{
|
||||
if (dbReader.Read())
|
||||
{
|
||||
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();
|
||||
"[ASSETS DB]: MySql failure fetching asset {0}" + Environment.NewLine + e.ToString(), uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -335,11 +297,12 @@ namespace OpenSim.Data.MySQL
|
|||
{
|
||||
List<AssetMetadata> retList = new List<AssetMetadata>(count);
|
||||
|
||||
lock (_dbConnection)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
_dbConnection.CheckConnection();
|
||||
|
||||
MySqlCommand cmd = new MySqlCommand("SELECT name,description,assetType,temporary,id FROM assets LIMIT ?start, ?count", _dbConnection.Connection);
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
MySqlCommand cmd = new MySqlCommand("SELECT name,description,assetType,temporary,id FROM assets LIMIT ?start, ?count", dbcon);
|
||||
cmd.Parameters.AddWithValue("?start", start);
|
||||
cmd.Parameters.AddWithValue("?count", count);
|
||||
|
||||
|
@ -350,14 +313,14 @@ namespace OpenSim.Data.MySQL
|
|||
while (dbReader.Read())
|
||||
{
|
||||
AssetMetadata metadata = new AssetMetadata();
|
||||
metadata.Name = (string) dbReader["name"];
|
||||
metadata.Description = (string) dbReader["description"];
|
||||
metadata.Type = (sbyte) dbReader["assetType"];
|
||||
metadata.Name = (string)dbReader["name"];
|
||||
metadata.Description = (string)dbReader["description"];
|
||||
metadata.Type = (sbyte)dbReader["assetType"];
|
||||
metadata.Temporary = Convert.ToBoolean(dbReader["temporary"]); // Not sure if this is correct.
|
||||
metadata.FullID = new UUID((string) dbReader["id"]);
|
||||
metadata.FullID = new UUID((string)dbReader["id"]);
|
||||
|
||||
// Current SHA1s are not stored/computed.
|
||||
metadata.SHA1 = new byte[] {};
|
||||
metadata.SHA1 = new byte[] { };
|
||||
|
||||
retList.Add(metadata);
|
||||
}
|
||||
|
@ -365,8 +328,8 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error("[ASSETS DB]: MySql failure fetching asset set" + Environment.NewLine + e.ToString() + Environment.NewLine + "Attempting reconnection");
|
||||
_dbConnection.Reconnect();
|
||||
m_log.Error("[ASSETS DB]: MySql failure fetching asset set" + Environment.NewLine + e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -374,7 +337,5 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,30 +38,36 @@ namespace OpenSim.Data.MySQL
|
|||
public class MySqlAuthenticationData : MySqlFramework, IAuthenticationData
|
||||
{
|
||||
private string m_Realm;
|
||||
private List<string> m_ColumnNames = null;
|
||||
private int m_LastExpire = 0;
|
||||
private List<string> m_ColumnNames;
|
||||
private int m_LastExpire;
|
||||
// private string m_connectionString;
|
||||
|
||||
public MySqlAuthenticationData(string connectionString, string realm)
|
||||
: base(connectionString)
|
||||
{
|
||||
m_Realm = realm;
|
||||
m_connectionString = connectionString;
|
||||
|
||||
Migration m = new Migration(m_Connection, GetType().Assembly, "AuthStore");
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
Migration m = new Migration(dbcon, GetType().Assembly, "AuthStore");
|
||||
m.Update();
|
||||
}
|
||||
}
|
||||
|
||||
public AuthenticationData Get(UUID principalID)
|
||||
{
|
||||
AuthenticationData ret = new AuthenticationData();
|
||||
ret.Data = new Dictionary<string, object>();
|
||||
|
||||
MySqlCommand cmd = new MySqlCommand(
|
||||
"select * from `"+m_Realm+"` where UUID = ?principalID"
|
||||
);
|
||||
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
MySqlCommand cmd = new MySqlCommand("select * from `" + m_Realm + "` where UUID = ?principalID", dbcon);
|
||||
cmd.Parameters.AddWithValue("?principalID", principalID.ToString());
|
||||
|
||||
IDataReader result = ExecuteReader(cmd);
|
||||
IDataReader result = cmd.ExecuteReader();
|
||||
|
||||
if (result.Read())
|
||||
{
|
||||
|
@ -84,17 +90,14 @@ namespace OpenSim.Data.MySQL
|
|||
ret.Data[s] = result[s].ToString();
|
||||
}
|
||||
|
||||
result.Close();
|
||||
CloseReaderCommand(cmd);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
result.Close();
|
||||
CloseReaderCommand(cmd);
|
||||
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Store(AuthenticationData data)
|
||||
{
|
||||
|
|
|
@ -44,7 +44,6 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
private const string m_waitTimeoutSelect = "select @@wait_timeout";
|
||||
|
||||
private MySqlConnection m_connection;
|
||||
private string m_connectionString;
|
||||
private long m_waitTimeout;
|
||||
private long m_waitTimeoutLeeway = 60 * TimeSpan.TicksPerSecond;
|
||||
|
@ -67,13 +66,14 @@ namespace OpenSim.Data.MySQL
|
|||
m_log.Debug("Exception: password not found in connection string\n" + e.ToString());
|
||||
}
|
||||
|
||||
m_connection = new MySqlConnection(m_connectionString);
|
||||
m_connection.Open();
|
||||
|
||||
GetWaitTimeout();
|
||||
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
Assembly assem = GetType().Assembly;
|
||||
Migration m = new Migration(m_connection, assem, "EstateStore");
|
||||
Migration m = new Migration(dbcon, assem, "EstateStore");
|
||||
m.Update();
|
||||
|
||||
Type t = typeof(EstateSettings);
|
||||
|
@ -87,6 +87,7 @@ namespace OpenSim.Data.MySQL
|
|||
m_FieldMap[f.Name.Substring(2)] = f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string[] FieldList
|
||||
{
|
||||
|
@ -95,11 +96,13 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
protected void GetWaitTimeout()
|
||||
{
|
||||
MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect,
|
||||
m_connection);
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlDataReader dbReader =
|
||||
cmd.ExecuteReader(CommandBehavior.SingleRow))
|
||||
using (MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect, dbcon))
|
||||
{
|
||||
using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
|
||||
{
|
||||
if (dbReader.Read())
|
||||
{
|
||||
|
@ -107,9 +110,7 @@ namespace OpenSim.Data.MySQL
|
|||
= Convert.ToInt32(dbReader["@@wait_timeout"]) *
|
||||
TimeSpan.TicksPerSecond + m_waitTimeoutLeeway;
|
||||
}
|
||||
|
||||
dbReader.Close();
|
||||
cmd.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
m_lastConnectionUse = DateTime.Now.Ticks;
|
||||
|
@ -118,24 +119,6 @@ namespace OpenSim.Data.MySQL
|
|||
"[REGION DB]: Connection wait timeout {0} seconds",
|
||||
m_waitTimeout / TimeSpan.TicksPerSecond);
|
||||
}
|
||||
|
||||
protected void CheckConnection()
|
||||
{
|
||||
long timeNow = DateTime.Now.Ticks;
|
||||
if (timeNow - m_lastConnectionUse > m_waitTimeout ||
|
||||
m_connection.State != ConnectionState.Open)
|
||||
{
|
||||
m_log.DebugFormat("[REGION DB]: Database connection has gone away - reconnecting");
|
||||
|
||||
lock (m_connection)
|
||||
{
|
||||
m_connection.Close();
|
||||
m_connection = new MySqlConnection(m_connectionString);
|
||||
m_connection.Open();
|
||||
}
|
||||
}
|
||||
|
||||
m_lastConnectionUse = timeNow;
|
||||
}
|
||||
|
||||
public EstateSettings LoadEstateSettings(UUID regionID)
|
||||
|
@ -143,19 +126,26 @@ namespace OpenSim.Data.MySQL
|
|||
EstateSettings es = new EstateSettings();
|
||||
es.OnSave += StoreEstateSettings;
|
||||
|
||||
string sql = "select estate_settings." + String.Join(",estate_settings.", FieldList) + " from estate_map left join estate_settings on estate_map.EstateID = estate_settings.EstateID where estate_settings.EstateID is not null and RegionID = ?RegionID";
|
||||
string sql = "select estate_settings." + String.Join(",estate_settings.", FieldList) +
|
||||
" from estate_map left join estate_settings on estate_map.EstateID = estate_settings.EstateID where estate_settings.EstateID is not null and RegionID = ?RegionID";
|
||||
|
||||
CheckConnection();
|
||||
bool migration = true;
|
||||
|
||||
MySqlCommand cmd = m_connection.CreateCommand();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlCommand cmd = dbcon.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 +168,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 = dbcon.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = sql;
|
||||
cmd.Parameters.Clear();
|
||||
|
||||
|
@ -215,43 +206,32 @@ 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);
|
||||
|
||||
|
@ -265,10 +245,12 @@ namespace OpenSim.Data.MySQL
|
|||
{
|
||||
string sql = "replace into estate_settings (" + String.Join(",", FieldList) + ") values ( ?" + String.Join(", ?", FieldList) + ")";
|
||||
|
||||
CheckConnection();
|
||||
|
||||
MySqlCommand cmd = m_connection.CreateCommand();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlCommand cmd = dbcon.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = sql;
|
||||
|
||||
foreach (string name in FieldList)
|
||||
|
@ -287,6 +269,8 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
SaveBanList(es);
|
||||
SaveUUIDList(es.EstateID, "estate_managers", es.EstateManagers);
|
||||
|
@ -298,15 +282,17 @@ namespace OpenSim.Data.MySQL
|
|||
{
|
||||
es.ClearBans();
|
||||
|
||||
CheckConnection();
|
||||
|
||||
MySqlCommand cmd = m_connection.CreateCommand();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlCommand cmd = dbcon.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 +305,19 @@ 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 (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlCommand cmd = dbcon.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "delete from estateban where EstateID = ?EstateID";
|
||||
cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString());
|
||||
|
||||
|
@ -346,13 +336,17 @@ namespace OpenSim.Data.MySQL
|
|||
cmd.Parameters.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SaveUUIDList(uint EstateID, string table, UUID[] data)
|
||||
{
|
||||
CheckConnection();
|
||||
|
||||
MySqlCommand cmd = m_connection.CreateCommand();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlCommand cmd = dbcon.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "delete from " + table + " where EstateID = ?EstateID";
|
||||
cmd.Parameters.AddWithValue("?EstateID", EstateID.ToString());
|
||||
|
||||
|
@ -371,20 +365,24 @@ namespace OpenSim.Data.MySQL
|
|||
cmd.Parameters.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UUID[] LoadUUIDList(uint EstateID, string table)
|
||||
{
|
||||
List<UUID> uuids = new List<UUID>();
|
||||
|
||||
CheckConnection();
|
||||
|
||||
MySqlCommand cmd = m_connection.CreateCommand();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlCommand cmd = dbcon.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 +392,9 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
uuids.Add(uuid);
|
||||
}
|
||||
r.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return uuids.ToArray();
|
||||
}
|
||||
|
|
|
@ -40,12 +40,16 @@ namespace OpenSim.Data.MySQL
|
|||
/// </summary>
|
||||
public class MySqlFramework
|
||||
{
|
||||
protected MySqlConnection m_Connection;
|
||||
private static readonly log4net.ILog m_log =
|
||||
log4net.LogManager.GetLogger(
|
||||
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
protected string m_connectionString;
|
||||
protected object m_dbLock = new object();
|
||||
|
||||
protected MySqlFramework(string connectionString)
|
||||
{
|
||||
m_Connection = new MySqlConnection(connectionString);
|
||||
m_Connection.Open();
|
||||
m_connectionString = connectionString;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
@ -55,64 +59,24 @@ namespace OpenSim.Data.MySQL
|
|||
//
|
||||
protected int ExecuteNonQuery(MySqlCommand cmd)
|
||||
{
|
||||
lock (m_Connection)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
cmd.Connection = m_Connection;
|
||||
|
||||
bool errorSeen = false;
|
||||
|
||||
while (true)
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
cmd.Connection = dbcon;
|
||||
|
||||
try
|
||||
{
|
||||
return cmd.ExecuteNonQuery();
|
||||
}
|
||||
catch (MySqlException e)
|
||||
{
|
||||
if (errorSeen)
|
||||
throw;
|
||||
|
||||
// This is "Server has gone away" and "Server lost"
|
||||
//
|
||||
if (e.Number == 2006 || e.Number == 2013)
|
||||
{
|
||||
errorSeen = true;
|
||||
|
||||
m_Connection.Close();
|
||||
MySqlConnection newConnection =
|
||||
(MySqlConnection)((ICloneable)m_Connection).Clone();
|
||||
m_Connection.Dispose();
|
||||
m_Connection = newConnection;
|
||||
m_Connection.Open();
|
||||
|
||||
cmd.Connection = m_Connection;
|
||||
}
|
||||
else
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error(e.Message, e);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected IDataReader ExecuteReader(MySqlCommand cmd)
|
||||
{
|
||||
MySqlConnection newConnection =
|
||||
(MySqlConnection)((ICloneable)m_Connection).Clone();
|
||||
newConnection.Open();
|
||||
|
||||
cmd.Connection = newConnection;
|
||||
return cmd.ExecuteReader();
|
||||
}
|
||||
|
||||
protected void CloseReaderCommand(MySqlCommand cmd)
|
||||
{
|
||||
cmd.Connection.Close();
|
||||
cmd.Connection.Dispose();
|
||||
cmd.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,13 +54,17 @@ namespace OpenSim.Data.MySQL
|
|||
string realm, string storeName) : base(connectionString)
|
||||
{
|
||||
m_Realm = realm;
|
||||
m_connectionString = connectionString;
|
||||
|
||||
if (storeName != String.Empty)
|
||||
{
|
||||
Assembly assem = GetType().Assembly;
|
||||
|
||||
Migration m = new Migration(m_Connection, assem, storeName);
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
Migration m = new Migration(dbcon, GetType().Assembly, storeName);
|
||||
m.Update();
|
||||
}
|
||||
}
|
||||
|
||||
Type t = typeof(T);
|
||||
FieldInfo[] fields = t.GetFields(BindingFlags.Public |
|
||||
|
@ -107,8 +111,8 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
List<string> terms = new List<string>();
|
||||
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
|
||||
using (MySqlCommand cmd = new MySqlCommand())
|
||||
{
|
||||
for (int i = 0 ; i < fields.Length ; i++)
|
||||
{
|
||||
cmd.Parameters.AddWithValue(fields[i], keys[i]);
|
||||
|
@ -124,17 +128,24 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
return DoQuery(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
protected T[] DoQuery(MySqlCommand cmd)
|
||||
{
|
||||
IDataReader reader = ExecuteReader(cmd);
|
||||
List<T> result = new List<T>();
|
||||
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
cmd.Connection = dbcon;
|
||||
|
||||
using (IDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
if (reader == null)
|
||||
return new T[0];
|
||||
|
||||
CheckColumnNames(reader);
|
||||
|
||||
List<T> result = new List<T>();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
T row = new T();
|
||||
|
@ -181,15 +192,16 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
result.Add(row);
|
||||
}
|
||||
|
||||
CloseReaderCommand(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
public T[] Get(string where)
|
||||
{
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
using (MySqlCommand cmd = new MySqlCommand())
|
||||
{
|
||||
|
||||
string query = String.Format("select * from {0} where {1}",
|
||||
m_Realm, where);
|
||||
|
@ -198,10 +210,12 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
return DoQuery(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Store(T row)
|
||||
{
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
using (MySqlCommand cmd = new MySqlCommand())
|
||||
{
|
||||
|
||||
string query = "";
|
||||
List<String> names = new List<String>();
|
||||
|
@ -236,10 +250,12 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Delete(string field, string val)
|
||||
{
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
using (MySqlCommand cmd = new MySqlCommand())
|
||||
{
|
||||
|
||||
cmd.CommandText = String.Format("delete from {0} where `{1}` = ?{1}", m_Realm, field);
|
||||
cmd.Parameters.AddWithValue(field, val);
|
||||
|
@ -250,4 +266,5 @@ namespace OpenSim.Data.MySQL
|
|||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ using System.Data;
|
|||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using log4net;
|
||||
using MySql.Data.MySqlClient;
|
||||
using OpenMetaverse;
|
||||
using OpenSim.Framework;
|
||||
|
||||
|
@ -43,49 +44,9 @@ namespace OpenSim.Data.MySQL
|
|||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
/// <summary>
|
||||
/// MySQL Database Manager
|
||||
/// </summary>
|
||||
private MySQLManager database;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Better DB manager. Swap-in replacement too.
|
||||
/// </summary>
|
||||
public Dictionary<int, MySQLSuperManager> m_dbconnections = new Dictionary<int, MySQLSuperManager>();
|
||||
|
||||
public int m_maxConnections = 10;
|
||||
public int m_lastConnect;
|
||||
|
||||
public MySQLSuperManager GetLockedConnection()
|
||||
{
|
||||
int lockedCons = 0;
|
||||
while (true)
|
||||
{
|
||||
m_lastConnect++;
|
||||
|
||||
// Overflow protection
|
||||
if (m_lastConnect == int.MaxValue)
|
||||
m_lastConnect = 0;
|
||||
|
||||
MySQLSuperManager x = m_dbconnections[m_lastConnect % m_maxConnections];
|
||||
if (!x.Locked)
|
||||
{
|
||||
x.GetLock();
|
||||
return x;
|
||||
}
|
||||
|
||||
lockedCons++;
|
||||
if (lockedCons > m_maxConnections)
|
||||
{
|
||||
lockedCons = 0;
|
||||
Thread.Sleep(1000); // Wait some time before searching them again.
|
||||
m_log.Debug(
|
||||
"WARNING: All threads are in use. Probable cause: Something didnt release a mutex properly, or high volume of requests inbound.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private MySQLManager m_database;
|
||||
private object m_dbLock = new object();
|
||||
private string m_connectionString;
|
||||
|
||||
override public void Initialise()
|
||||
{
|
||||
|
@ -106,57 +67,24 @@ namespace OpenSim.Data.MySQL
|
|||
/// <param name="connect">connect string.</param>
|
||||
override public void Initialise(string connect)
|
||||
{
|
||||
if (connect != String.Empty)
|
||||
{
|
||||
database = new MySQLManager(connect);
|
||||
|
||||
m_log.Info("Creating " + m_maxConnections + " DB connections...");
|
||||
for (int i = 0; i < m_maxConnections; i++)
|
||||
{
|
||||
m_log.Info("Connecting to DB... [" + i + "]");
|
||||
MySQLSuperManager msm = new MySQLSuperManager();
|
||||
msm.Manager = new MySQLManager(connect);
|
||||
m_dbconnections.Add(i, msm);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.Warn("Using deprecated mysql_connection.ini. Please update database_connect in GridServer_Config.xml and we'll use that instead");
|
||||
IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini");
|
||||
string settingHostname = GridDataMySqlFile.ParseFileReadValue("hostname");
|
||||
string settingDatabase = GridDataMySqlFile.ParseFileReadValue("database");
|
||||
string settingUsername = GridDataMySqlFile.ParseFileReadValue("username");
|
||||
string settingPassword = GridDataMySqlFile.ParseFileReadValue("password");
|
||||
string settingPooling = GridDataMySqlFile.ParseFileReadValue("pooling");
|
||||
string settingPort = GridDataMySqlFile.ParseFileReadValue("port");
|
||||
|
||||
database = new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword,
|
||||
settingPooling, settingPort);
|
||||
|
||||
m_log.Info("Creating " + m_maxConnections + " DB connections...");
|
||||
for (int i = 0; i < m_maxConnections; i++)
|
||||
{
|
||||
m_log.Info("Connecting to DB... [" + i + "]");
|
||||
MySQLSuperManager msm = new MySQLSuperManager();
|
||||
msm.Manager = new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword,
|
||||
settingPooling, settingPort);
|
||||
m_dbconnections.Add(i, msm);
|
||||
}
|
||||
}
|
||||
m_connectionString = connect;
|
||||
m_database = new MySQLManager(connect);
|
||||
|
||||
// This actually does the roll forward assembly stuff
|
||||
Assembly assem = GetType().Assembly;
|
||||
Migration m = new Migration(database.Connection, assem, "GridStore");
|
||||
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
Migration m = new Migration(dbcon, assem, "GridStore");
|
||||
m.Update();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shuts down the grid interface
|
||||
/// </summary>
|
||||
override public void Dispose()
|
||||
{
|
||||
database.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -187,8 +115,6 @@ namespace OpenSim.Data.MySQL
|
|||
/// <returns>Array of sim profiles</returns>
|
||||
override public RegionProfileData[] GetProfilesInRange(uint xmin, uint ymin, uint xmax, uint ymax)
|
||||
{
|
||||
MySQLSuperManager dbm = GetLockedConnection();
|
||||
|
||||
try
|
||||
{
|
||||
Dictionary<string, object> param = new Dictionary<string, object>();
|
||||
|
@ -197,35 +123,33 @@ namespace OpenSim.Data.MySQL
|
|||
param["?xmax"] = xmax.ToString();
|
||||
param["?ymax"] = ymax.ToString();
|
||||
|
||||
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();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (IDbCommand result = m_database.Query(dbcon,
|
||||
"SELECT * FROM regions WHERE locX >= ?xmin AND locX <= ?xmax AND locY >= ?ymin AND locY <= ?ymax",
|
||||
param))
|
||||
{
|
||||
using (IDataReader reader = result.ExecuteReader())
|
||||
{
|
||||
RegionProfileData row;
|
||||
|
||||
List<RegionProfileData> rows = new List<RegionProfileData>();
|
||||
|
||||
while ((row = dbm.Manager.readSimRow(reader)) != null)
|
||||
{
|
||||
while ((row = m_database.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
|
||||
{
|
||||
dbm.Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -236,42 +160,38 @@ namespace OpenSim.Data.MySQL
|
|||
/// <returns>A list of sim profiles</returns>
|
||||
override public List<RegionProfileData> GetRegionsByName(string namePrefix, uint maxNum)
|
||||
{
|
||||
MySQLSuperManager dbm = GetLockedConnection();
|
||||
|
||||
try
|
||||
{
|
||||
Dictionary<string, object> param = new Dictionary<string, object>();
|
||||
param["?name"] = namePrefix + "%";
|
||||
|
||||
IDbCommand result =
|
||||
dbm.Manager.Query(
|
||||
"SELECT * FROM regions WHERE regionName LIKE ?name",
|
||||
param);
|
||||
IDataReader reader = result.ExecuteReader();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (IDbCommand result = m_database.Query(dbcon,
|
||||
"SELECT * FROM regions WHERE regionName LIKE ?name",
|
||||
param))
|
||||
{
|
||||
using (IDataReader reader = result.ExecuteReader())
|
||||
{
|
||||
RegionProfileData row;
|
||||
|
||||
List<RegionProfileData> rows = new List<RegionProfileData>();
|
||||
|
||||
while (rows.Count < maxNum && (row = dbm.Manager.readSimRow(reader)) != null)
|
||||
{
|
||||
while (rows.Count < maxNum && (row = m_database.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
|
||||
{
|
||||
dbm.Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -281,32 +201,30 @@ namespace OpenSim.Data.MySQL
|
|||
/// <returns>Sim profile</returns>
|
||||
override public RegionProfileData GetProfileByHandle(ulong handle)
|
||||
{
|
||||
MySQLSuperManager dbm = GetLockedConnection();
|
||||
|
||||
try
|
||||
{
|
||||
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();
|
||||
|
||||
RegionProfileData row = dbm.Manager.readSimRow(reader);
|
||||
reader.Close();
|
||||
result.Dispose();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (IDbCommand result = m_database.Query(dbcon, "SELECT * FROM regions WHERE regionHandle = ?handle", param))
|
||||
{
|
||||
using (IDataReader reader = result.ExecuteReader())
|
||||
{
|
||||
RegionProfileData row = m_database.readSimRow(reader);
|
||||
return row;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
dbm.Manager.Reconnect();
|
||||
m_log.Error(e.ToString());
|
||||
m_log.Error(e.Message, e);
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
dbm.Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -316,30 +234,29 @@ namespace OpenSim.Data.MySQL
|
|||
/// <returns>The sim profile</returns>
|
||||
override public RegionProfileData GetProfileByUUID(UUID uuid)
|
||||
{
|
||||
MySQLSuperManager dbm = GetLockedConnection();
|
||||
|
||||
try
|
||||
{
|
||||
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();
|
||||
|
||||
RegionProfileData row = dbm.Manager.readSimRow(reader);
|
||||
reader.Close();
|
||||
result.Dispose();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (IDbCommand result = m_database.Query(dbcon, "SELECT * FROM regions WHERE uuid = ?uuid", param))
|
||||
{
|
||||
using (IDataReader reader = result.ExecuteReader())
|
||||
{
|
||||
RegionProfileData row = m_database.readSimRow(reader);
|
||||
return row;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
dbm.Manager.Reconnect();
|
||||
m_log.Error(e.ToString());
|
||||
m_log.Error(e.Message, e);
|
||||
return null;
|
||||
} finally
|
||||
{
|
||||
dbm.Release();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -351,37 +268,36 @@ namespace OpenSim.Data.MySQL
|
|||
{
|
||||
if (regionName.Length > 2)
|
||||
{
|
||||
MySQLSuperManager dbm = GetLockedConnection();
|
||||
|
||||
try
|
||||
{
|
||||
Dictionary<string, object> param = new Dictionary<string, object>();
|
||||
// Add % because this is a like query.
|
||||
param["?regionName"] = regionName + "%";
|
||||
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
// Order by statement will return shorter matches first. Only returns one record or no record.
|
||||
IDbCommand result =
|
||||
dbm.Manager.Query(
|
||||
using (IDbCommand result = m_database.Query(dbcon,
|
||||
"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();
|
||||
|
||||
param))
|
||||
{
|
||||
using (IDataReader reader = result.ExecuteReader())
|
||||
{
|
||||
RegionProfileData row = m_database.readSimRow(reader);
|
||||
return row;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
dbm.Manager.Reconnect();
|
||||
m_log.Error(e.ToString());
|
||||
m_log.Error(e.Message, e);
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
dbm.Release();
|
||||
}
|
||||
}
|
||||
|
||||
m_log.Error("[GRID DB]: Searched for a Region Name shorter then 3 characters");
|
||||
return null;
|
||||
}
|
||||
|
@ -393,17 +309,16 @@ namespace OpenSim.Data.MySQL
|
|||
/// <returns>Successful?</returns>
|
||||
override public DataResponse StoreProfile(RegionProfileData profile)
|
||||
{
|
||||
MySQLSuperManager dbm = GetLockedConnection();
|
||||
try {
|
||||
if (dbm.Manager.insertRegion(profile))
|
||||
try
|
||||
{
|
||||
if (m_database.insertRegion(profile))
|
||||
return DataResponse.RESPONSE_OK;
|
||||
}
|
||||
else
|
||||
return DataResponse.RESPONSE_ERROR;
|
||||
}
|
||||
finally
|
||||
catch
|
||||
{
|
||||
dbm.Release();
|
||||
return DataResponse.RESPONSE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -415,18 +330,16 @@ namespace OpenSim.Data.MySQL
|
|||
//public DataResponse DeleteProfile(RegionProfileData profile)
|
||||
override public DataResponse DeleteProfile(string uuid)
|
||||
{
|
||||
MySQLSuperManager dbm = GetLockedConnection();
|
||||
|
||||
|
||||
try {
|
||||
if (dbm.Manager.deleteRegion(uuid))
|
||||
try
|
||||
{
|
||||
if (m_database.deleteRegion(uuid))
|
||||
return DataResponse.RESPONSE_OK;
|
||||
}
|
||||
else
|
||||
return DataResponse.RESPONSE_ERROR;
|
||||
} finally
|
||||
}
|
||||
catch
|
||||
{
|
||||
dbm.Release();
|
||||
return DataResponse.RESPONSE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -477,33 +390,32 @@ namespace OpenSim.Data.MySQL
|
|||
/// <returns></returns>
|
||||
override public ReservationData GetReservationAtPoint(uint x, uint y)
|
||||
{
|
||||
MySQLSuperManager dbm = GetLockedConnection();
|
||||
|
||||
try
|
||||
{
|
||||
Dictionary<string, object> param = new Dictionary<string, object>();
|
||||
param["?x"] = x.ToString();
|
||||
param["?y"] = y.ToString();
|
||||
IDbCommand result =
|
||||
dbm.Manager.Query(
|
||||
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (IDbCommand result = m_database.Query(dbcon,
|
||||
"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();
|
||||
|
||||
param))
|
||||
{
|
||||
using (IDataReader reader = result.ExecuteReader())
|
||||
{
|
||||
ReservationData row = m_database.readReservationRow(reader);
|
||||
return row;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
dbm.Manager.Reconnect();
|
||||
m_log.Error(e.ToString());
|
||||
m_log.Error(e.Message, e);
|
||||
return null;
|
||||
} finally
|
||||
{
|
||||
dbm.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
*/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using log4net;
|
||||
|
@ -44,14 +43,10 @@ namespace OpenSim.Data.MySQL
|
|||
private static readonly ILog m_log
|
||||
= LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
/// <summary>
|
||||
/// The database manager
|
||||
/// </summary>
|
||||
private MySQLManager database;
|
||||
private string m_connectionString;
|
||||
private object m_dbLock = new object();
|
||||
|
||||
private bool rollbackStore = false;
|
||||
private bool opengridmode = false;
|
||||
private string rollbackDir = "";
|
||||
public string Version { get { return "1.0.0.0"; } }
|
||||
|
||||
public void Initialise()
|
||||
{
|
||||
|
@ -72,38 +67,18 @@ namespace OpenSim.Data.MySQL
|
|||
/// <param name="connect">connect string</param>
|
||||
public void Initialise(string connect)
|
||||
{
|
||||
if (connect != String.Empty)
|
||||
{
|
||||
database = new MySQLManager(connect);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.Warn("Reverting to deprecated mysql_connection.ini file for connection info");
|
||||
IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini");
|
||||
string settingHostname = GridDataMySqlFile.ParseFileReadValue("hostname");
|
||||
string settingDatabase = GridDataMySqlFile.ParseFileReadValue("database");
|
||||
string settingUsername = GridDataMySqlFile.ParseFileReadValue("username");
|
||||
string settingPassword = GridDataMySqlFile.ParseFileReadValue("password");
|
||||
string settingPooling = GridDataMySqlFile.ParseFileReadValue("pooling");
|
||||
string settingPort = GridDataMySqlFile.ParseFileReadValue("port");
|
||||
|
||||
rollbackDir = GridDataMySqlFile.ParseFileReadValue("rollbackdir");
|
||||
rollbackStore = GridDataMySqlFile.ParseFileReadValue("rollback") == "true";
|
||||
opengridmode = GridDataMySqlFile.ParseFileReadValue("opengridmode") == "true";
|
||||
|
||||
if (rollbackStore)
|
||||
m_log.Warn("[MysqlInventory] Enabling rollback mode in: " + rollbackDir);
|
||||
|
||||
database =
|
||||
new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword, settingPooling,
|
||||
settingPort);
|
||||
}
|
||||
m_connectionString = connect;
|
||||
|
||||
// This actually does the roll forward assembly stuff
|
||||
Assembly assem = GetType().Assembly;
|
||||
Migration m = new Migration(database.Connection, assem, "InventoryStore");
|
||||
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
Migration m = new Migration(dbcon, assem, "InventoryStore");
|
||||
m.Update();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The name of this DB provider
|
||||
|
@ -123,15 +98,6 @@ namespace OpenSim.Data.MySQL
|
|||
// Do nothing.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the version of this DB provider
|
||||
/// </summary>
|
||||
/// <returns>A string containing the DB provider version</returns>
|
||||
public string Version
|
||||
{
|
||||
get { return database.getVersion(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of items in a specified folder
|
||||
/// </summary>
|
||||
|
@ -141,18 +107,20 @@ namespace OpenSim.Data.MySQL
|
|||
{
|
||||
try
|
||||
{
|
||||
lock (database)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
List<InventoryItemBase> items = new List<InventoryItemBase>();
|
||||
|
||||
database.CheckConnection();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
MySqlCommand result =
|
||||
new MySqlCommand("SELECT * FROM inventoryitems WHERE parentFolderID = ?uuid",
|
||||
database.Connection);
|
||||
using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE parentFolderID = ?uuid", dbcon))
|
||||
{
|
||||
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
|
||||
|
@ -161,16 +129,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;
|
||||
}
|
||||
}
|
||||
|
@ -184,33 +151,33 @@ namespace OpenSim.Data.MySQL
|
|||
{
|
||||
try
|
||||
{
|
||||
lock (database)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
database.CheckConnection();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
MySqlCommand result =
|
||||
new MySqlCommand(
|
||||
"SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid",
|
||||
database.Connection);
|
||||
using (MySqlCommand result = new MySqlCommand(
|
||||
"SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", dbcon))
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -225,19 +192,20 @@ namespace OpenSim.Data.MySQL
|
|||
{
|
||||
try
|
||||
{
|
||||
lock (database)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
database.CheckConnection();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
MySqlCommand result =
|
||||
new MySqlCommand(
|
||||
"SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid",
|
||||
database.Connection);
|
||||
using (MySqlCommand result = new MySqlCommand(
|
||||
"SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", dbcon))
|
||||
{
|
||||
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));
|
||||
|
@ -250,21 +218,18 @@ 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());
|
||||
throw;
|
||||
m_log.Error(e.Message, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -279,31 +244,31 @@ namespace OpenSim.Data.MySQL
|
|||
{
|
||||
try
|
||||
{
|
||||
lock (database)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
database.CheckConnection();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
MySqlCommand result =
|
||||
new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?uuid",
|
||||
database.Connection);
|
||||
using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?uuid", dbcon))
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -378,29 +343,31 @@ namespace OpenSim.Data.MySQL
|
|||
{
|
||||
try
|
||||
{
|
||||
lock (database)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
database.CheckConnection();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
MySqlCommand result =
|
||||
new MySqlCommand("SELECT * FROM inventoryitems WHERE inventoryID = ?uuid", database.Connection);
|
||||
using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE inventoryID = ?uuid", dbcon))
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
@ -425,7 +392,7 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error(e.ToString());
|
||||
m_log.Error(e.Message, e);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -441,151 +408,35 @@ namespace OpenSim.Data.MySQL
|
|||
{
|
||||
try
|
||||
{
|
||||
lock (database)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
database.CheckConnection();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
MySqlCommand result =
|
||||
new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", database.Connection);
|
||||
using (MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", dbcon))
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
#region Inventory Rollback-via-.sql Support
|
||||
/// <summary>
|
||||
/// Not a good SQL escape function, but it'll do the job (if mutilate the data.)
|
||||
/// Someone may want to write something better here.
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
private static string cheapSQLescape(string str)
|
||||
{
|
||||
str = str.Replace("\\", "");
|
||||
str = str.Replace("'", "");
|
||||
str = str.Replace("\"", "");
|
||||
return "'" + str + "'";
|
||||
}
|
||||
|
||||
private static string InventoryItemToSql(InventoryItemBase item)
|
||||
{
|
||||
string sql =
|
||||
"REPLACE /*! INVITEM AT ***$SUBS$*** */ INTO inventoryitems (inventoryID, assetID, assetType, parentFolderID, avatarID, inventoryName"
|
||||
+ ", inventoryDescription, inventoryNextPermissions, inventoryCurrentPermissions, invType"
|
||||
+ ", creatorID, inventoryBasePermissions, inventoryEveryOnePermissions, inventoryGroupPermissions, salePrice, saleType"
|
||||
+ ", creationDate, groupID, groupOwned, flags) VALUES ";
|
||||
sql +=
|
||||
"(?inventoryID, ?assetID, ?assetType, ?parentFolderID, ?avatarID, ?inventoryName, ?inventoryDescription"
|
||||
+ ", ?inventoryNextPermissions, ?inventoryCurrentPermissions, ?invType, ?creatorID"
|
||||
+ ", ?inventoryBasePermissions, ?inventoryEveryOnePermissions, ?inventoryGroupPermissions, ?salePrice, ?saleType, ?creationDate"
|
||||
+ ", ?groupID, ?groupOwned, ?flags);\r\n";
|
||||
|
||||
string itemName = item.Name;
|
||||
string itemDesc = item.Description;
|
||||
|
||||
sql = sql.Replace("$SUBS$", Util.UnixTimeSinceEpoch().ToString());
|
||||
|
||||
sql = sql.Replace("?inventoryID", cheapSQLescape(item.ID.ToString()));
|
||||
sql = sql.Replace("?assetID", cheapSQLescape(item.AssetID.ToString()));
|
||||
sql = sql.Replace("?assetType", cheapSQLescape(item.AssetType.ToString()));
|
||||
sql = sql.Replace("?parentFolderID", cheapSQLescape(item.Folder.ToString()));
|
||||
sql = sql.Replace("?avatarID", cheapSQLescape(item.Owner.ToString()));
|
||||
sql = sql.Replace("?inventoryName", cheapSQLescape(itemName));
|
||||
sql = sql.Replace("?inventoryDescription", cheapSQLescape(itemDesc));
|
||||
sql = sql.Replace("?inventoryNextPermissions", cheapSQLescape(item.NextPermissions.ToString()));
|
||||
sql = sql.Replace("?inventoryCurrentPermissions", cheapSQLescape(item.CurrentPermissions.ToString()));
|
||||
sql = sql.Replace("?invType", cheapSQLescape(item.InvType.ToString()));
|
||||
sql = sql.Replace("?creatorID", cheapSQLescape(item.CreatorId));
|
||||
sql = sql.Replace("?inventoryBasePermissions", cheapSQLescape(item.BasePermissions.ToString()));
|
||||
sql = sql.Replace("?inventoryEveryOnePermissions", cheapSQLescape(item.EveryOnePermissions.ToString()));
|
||||
sql = sql.Replace("?inventoryGroupPermissions", cheapSQLescape(item.GroupPermissions.ToString()));
|
||||
sql = sql.Replace("?salePrice", cheapSQLescape(item.SalePrice.ToString()));
|
||||
sql = sql.Replace("?saleType", cheapSQLescape(unchecked((sbyte)item.SaleType).ToString()));
|
||||
sql = sql.Replace("?creationDate", cheapSQLescape(item.CreationDate.ToString()));
|
||||
sql = sql.Replace("?groupID", cheapSQLescape(item.GroupID.ToString()));
|
||||
sql = sql.Replace("?groupOwned", cheapSQLescape(item.GroupOwned.ToString()));
|
||||
sql = sql.Replace("?flags", cheapSQLescape(item.Flags.ToString()));
|
||||
|
||||
return sql;
|
||||
}
|
||||
|
||||
private static string InventoryFolderToSql(InventoryFolderBase folder)
|
||||
{
|
||||
string sql =
|
||||
"REPLACE /*! INVFOLDER AT ***$SUBS$*** */ INTO inventoryfolders (folderID, agentID, parentFolderID, folderName, type, version) VALUES ";
|
||||
sql += "(?folderID, ?agentID, ?parentFolderID, ?folderName, ?type, ?version);\r\n";
|
||||
|
||||
string folderName = folder.Name;
|
||||
|
||||
sql = sql.Replace("$SUBS$", Util.UnixTimeSinceEpoch().ToString());
|
||||
|
||||
sql = sql.Replace("?folderID", cheapSQLescape(folder.ID.ToString()));
|
||||
sql = sql.Replace("?agentID", cheapSQLescape(folder.Owner.ToString()));
|
||||
sql = sql.Replace("?parentFolderID", cheapSQLescape(folder.ParentID.ToString()));
|
||||
sql = sql.Replace("?folderName", cheapSQLescape(folderName));
|
||||
sql = sql.Replace("?type", cheapSQLescape(folder.Type.ToString()));
|
||||
sql = sql.Replace("?version", cheapSQLescape(folder.Version.ToString()));
|
||||
|
||||
return sql;
|
||||
}
|
||||
|
||||
private static string getRollbackFolderDate()
|
||||
{
|
||||
return DateTime.UtcNow.Year.ToString() + "-" + DateTime.UtcNow.Month.ToString() + "-" +
|
||||
DateTime.UtcNow.Day.ToString();
|
||||
}
|
||||
|
||||
private void StoreRollbackItem(UUID ItemID)
|
||||
{
|
||||
if (rollbackStore == true)
|
||||
{
|
||||
string todaysPath = RollbackGetTodaysPath();
|
||||
|
||||
InventoryItemBase imb = getInventoryItem(ItemID);
|
||||
string sql = InventoryItemToSql(imb);
|
||||
File.AppendAllText(Path.Combine(todaysPath, imb.Owner.ToString()), sql);
|
||||
}
|
||||
}
|
||||
|
||||
private void StoreRollbackFolder(UUID FolderID)
|
||||
{
|
||||
if (rollbackStore == true)
|
||||
{
|
||||
string todaysPath = RollbackGetTodaysPath();
|
||||
|
||||
InventoryFolderBase ifb = getInventoryFolder(FolderID);
|
||||
string sql = InventoryFolderToSql(ifb);
|
||||
File.AppendAllText(Path.Combine(todaysPath, ifb.Owner.ToString()), sql);
|
||||
}
|
||||
}
|
||||
|
||||
private string RollbackGetTodaysPath()
|
||||
{
|
||||
if (!Directory.Exists(rollbackDir))
|
||||
Directory.CreateDirectory(rollbackDir);
|
||||
|
||||
string todaysPath = Path.Combine(rollbackDir, getRollbackFolderDate());
|
||||
if (!Directory.Exists(todaysPath))
|
||||
Directory.CreateDirectory(todaysPath);
|
||||
return todaysPath;
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Adds a specified item to the database
|
||||
/// </summary>
|
||||
|
@ -619,9 +470,11 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
try
|
||||
{
|
||||
database.CheckConnection();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
MySqlCommand result = new MySqlCommand(sql, database.Connection);
|
||||
MySqlCommand result = new MySqlCommand(sql, dbcon);
|
||||
result.Parameters.AddWithValue("?inventoryID", item.ID.ToString());
|
||||
result.Parameters.AddWithValue("?assetID", item.AssetID.ToString());
|
||||
result.Parameters.AddWithValue("?assetType", item.AssetType.ToString());
|
||||
|
@ -644,22 +497,22 @@ namespace OpenSim.Data.MySQL
|
|||
result.Parameters.AddWithValue("?groupOwned", item.GroupOwned);
|
||||
result.Parameters.AddWithValue("?flags", item.Flags);
|
||||
|
||||
lock (database)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
result.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
result.Dispose();
|
||||
|
||||
result = new MySqlCommand("update inventoryfolders set version=version+1 where folderID = ?folderID", database.Connection);
|
||||
result.Parameters.AddWithValue("?folderID", item.Folder.ToString
|
||||
());
|
||||
lock (database)
|
||||
result = new MySqlCommand("update inventoryfolders set version=version+1 where folderID = ?folderID", dbcon);
|
||||
result.Parameters.AddWithValue("?folderID", item.Folder.ToString());
|
||||
lock (m_dbLock)
|
||||
{
|
||||
result.ExecuteNonQuery();
|
||||
}
|
||||
result.Dispose();
|
||||
}
|
||||
}
|
||||
catch (MySqlException e)
|
||||
{
|
||||
m_log.Error(e.ToString());
|
||||
|
@ -672,8 +525,6 @@ namespace OpenSim.Data.MySQL
|
|||
/// <param name="item">Inventory item to update</param>
|
||||
public void updateInventoryItem(InventoryItemBase item)
|
||||
{
|
||||
StoreRollbackItem(item.ID);
|
||||
|
||||
addInventoryItem(item);
|
||||
}
|
||||
|
||||
|
@ -683,25 +534,24 @@ namespace OpenSim.Data.MySQL
|
|||
/// <param name="item">The inventory item UUID to delete</param>
|
||||
public void deleteInventoryItem(UUID itemID)
|
||||
{
|
||||
StoreRollbackItem(itemID);
|
||||
|
||||
try
|
||||
{
|
||||
database.CheckConnection();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
MySqlCommand cmd =
|
||||
new MySqlCommand("DELETE FROM inventoryitems WHERE inventoryID=?uuid", database.Connection);
|
||||
MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryitems WHERE inventoryID=?uuid", dbcon);
|
||||
cmd.Parameters.AddWithValue("?uuid", itemID.ToString());
|
||||
|
||||
lock (database)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (MySqlException e)
|
||||
{
|
||||
database.Reconnect();
|
||||
m_log.Error(e.ToString());
|
||||
m_log.Error(e.Message, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -732,9 +582,11 @@ namespace OpenSim.Data.MySQL
|
|||
m_log.Warn("[INVENTORY DB]: Name field truncated from " + folder.Name.Length + " to " + folderName.Length + " characters on add folder");
|
||||
}
|
||||
|
||||
database.CheckConnection();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
MySqlCommand cmd = new MySqlCommand(sql, database.Connection);
|
||||
MySqlCommand cmd = new MySqlCommand(sql, dbcon);
|
||||
cmd.Parameters.AddWithValue("?folderID", folder.ID.ToString());
|
||||
cmd.Parameters.AddWithValue("?agentID", folder.Owner.ToString());
|
||||
cmd.Parameters.AddWithValue("?parentFolderID", folder.ParentID.ToString());
|
||||
|
@ -744,7 +596,7 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
try
|
||||
{
|
||||
lock (database)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
@ -754,6 +606,7 @@ namespace OpenSim.Data.MySQL
|
|||
m_log.Error(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates an inventory folder
|
||||
|
@ -761,7 +614,6 @@ namespace OpenSim.Data.MySQL
|
|||
/// <param name="folder">Folder to update</param>
|
||||
public void updateInventoryFolder(InventoryFolderBase folder)
|
||||
{
|
||||
StoreRollbackFolder(folder.ID);
|
||||
addInventoryFolder(folder);
|
||||
}
|
||||
|
||||
|
@ -772,20 +624,20 @@ namespace OpenSim.Data.MySQL
|
|||
/// <remarks>UPDATE inventoryfolders SET parentFolderID=?parentFolderID WHERE folderID=?folderID</remarks>
|
||||
public void moveInventoryFolder(InventoryFolderBase folder)
|
||||
{
|
||||
StoreRollbackFolder(folder.ID);
|
||||
|
||||
string sql =
|
||||
"UPDATE inventoryfolders SET parentFolderID=?parentFolderID WHERE folderID=?folderID";
|
||||
|
||||
database.CheckConnection();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
MySqlCommand cmd = new MySqlCommand(sql, database.Connection);
|
||||
MySqlCommand cmd = new MySqlCommand(sql, dbcon);
|
||||
cmd.Parameters.AddWithValue("?folderID", folder.ID.ToString());
|
||||
cmd.Parameters.AddWithValue("?parentFolderID", folder.ParentID.ToString());
|
||||
|
||||
try
|
||||
{
|
||||
lock (database)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
@ -795,6 +647,7 @@ namespace OpenSim.Data.MySQL
|
|||
m_log.Error(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Append a list of all the child folders of a parent folder
|
||||
|
@ -836,54 +689,60 @@ 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;
|
||||
|
||||
database.CheckConnection();
|
||||
lock (m_dbLock)
|
||||
{
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
/* 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", dbcon))
|
||||
{
|
||||
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", dbcon))
|
||||
{
|
||||
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", dbcon))
|
||||
{
|
||||
result.Parameters.AddWithValue("?uuid", parentFolder[0].Owner.ToString());
|
||||
reader = result.ExecuteReader();
|
||||
|
||||
using (MySqlDataReader reader = result.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
InventoryFolderBase curFolder = readInventoryFolder(reader);
|
||||
|
@ -897,8 +756,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
|
||||
|
@ -918,13 +777,14 @@ namespace OpenSim.Data.MySQL
|
|||
if (hashtable.ContainsKey(folders[i].ID))
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -935,25 +795,24 @@ namespace OpenSim.Data.MySQL
|
|||
/// <param name="folderID">the folder UUID</param>
|
||||
protected void deleteOneFolder(UUID folderID)
|
||||
{
|
||||
StoreRollbackFolder(folderID);
|
||||
|
||||
try
|
||||
{
|
||||
database.CheckConnection();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
MySqlCommand cmd =
|
||||
new MySqlCommand("DELETE FROM inventoryfolders WHERE folderID=?uuid", database.Connection);
|
||||
using (MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryfolders WHERE folderID=?uuid", dbcon))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("?uuid", folderID.ToString());
|
||||
|
||||
lock (database)
|
||||
{
|
||||
lock (m_dbLock)
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (MySqlException e)
|
||||
{
|
||||
database.Reconnect();
|
||||
m_log.Error(e.ToString());
|
||||
m_log.Error(e.Message, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -963,30 +822,23 @@ namespace OpenSim.Data.MySQL
|
|||
/// <param name="folderID">the folder UUID</param>
|
||||
protected void deleteItemsInFolder(UUID folderID)
|
||||
{
|
||||
if (rollbackStore)
|
||||
{
|
||||
foreach (InventoryItemBase itemBase in getInventoryInFolder(folderID))
|
||||
{
|
||||
StoreRollbackItem(itemBase.ID);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
database.CheckConnection();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
MySqlCommand cmd =
|
||||
new MySqlCommand("DELETE FROM inventoryitems WHERE parentFolderID=?uuid", database.Connection);
|
||||
using (MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryitems WHERE parentFolderID=?uuid", dbcon))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("?uuid", folderID.ToString());
|
||||
|
||||
lock (database)
|
||||
{
|
||||
lock (m_dbLock)
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (MySqlException e)
|
||||
{
|
||||
database.Reconnect();
|
||||
m_log.Error(e.ToString());
|
||||
}
|
||||
}
|
||||
|
@ -999,60 +851,36 @@ namespace OpenSim.Data.MySQL
|
|||
{
|
||||
List<InventoryFolderBase> subFolders = getFolderHierarchy(folderID);
|
||||
|
||||
// Dont delete in OGM - makes for easier restores if someone sends a malcious command. (just restore the folder entry)
|
||||
if (opengridmode == false)
|
||||
{
|
||||
//Delete all sub-folders
|
||||
foreach (InventoryFolderBase f in subFolders)
|
||||
{
|
||||
StoreRollbackFolder(f.ID);
|
||||
deleteOneFolder(f.ID);
|
||||
|
||||
if (rollbackStore)
|
||||
{
|
||||
foreach (InventoryItemBase itemBase in getInventoryInFolder(f.ID))
|
||||
{
|
||||
StoreRollbackItem(itemBase.ID);
|
||||
}
|
||||
}
|
||||
deleteItemsInFolder(f.ID);
|
||||
}
|
||||
}
|
||||
|
||||
StoreRollbackFolder(folderID);
|
||||
//Delete the actual row
|
||||
deleteOneFolder(folderID);
|
||||
|
||||
// Just delete the folder context in OGM
|
||||
if (opengridmode == false)
|
||||
{
|
||||
if (rollbackStore)
|
||||
{
|
||||
foreach (InventoryItemBase itemBase in getInventoryInFolder(folderID))
|
||||
{
|
||||
StoreRollbackItem(itemBase.ID);
|
||||
}
|
||||
}
|
||||
deleteItemsInFolder(folderID);
|
||||
}
|
||||
}
|
||||
|
||||
public List<InventoryItemBase> fetchActiveGestures(UUID avatarID)
|
||||
{
|
||||
MySqlDataReader result = null;
|
||||
MySqlCommand sqlCmd = null;
|
||||
lock (database)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
try
|
||||
{
|
||||
database.CheckConnection();
|
||||
sqlCmd = new MySqlCommand(
|
||||
"SELECT * FROM inventoryitems WHERE avatarId = ?uuid AND assetType = ?type and flags = 1",
|
||||
database.Connection);
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlCommand sqlCmd = new MySqlCommand(
|
||||
"SELECT * FROM inventoryitems WHERE avatarId = ?uuid AND assetType = ?type and flags = 1", dbcon))
|
||||
{
|
||||
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())
|
||||
{
|
||||
|
@ -1062,17 +890,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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,109 +48,70 @@ namespace OpenSim.Data.MySQL
|
|||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private string m_ConnectionString;
|
||||
|
||||
private MySqlConnection m_Connection = null;
|
||||
private string m_connectionString;
|
||||
private object m_dbLock = new object();
|
||||
|
||||
public void Initialise(string connectionString)
|
||||
{
|
||||
m_ConnectionString = connectionString;
|
||||
m_connectionString = connectionString;
|
||||
|
||||
m_Connection = new MySqlConnection(m_ConnectionString);
|
||||
|
||||
m_Connection.Open();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
// Apply new Migrations
|
||||
//
|
||||
Assembly assem = GetType().Assembly;
|
||||
Migration m = new Migration(m_Connection, assem, "RegionStore");
|
||||
Migration m = new Migration(dbcon, assem, "RegionStore");
|
||||
m.Update();
|
||||
|
||||
// NOTE: This is a very slow query that times out on regions with a lot of prims.
|
||||
// I'm told that it is no longer relevant so it's commented out now, but if it
|
||||
// is relevant it should be added as a console command instead of part of the
|
||||
// startup phase
|
||||
// Clean dropped attachments
|
||||
//
|
||||
//try
|
||||
//{
|
||||
// using (MySqlCommand cmd = m_Connection.CreateCommand())
|
||||
// {
|
||||
// cmd.CommandText = "delete from prims, primshapes using prims " +
|
||||
// "left join primshapes on prims.uuid = primshapes.uuid " +
|
||||
// "where PCode = 9 and State <> 0";
|
||||
// ExecuteNonQuery(cmd);
|
||||
// }
|
||||
//}
|
||||
//catch (MySqlException ex)
|
||||
//{
|
||||
// m_log.Error("[REGION DB]: Error cleaning up dropped attachments: " + ex.Message);
|
||||
//}
|
||||
try
|
||||
{
|
||||
using (MySqlCommand cmd = dbcon.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "delete from prims, primshapes using prims " +
|
||||
"left join primshapes on prims.uuid = primshapes.uuid " +
|
||||
"where PCode = 9 and State <> 0";
|
||||
ExecuteNonQuery(cmd);
|
||||
}
|
||||
}
|
||||
catch (MySqlException ex)
|
||||
{
|
||||
m_log.Error("[REGION DB]: Error cleaning up dropped attachments: " + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IDataReader ExecuteReader(MySqlCommand c)
|
||||
{
|
||||
IDataReader r = null;
|
||||
bool errorSeen = false;
|
||||
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
r = c.ExecuteReader();
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception e)
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
|
||||
m_Connection.Close();
|
||||
m_Connection = (MySqlConnection) ((ICloneable)m_Connection).Clone();
|
||||
m_Connection.Open();
|
||||
c.Connection = m_Connection;
|
||||
|
||||
if (!errorSeen)
|
||||
{
|
||||
errorSeen = true;
|
||||
continue;
|
||||
}
|
||||
m_log.Error("[REGION DB]: MySQL error in ExecuteReader: " + e.Message);
|
||||
throw;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
private void ExecuteNonQuery(MySqlCommand c)
|
||||
{
|
||||
bool errorSeen = false;
|
||||
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
c.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception e)
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
|
||||
m_Connection.Close();
|
||||
m_Connection = (MySqlConnection) ((ICloneable)m_Connection).Clone();
|
||||
m_Connection.Open();
|
||||
c.Connection = m_Connection;
|
||||
|
||||
if (!errorSeen)
|
||||
{
|
||||
errorSeen = true;
|
||||
continue;
|
||||
}
|
||||
m_log.Error("[REGION DB]: MySQL error in ExecuteNonQuery: " + e.Message);
|
||||
throw;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose() {}
|
||||
|
@ -166,80 +127,83 @@ namespace OpenSim.Data.MySQL
|
|||
if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0)
|
||||
return;
|
||||
|
||||
lock (m_Connection)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
MySqlCommand cmd = m_Connection.CreateCommand();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
MySqlCommand cmd = dbcon.CreateCommand();
|
||||
|
||||
foreach (SceneObjectPart prim in obj.Children.Values)
|
||||
{
|
||||
cmd.Parameters.Clear();
|
||||
|
||||
cmd.CommandText = "replace into prims ("+
|
||||
"UUID, CreationDate, "+
|
||||
"Name, Text, Description, "+
|
||||
"SitName, TouchName, ObjectFlags, "+
|
||||
"OwnerMask, NextOwnerMask, GroupMask, "+
|
||||
"EveryoneMask, BaseMask, PositionX, "+
|
||||
"PositionY, PositionZ, GroupPositionX, "+
|
||||
"GroupPositionY, GroupPositionZ, VelocityX, "+
|
||||
"VelocityY, VelocityZ, AngularVelocityX, "+
|
||||
"AngularVelocityY, AngularVelocityZ, "+
|
||||
"AccelerationX, AccelerationY, "+
|
||||
"AccelerationZ, RotationX, "+
|
||||
"RotationY, RotationZ, "+
|
||||
"RotationW, SitTargetOffsetX, "+
|
||||
"SitTargetOffsetY, SitTargetOffsetZ, "+
|
||||
"SitTargetOrientW, SitTargetOrientX, "+
|
||||
"SitTargetOrientY, SitTargetOrientZ, "+
|
||||
"RegionUUID, CreatorID, "+
|
||||
"OwnerID, GroupID, "+
|
||||
"LastOwnerID, SceneGroupID, "+
|
||||
"PayPrice, PayButton1, "+
|
||||
"PayButton2, PayButton3, "+
|
||||
"PayButton4, LoopedSound, "+
|
||||
"LoopedSoundGain, TextureAnimation, "+
|
||||
"OmegaX, OmegaY, OmegaZ, "+
|
||||
"CameraEyeOffsetX, CameraEyeOffsetY, "+
|
||||
"CameraEyeOffsetZ, CameraAtOffsetX, "+
|
||||
"CameraAtOffsetY, CameraAtOffsetZ, "+
|
||||
"ForceMouselook, ScriptAccessPin, "+
|
||||
"AllowedDrop, DieAtEdge, "+
|
||||
"SalePrice, SaleType, "+
|
||||
"ColorR, ColorG, ColorB, ColorA, "+
|
||||
"ParticleSystem, ClickAction, Material, "+
|
||||
"CollisionSound, CollisionSoundVolume, "+
|
||||
"PassTouches, "+
|
||||
"LinkNumber) values (" + "?UUID, "+
|
||||
"?CreationDate, ?Name, ?Text, "+
|
||||
"?Description, ?SitName, ?TouchName, "+
|
||||
"?ObjectFlags, ?OwnerMask, ?NextOwnerMask, "+
|
||||
"?GroupMask, ?EveryoneMask, ?BaseMask, "+
|
||||
"?PositionX, ?PositionY, ?PositionZ, "+
|
||||
"?GroupPositionX, ?GroupPositionY, "+
|
||||
"?GroupPositionZ, ?VelocityX, "+
|
||||
"?VelocityY, ?VelocityZ, ?AngularVelocityX, "+
|
||||
"?AngularVelocityY, ?AngularVelocityZ, "+
|
||||
"?AccelerationX, ?AccelerationY, "+
|
||||
"?AccelerationZ, ?RotationX, "+
|
||||
"?RotationY, ?RotationZ, "+
|
||||
"?RotationW, ?SitTargetOffsetX, "+
|
||||
"?SitTargetOffsetY, ?SitTargetOffsetZ, "+
|
||||
"?SitTargetOrientW, ?SitTargetOrientX, "+
|
||||
"?SitTargetOrientY, ?SitTargetOrientZ, "+
|
||||
"?RegionUUID, ?CreatorID, ?OwnerID, "+
|
||||
"?GroupID, ?LastOwnerID, ?SceneGroupID, "+
|
||||
"?PayPrice, ?PayButton1, ?PayButton2, "+
|
||||
"?PayButton3, ?PayButton4, ?LoopedSound, "+
|
||||
"?LoopedSoundGain, ?TextureAnimation, "+
|
||||
"?OmegaX, ?OmegaY, ?OmegaZ, "+
|
||||
"?CameraEyeOffsetX, ?CameraEyeOffsetY, "+
|
||||
"?CameraEyeOffsetZ, ?CameraAtOffsetX, "+
|
||||
"?CameraAtOffsetY, ?CameraAtOffsetZ, "+
|
||||
"?ForceMouselook, ?ScriptAccessPin, "+
|
||||
"?AllowedDrop, ?DieAtEdge, ?SalePrice, "+
|
||||
"?SaleType, ?ColorR, ?ColorG, "+
|
||||
"?ColorB, ?ColorA, ?ParticleSystem, "+
|
||||
"?ClickAction, ?Material, ?CollisionSound, "+
|
||||
cmd.CommandText = "replace into prims (" +
|
||||
"UUID, CreationDate, " +
|
||||
"Name, Text, Description, " +
|
||||
"SitName, TouchName, ObjectFlags, " +
|
||||
"OwnerMask, NextOwnerMask, GroupMask, " +
|
||||
"EveryoneMask, BaseMask, PositionX, " +
|
||||
"PositionY, PositionZ, GroupPositionX, " +
|
||||
"GroupPositionY, GroupPositionZ, VelocityX, " +
|
||||
"VelocityY, VelocityZ, AngularVelocityX, " +
|
||||
"AngularVelocityY, AngularVelocityZ, " +
|
||||
"AccelerationX, AccelerationY, " +
|
||||
"AccelerationZ, RotationX, " +
|
||||
"RotationY, RotationZ, " +
|
||||
"RotationW, SitTargetOffsetX, " +
|
||||
"SitTargetOffsetY, SitTargetOffsetZ, " +
|
||||
"SitTargetOrientW, SitTargetOrientX, " +
|
||||
"SitTargetOrientY, SitTargetOrientZ, " +
|
||||
"RegionUUID, CreatorID, " +
|
||||
"OwnerID, GroupID, " +
|
||||
"LastOwnerID, SceneGroupID, " +
|
||||
"PayPrice, PayButton1, " +
|
||||
"PayButton2, PayButton3, " +
|
||||
"PayButton4, LoopedSound, " +
|
||||
"LoopedSoundGain, TextureAnimation, " +
|
||||
"OmegaX, OmegaY, OmegaZ, " +
|
||||
"CameraEyeOffsetX, CameraEyeOffsetY, " +
|
||||
"CameraEyeOffsetZ, CameraAtOffsetX, " +
|
||||
"CameraAtOffsetY, CameraAtOffsetZ, " +
|
||||
"ForceMouselook, ScriptAccessPin, " +
|
||||
"AllowedDrop, DieAtEdge, " +
|
||||
"SalePrice, SaleType, " +
|
||||
"ColorR, ColorG, ColorB, ColorA, " +
|
||||
"ParticleSystem, ClickAction, Material, " +
|
||||
"CollisionSound, CollisionSoundVolume, " +
|
||||
"PassTouches, " +
|
||||
"LinkNumber) values (" + "?UUID, " +
|
||||
"?CreationDate, ?Name, ?Text, " +
|
||||
"?Description, ?SitName, ?TouchName, " +
|
||||
"?ObjectFlags, ?OwnerMask, ?NextOwnerMask, " +
|
||||
"?GroupMask, ?EveryoneMask, ?BaseMask, " +
|
||||
"?PositionX, ?PositionY, ?PositionZ, " +
|
||||
"?GroupPositionX, ?GroupPositionY, " +
|
||||
"?GroupPositionZ, ?VelocityX, " +
|
||||
"?VelocityY, ?VelocityZ, ?AngularVelocityX, " +
|
||||
"?AngularVelocityY, ?AngularVelocityZ, " +
|
||||
"?AccelerationX, ?AccelerationY, " +
|
||||
"?AccelerationZ, ?RotationX, " +
|
||||
"?RotationY, ?RotationZ, " +
|
||||
"?RotationW, ?SitTargetOffsetX, " +
|
||||
"?SitTargetOffsetY, ?SitTargetOffsetZ, " +
|
||||
"?SitTargetOrientW, ?SitTargetOrientX, " +
|
||||
"?SitTargetOrientY, ?SitTargetOrientZ, " +
|
||||
"?RegionUUID, ?CreatorID, ?OwnerID, " +
|
||||
"?GroupID, ?LastOwnerID, ?SceneGroupID, " +
|
||||
"?PayPrice, ?PayButton1, ?PayButton2, " +
|
||||
"?PayButton3, ?PayButton4, ?LoopedSound, " +
|
||||
"?LoopedSoundGain, ?TextureAnimation, " +
|
||||
"?OmegaX, ?OmegaY, ?OmegaZ, " +
|
||||
"?CameraEyeOffsetX, ?CameraEyeOffsetY, " +
|
||||
"?CameraEyeOffsetZ, ?CameraAtOffsetX, " +
|
||||
"?CameraAtOffsetY, ?CameraAtOffsetZ, " +
|
||||
"?ForceMouselook, ?ScriptAccessPin, " +
|
||||
"?AllowedDrop, ?DieAtEdge, ?SalePrice, " +
|
||||
"?SaleType, ?ColorR, ?ColorG, " +
|
||||
"?ColorB, ?ColorA, ?ParticleSystem, " +
|
||||
"?ClickAction, ?Material, ?CollisionSound, " +
|
||||
"?CollisionSoundVolume, ?PassTouches, ?LinkNumber)";
|
||||
|
||||
FillPrimCommand(cmd, prim, obj.UUID, regionUUID);
|
||||
|
@ -248,26 +212,26 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
cmd.Parameters.Clear();
|
||||
|
||||
cmd.CommandText = "replace into primshapes ("+
|
||||
"UUID, Shape, ScaleX, ScaleY, "+
|
||||
"ScaleZ, PCode, PathBegin, PathEnd, "+
|
||||
"PathScaleX, PathScaleY, PathShearX, "+
|
||||
"PathShearY, PathSkew, PathCurve, "+
|
||||
"PathRadiusOffset, PathRevolutions, "+
|
||||
"PathTaperX, PathTaperY, PathTwist, "+
|
||||
"PathTwistBegin, ProfileBegin, ProfileEnd, "+
|
||||
"ProfileCurve, ProfileHollow, Texture, "+
|
||||
"ExtraParams, State) values (?UUID, "+
|
||||
"?Shape, ?ScaleX, ?ScaleY, ?ScaleZ, "+
|
||||
"?PCode, ?PathBegin, ?PathEnd, "+
|
||||
"?PathScaleX, ?PathScaleY, "+
|
||||
"?PathShearX, ?PathShearY, "+
|
||||
"?PathSkew, ?PathCurve, ?PathRadiusOffset, "+
|
||||
"?PathRevolutions, ?PathTaperX, "+
|
||||
"?PathTaperY, ?PathTwist, "+
|
||||
"?PathTwistBegin, ?ProfileBegin, "+
|
||||
"?ProfileEnd, ?ProfileCurve, "+
|
||||
"?ProfileHollow, ?Texture, ?ExtraParams, "+
|
||||
cmd.CommandText = "replace into primshapes (" +
|
||||
"UUID, Shape, ScaleX, ScaleY, " +
|
||||
"ScaleZ, PCode, PathBegin, PathEnd, " +
|
||||
"PathScaleX, PathScaleY, PathShearX, " +
|
||||
"PathShearY, PathSkew, PathCurve, " +
|
||||
"PathRadiusOffset, PathRevolutions, " +
|
||||
"PathTaperX, PathTaperY, PathTwist, " +
|
||||
"PathTwistBegin, ProfileBegin, ProfileEnd, " +
|
||||
"ProfileCurve, ProfileHollow, Texture, " +
|
||||
"ExtraParams, State) values (?UUID, " +
|
||||
"?Shape, ?ScaleX, ?ScaleY, ?ScaleZ, " +
|
||||
"?PCode, ?PathBegin, ?PathEnd, " +
|
||||
"?PathScaleX, ?PathScaleY, " +
|
||||
"?PathShearX, ?PathShearY, " +
|
||||
"?PathSkew, ?PathCurve, ?PathRadiusOffset, " +
|
||||
"?PathRevolutions, ?PathTaperX, " +
|
||||
"?PathTaperY, ?PathTwist, " +
|
||||
"?PathTwistBegin, ?ProfileBegin, " +
|
||||
"?ProfileEnd, ?ProfileCurve, " +
|
||||
"?ProfileHollow, ?Texture, ?ExtraParams, " +
|
||||
"?State)";
|
||||
|
||||
FillShapeCommand(cmd, prim);
|
||||
|
@ -277,6 +241,7 @@ namespace OpenSim.Data.MySQL
|
|||
cmd.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveObject(UUID obj, UUID regionUUID)
|
||||
{
|
||||
|
@ -290,9 +255,13 @@ namespace OpenSim.Data.MySQL
|
|||
// cause the loss of a prim, but is cleaner.
|
||||
// It's also faster because it uses the primary key.
|
||||
//
|
||||
lock (m_Connection)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
using (MySqlCommand cmd = m_Connection.CreateCommand())
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlCommand cmd = dbcon.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "select UUID from prims where SceneGroupID= ?UUID";
|
||||
cmd.Parameters.AddWithValue("UUID", obj.ToString());
|
||||
|
@ -308,6 +277,7 @@ namespace OpenSim.Data.MySQL
|
|||
ExecuteNonQuery(cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// there is no way this should be < 1 unless there is
|
||||
// a very corrupt database, but in that case be extra
|
||||
|
@ -326,9 +296,13 @@ namespace OpenSim.Data.MySQL
|
|||
/// <param name="uuid">the Item UUID</param>
|
||||
private void RemoveItems(UUID uuid)
|
||||
{
|
||||
lock (m_Connection)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
using (MySqlCommand cmd = m_Connection.CreateCommand())
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlCommand cmd = dbcon.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "delete from primitems where PrimID = ?PrimID";
|
||||
cmd.Parameters.AddWithValue("PrimID", uuid.ToString());
|
||||
|
@ -337,6 +311,7 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all persisted shapes for a list of prims
|
||||
|
@ -345,11 +320,14 @@ namespace OpenSim.Data.MySQL
|
|||
/// <param name="uuids">the list of UUIDs</param>
|
||||
private void RemoveShapes(List<UUID> uuids)
|
||||
{
|
||||
lock (m_Connection)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
string sql = "delete from primshapes where ";
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlCommand cmd = m_Connection.CreateCommand())
|
||||
using (MySqlCommand cmd = dbcon.CreateCommand())
|
||||
{
|
||||
for (int i = 0; i < uuids.Count; i++)
|
||||
{
|
||||
|
@ -371,6 +349,7 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all persisted items for a list of prims
|
||||
|
@ -379,11 +358,14 @@ namespace OpenSim.Data.MySQL
|
|||
/// <param name="uuids">the list of UUIDs</param>
|
||||
private void RemoveItems(List<UUID> uuids)
|
||||
{
|
||||
lock (m_Connection)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
string sql = "delete from primitems where ";
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlCommand cmd = m_Connection.CreateCommand())
|
||||
using (MySqlCommand cmd = dbcon.CreateCommand())
|
||||
{
|
||||
for (int i = 0; i < uuids.Count; i++)
|
||||
{
|
||||
|
@ -406,6 +388,7 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<SceneObjectGroup> LoadObjects(UUID regionID)
|
||||
{
|
||||
|
@ -417,9 +400,13 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
#region Prim Loading
|
||||
|
||||
lock (m_Connection)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
using (MySqlCommand cmd = m_Connection.CreateCommand())
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlCommand cmd = dbcon.CreateCommand())
|
||||
{
|
||||
cmd.CommandText =
|
||||
"SELECT * FROM prims LEFT JOIN primshapes ON prims.UUID = primshapes.UUID WHERE RegionUUID = ?RegionUUID";
|
||||
|
@ -448,6 +435,7 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Prim Loading
|
||||
|
||||
|
@ -497,9 +485,13 @@ namespace OpenSim.Data.MySQL
|
|||
// list from DB of all prims which have items and
|
||||
// LoadItems only on those
|
||||
List<SceneObjectPart> primsWithInventory = new List<SceneObjectPart>();
|
||||
lock (m_Connection)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
using (MySqlCommand itemCmd = m_Connection.CreateCommand())
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlCommand itemCmd = dbcon.CreateCommand())
|
||||
{
|
||||
itemCmd.CommandText = "SELECT DISTINCT primID FROM primitems";
|
||||
using (IDataReader itemReader = ExecuteReader(itemCmd))
|
||||
|
@ -516,6 +508,7 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (SceneObjectPart prim in primsWithInventory)
|
||||
{
|
||||
|
@ -535,11 +528,15 @@ namespace OpenSim.Data.MySQL
|
|||
/// <param name="prim">The prim</param>
|
||||
private void LoadItems(SceneObjectPart prim)
|
||||
{
|
||||
lock (m_Connection)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
List<TaskInventoryItem> inventory = new List<TaskInventoryItem>();
|
||||
|
||||
using (MySqlCommand cmd = m_Connection.CreateCommand())
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlCommand cmd = dbcon.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "select * from primitems where PrimID = ?PrimID";
|
||||
cmd.Parameters.AddWithValue("PrimID", prim.UUID.ToString());
|
||||
|
@ -555,6 +552,7 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
prim.Inventory.RestoreInventoryItems(inventory);
|
||||
}
|
||||
|
@ -564,9 +562,13 @@ namespace OpenSim.Data.MySQL
|
|||
{
|
||||
m_log.Info("[REGION DB]: Storing terrain");
|
||||
|
||||
lock (m_Connection)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
using (MySqlCommand cmd = m_Connection.CreateCommand())
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlCommand cmd = dbcon.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "delete from terrain where RegionUUID = ?RegionUUID";
|
||||
cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
|
||||
|
@ -583,14 +585,19 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public double[,] LoadTerrain(UUID regionID)
|
||||
{
|
||||
double[,] terrain = null;
|
||||
|
||||
lock (m_Connection)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
using (MySqlCommand cmd = m_Connection.CreateCommand())
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlCommand cmd = dbcon.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "select RegionUUID, Revision, Heightfield " +
|
||||
"from terrain where RegionUUID = ?RegionUUID " +
|
||||
|
@ -625,15 +632,20 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return terrain;
|
||||
}
|
||||
|
||||
public void RemoveLandObject(UUID globalID)
|
||||
{
|
||||
lock (m_Connection)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
using (MySqlCommand cmd = m_Connection.CreateCommand())
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlCommand cmd = dbcon.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "delete from land where UUID = ?UUID";
|
||||
cmd.Parameters.AddWithValue("UUID", globalID.ToString());
|
||||
|
@ -642,12 +654,17 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void StoreLandObject(ILandObject parcel)
|
||||
{
|
||||
lock (m_Connection)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
using (MySqlCommand cmd = m_Connection.CreateCommand())
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlCommand cmd = dbcon.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "replace into land (UUID, RegionUUID, " +
|
||||
"LocalLandID, Bitmap, Name, Description, " +
|
||||
|
@ -692,14 +709,19 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public RegionSettings LoadRegionSettings(UUID regionUUID)
|
||||
{
|
||||
RegionSettings rs = null;
|
||||
|
||||
lock (m_Connection)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
using (MySqlCommand cmd = m_Connection.CreateCommand())
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlCommand cmd = dbcon.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "select * from regionsettings where regionUUID = ?RegionUUID";
|
||||
cmd.Parameters.AddWithValue("regionUUID", regionUUID);
|
||||
|
@ -722,15 +744,20 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rs;
|
||||
}
|
||||
|
||||
public void StoreRegionSettings(RegionSettings rs)
|
||||
{
|
||||
lock (m_Connection)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
using (MySqlCommand cmd = m_Connection.CreateCommand())
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlCommand cmd = dbcon.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "replace into regionsettings (regionUUID, " +
|
||||
"block_terraform, block_fly, allow_damage, " +
|
||||
|
@ -771,14 +798,19 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<LandData> LoadLandObjects(UUID regionUUID)
|
||||
{
|
||||
List<LandData> landData = new List<LandData>();
|
||||
|
||||
lock (m_Connection)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
using (MySqlCommand cmd = m_Connection.CreateCommand())
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlCommand cmd = dbcon.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "select * from land where RegionUUID = ?RegionUUID";
|
||||
cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
|
||||
|
@ -793,7 +825,7 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
}
|
||||
|
||||
using (MySqlCommand cmd = m_Connection.CreateCommand())
|
||||
using (MySqlCommand cmd = dbcon.CreateCommand())
|
||||
{
|
||||
foreach (LandData land in landData)
|
||||
{
|
||||
|
@ -811,6 +843,7 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return landData;
|
||||
}
|
||||
|
@ -1513,29 +1546,33 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
|
||||
{
|
||||
lock (m_Connection)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
RemoveItems(primID);
|
||||
|
||||
MySqlCommand cmd = m_Connection.CreateCommand();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
MySqlCommand cmd = dbcon.CreateCommand();
|
||||
|
||||
if (items.Count == 0)
|
||||
return;
|
||||
|
||||
cmd.CommandText = "insert into primitems ("+
|
||||
"invType, assetType, name, "+
|
||||
"description, creationDate, nextPermissions, "+
|
||||
"currentPermissions, basePermissions, "+
|
||||
"everyonePermissions, groupPermissions, "+
|
||||
"flags, itemID, primID, assetID, "+
|
||||
"parentFolderID, creatorID, ownerID, "+
|
||||
"groupID, lastOwnerID) values (?invType, "+
|
||||
"?assetType, ?name, ?description, "+
|
||||
"?creationDate, ?nextPermissions, "+
|
||||
"?currentPermissions, ?basePermissions, "+
|
||||
"?everyonePermissions, ?groupPermissions, "+
|
||||
"?flags, ?itemID, ?primID, ?assetID, "+
|
||||
"?parentFolderID, ?creatorID, ?ownerID, "+
|
||||
cmd.CommandText = "insert into primitems (" +
|
||||
"invType, assetType, name, " +
|
||||
"description, creationDate, nextPermissions, " +
|
||||
"currentPermissions, basePermissions, " +
|
||||
"everyonePermissions, groupPermissions, " +
|
||||
"flags, itemID, primID, assetID, " +
|
||||
"parentFolderID, creatorID, ownerID, " +
|
||||
"groupID, lastOwnerID) values (?invType, " +
|
||||
"?assetType, ?name, ?description, " +
|
||||
"?creationDate, ?nextPermissions, " +
|
||||
"?currentPermissions, ?basePermissions, " +
|
||||
"?everyonePermissions, ?groupPermissions, " +
|
||||
"?flags, ?itemID, ?primID, ?assetID, " +
|
||||
"?parentFolderID, ?creatorID, ?ownerID, " +
|
||||
"?groupID, ?lastOwnerID)";
|
||||
|
||||
foreach (TaskInventoryItem item in items)
|
||||
|
@ -1551,4 +1588,5 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,14 +79,19 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
// This actually does the roll forward assembly stuff
|
||||
Assembly assem = GetType().Assembly;
|
||||
Migration m = new Migration(database.Connection, assem, "LogStore");
|
||||
|
||||
using (MySql.Data.MySqlClient.MySqlConnection dbcon = new MySql.Data.MySqlClient.MySqlConnection(connect))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
Migration m = new Migration(dbcon, assem, "LogStore");
|
||||
|
||||
// TODO: After rev 6000, remove this. People should have
|
||||
// been rolled onto the new migration code by then.
|
||||
TestTables(m);
|
||||
|
||||
m.Update();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary></summary>
|
||||
|
@ -128,7 +133,6 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
catch
|
||||
{
|
||||
database.Reconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,16 +45,13 @@ namespace OpenSim.Data.MySQL
|
|||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
/// <summary>
|
||||
/// The database connection object
|
||||
/// </summary>
|
||||
private MySqlConnection dbcon;
|
||||
|
||||
/// <summary>
|
||||
/// Connection string for ADO.net
|
||||
/// </summary>
|
||||
private string connectionString;
|
||||
|
||||
private object m_dbLock = new object();
|
||||
|
||||
private const string m_waitTimeoutSelect = "select @@wait_timeout";
|
||||
|
||||
/// <summary>
|
||||
|
@ -109,11 +106,11 @@ namespace OpenSim.Data.MySQL
|
|||
try
|
||||
{
|
||||
connectionString = connect;
|
||||
dbcon = new MySqlConnection(connectionString);
|
||||
//dbcon = new MySqlConnection(connectionString);
|
||||
|
||||
try
|
||||
{
|
||||
dbcon.Open();
|
||||
//dbcon.Open();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
|
@ -134,8 +131,12 @@ namespace OpenSim.Data.MySQL
|
|||
/// </summary>
|
||||
protected void GetWaitTimeout()
|
||||
{
|
||||
MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect, dbcon);
|
||||
using (MySqlConnection dbcon = new MySqlConnection(connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect, dbcon))
|
||||
{
|
||||
using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
|
||||
{
|
||||
if (dbReader.Read())
|
||||
|
@ -143,9 +144,8 @@ namespace OpenSim.Data.MySQL
|
|||
m_waitTimeout
|
||||
= Convert.ToInt32(dbReader["@@wait_timeout"]) * TimeSpan.TicksPerSecond + m_waitTimeoutLeeway;
|
||||
}
|
||||
|
||||
dbReader.Close();
|
||||
cmd.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_lastConnectionUse = DateTime.Now.Ticks;
|
||||
|
@ -154,66 +154,9 @@ namespace OpenSim.Data.MySQL
|
|||
"[REGION DB]: Connection wait timeout {0} seconds", m_waitTimeout / TimeSpan.TicksPerSecond);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Should be called before any db operation. This checks to see if the connection has not timed out
|
||||
/// </summary>
|
||||
public void CheckConnection()
|
||||
public string ConnectionString
|
||||
{
|
||||
//m_log.Debug("[REGION DB]: Checking connection");
|
||||
|
||||
long timeNow = DateTime.Now.Ticks;
|
||||
if (timeNow - m_lastConnectionUse > m_waitTimeout || dbcon.State != ConnectionState.Open)
|
||||
{
|
||||
m_log.DebugFormat("[REGION DB]: Database connection has gone away - reconnecting");
|
||||
Reconnect();
|
||||
}
|
||||
|
||||
// Strictly, we should set this after the actual db operation. But it's more convenient to set here rather
|
||||
// than require the code to call another method - the timeout leeway should be large enough to cover the
|
||||
// inaccuracy.
|
||||
m_lastConnectionUse = timeNow;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the connection being used
|
||||
/// </summary>
|
||||
/// <returns>MySqlConnection Object</returns>
|
||||
public MySqlConnection Connection
|
||||
{
|
||||
get { return dbcon; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shuts down the database connection
|
||||
/// </summary>
|
||||
public void Close()
|
||||
{
|
||||
dbcon.Close();
|
||||
dbcon = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reconnects to the database
|
||||
/// </summary>
|
||||
public void Reconnect()
|
||||
{
|
||||
m_log.Info("[REGION DB] Reconnecting database");
|
||||
|
||||
lock (dbcon)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Close the DB connection
|
||||
dbcon.Close();
|
||||
// Try reopen it
|
||||
dbcon = new MySqlConnection(connectionString);
|
||||
dbcon.Open();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error("Unable to reconnect to database " + e.ToString());
|
||||
}
|
||||
}
|
||||
get { return connectionString; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -264,10 +207,14 @@ namespace OpenSim.Data.MySQL
|
|||
/// <param name="name">name of embedded resource</param>
|
||||
public void ExecuteResourceSql(string name)
|
||||
{
|
||||
CheckConnection();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
MySqlCommand cmd = new MySqlCommand(getResourceString(name), dbcon);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Execute a MySqlCommand
|
||||
|
@ -275,14 +222,20 @@ namespace OpenSim.Data.MySQL
|
|||
/// <param name="sql">sql string to execute</param>
|
||||
public void ExecuteSql(string sql)
|
||||
{
|
||||
CheckConnection();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
MySqlCommand cmd = new MySqlCommand(sql, dbcon);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
public void ExecuteParameterizedSql(string sql, Dictionary<string, string> parameters)
|
||||
{
|
||||
CheckConnection();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
MySqlCommand cmd = (MySqlCommand)dbcon.CreateCommand();
|
||||
cmd.CommandText = sql;
|
||||
|
@ -292,6 +245,7 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Given a list of tables, return the version of the tables, as seen in the database
|
||||
|
@ -299,14 +253,15 @@ namespace OpenSim.Data.MySQL
|
|||
/// <param name="tableList"></param>
|
||||
public void GetTableVersion(Dictionary<string, string> tableList)
|
||||
{
|
||||
lock (dbcon)
|
||||
lock (m_dbLock)
|
||||
{
|
||||
CheckConnection();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
MySqlCommand tablesCmd =
|
||||
new MySqlCommand(
|
||||
"SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=?dbname",
|
||||
dbcon);
|
||||
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);
|
||||
|
||||
using (MySqlDataReader tables = tablesCmd.ExecuteReader())
|
||||
|
@ -315,8 +270,8 @@ namespace OpenSim.Data.MySQL
|
|||
{
|
||||
try
|
||||
{
|
||||
string tableName = (string) tables["TABLE_NAME"];
|
||||
string comment = (string) tables["TABLE_COMMENT"];
|
||||
string tableName = (string)tables["TABLE_NAME"];
|
||||
string comment = (string)tables["TABLE_COMMENT"];
|
||||
if (tableList.ContainsKey(tableName))
|
||||
{
|
||||
tableList[tableName] = comment;
|
||||
|
@ -324,10 +279,11 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error(e.ToString());
|
||||
m_log.Error(e.Message, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
tables.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -337,28 +293,27 @@ namespace OpenSim.Data.MySQL
|
|||
/// <summary>
|
||||
/// Runs a query with protection against SQL Injection by using parameterised input.
|
||||
/// </summary>
|
||||
/// <param name="dbcon">Database connection</param>
|
||||
/// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param>
|
||||
/// <param name="parameters">The parameters - index so that @y is indexed as 'y'</param>
|
||||
/// <returns>A MySQL DB Command</returns>
|
||||
public IDbCommand Query(string sql, Dictionary<string, object> parameters)
|
||||
public IDbCommand Query(MySqlConnection dbcon, string sql, Dictionary<string, object> parameters)
|
||||
{
|
||||
try
|
||||
{
|
||||
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.ToString());
|
||||
m_log.Error("Failed during Query generation: " + e.Message, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -694,8 +649,6 @@ namespace OpenSim.Data.MySQL
|
|||
ret.Add(attachpoint, item);
|
||||
}
|
||||
|
||||
r.Close();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -727,13 +680,18 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
try
|
||||
{
|
||||
IDbCommand result = Query(sql, parameters);
|
||||
using (MySqlConnection dbcon = new MySqlConnection(connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
IDbCommand result = Query(dbcon, sql, parameters);
|
||||
|
||||
if (result.ExecuteNonQuery() == 1)
|
||||
returnval = true;
|
||||
|
||||
result.Dispose();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error(e.ToString());
|
||||
|
@ -828,13 +786,18 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
try
|
||||
{
|
||||
IDbCommand result = Query(sql, parameters);
|
||||
using (MySqlConnection dbcon = new MySqlConnection(connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
IDbCommand result = Query(dbcon, sql, parameters);
|
||||
|
||||
if (result.ExecuteNonQuery() == 1)
|
||||
returnval = true;
|
||||
|
||||
result.Dispose();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error(e.ToString());
|
||||
|
@ -927,13 +890,18 @@ namespace OpenSim.Data.MySQL
|
|||
bool returnval = false;
|
||||
try
|
||||
{
|
||||
IDbCommand result = Query(sql, parameters);
|
||||
using (MySqlConnection dbcon = new MySqlConnection(connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
IDbCommand result = Query(dbcon, sql, parameters);
|
||||
|
||||
if (result.ExecuteNonQuery() == 1)
|
||||
returnval = true;
|
||||
|
||||
result.Dispose();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error(e.ToString());
|
||||
|
@ -1030,7 +998,11 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
try
|
||||
{
|
||||
IDbCommand result = Query(sql, parameters);
|
||||
using (MySqlConnection dbcon = new MySqlConnection(connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
IDbCommand result = Query(dbcon, sql, parameters);
|
||||
|
||||
// int x;
|
||||
// if ((x = result.ExecuteNonQuery()) > 0)
|
||||
|
@ -1043,6 +1015,7 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
result.Dispose();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error(e.ToString());
|
||||
|
@ -1070,7 +1043,11 @@ namespace OpenSim.Data.MySQL
|
|||
{
|
||||
parameters["?uuid"] = uuid;
|
||||
|
||||
IDbCommand result = Query(sql, parameters);
|
||||
using (MySqlConnection dbcon = new MySqlConnection(connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
IDbCommand result = Query(dbcon, sql, parameters);
|
||||
|
||||
// int x;
|
||||
// if ((x = result.ExecuteNonQuery()) > 0)
|
||||
|
@ -1083,6 +1060,7 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
result.Dispose();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error(e.ToString());
|
||||
|
@ -1122,7 +1100,11 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
try
|
||||
{
|
||||
IDbCommand result = Query(sql, parameters);
|
||||
using (MySqlConnection dbcon = new MySqlConnection(connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
IDbCommand result = Query(dbcon, sql, parameters);
|
||||
|
||||
// int x;
|
||||
// if ((x = result.ExecuteNonQuery()) > 0)
|
||||
|
@ -1135,6 +1117,7 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
result.Dispose();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error(e.ToString());
|
||||
|
@ -1167,8 +1150,14 @@ namespace OpenSim.Data.MySQL
|
|||
bool returnval = false;
|
||||
|
||||
// we want to send in byte data, which means we can't just pass down strings
|
||||
try {
|
||||
MySqlCommand cmd = (MySqlCommand) dbcon.CreateCommand();
|
||||
try
|
||||
{
|
||||
using (MySqlConnection dbcon = new MySqlConnection(connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlCommand cmd = (MySqlCommand)dbcon.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = sql;
|
||||
cmd.Parameters.AddWithValue("?owner", appearance.Owner.ToString());
|
||||
cmd.Parameters.AddWithValue("?serial", appearance.Serial);
|
||||
|
@ -1204,8 +1193,8 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
if (cmd.ExecuteNonQuery() > 0)
|
||||
returnval = true;
|
||||
|
||||
cmd.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -1221,7 +1210,11 @@ namespace OpenSim.Data.MySQL
|
|||
{
|
||||
string sql = "delete from avatarattachments where UUID = ?uuid";
|
||||
|
||||
MySqlCommand cmd = (MySqlCommand) dbcon.CreateCommand();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
MySqlCommand cmd = (MySqlCommand)dbcon.CreateCommand();
|
||||
cmd.CommandText = sql;
|
||||
cmd.Parameters.AddWithValue("?uuid", agentID.ToString());
|
||||
|
||||
|
@ -1232,7 +1225,7 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
sql = "insert into avatarattachments (UUID, attachpoint, item, asset) values (?uuid, ?attachpoint, ?item, ?asset)";
|
||||
|
||||
cmd = (MySqlCommand) dbcon.CreateCommand();
|
||||
cmd = (MySqlCommand)dbcon.CreateCommand();
|
||||
cmd.CommandText = sql;
|
||||
|
||||
foreach (DictionaryEntry e in data)
|
||||
|
@ -1251,4 +1244,5 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,17 +38,22 @@ namespace OpenSim.Data.MySQL
|
|||
public class MySqlRegionData : MySqlFramework, IRegionData
|
||||
{
|
||||
private string m_Realm;
|
||||
private List<string> m_ColumnNames = null;
|
||||
// private int m_LastExpire = 0;
|
||||
private List<string> m_ColumnNames;
|
||||
//private string m_connectionString;
|
||||
|
||||
public MySqlRegionData(string connectionString, string realm)
|
||||
: base(connectionString)
|
||||
{
|
||||
m_Realm = realm;
|
||||
m_connectionString = connectionString;
|
||||
|
||||
Migration m = new Migration(m_Connection, GetType().Assembly, "GridStore");
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
Migration m = new Migration(dbcon, GetType().Assembly, "GridStore");
|
||||
m.Update();
|
||||
}
|
||||
}
|
||||
|
||||
public List<RegionData> Get(string regionName, UUID scopeID)
|
||||
{
|
||||
|
@ -56,13 +61,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 +76,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 +88,7 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
return ret[0];
|
||||
}
|
||||
}
|
||||
|
||||
public RegionData Get(UUID regionID, UUID scopeID)
|
||||
{
|
||||
|
@ -89,8 +96,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 +107,7 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
return ret[0];
|
||||
}
|
||||
}
|
||||
|
||||
public List<RegionData> Get(int startX, int startY, int endX, int endY, UUID scopeID)
|
||||
{
|
||||
|
@ -107,8 +115,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 +125,19 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
return RunCommand(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
public List<RegionData> RunCommand(MySqlCommand cmd)
|
||||
{
|
||||
List<RegionData> retList = new List<RegionData>();
|
||||
|
||||
IDataReader result = ExecuteReader(cmd);
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
cmd.Connection = dbcon;
|
||||
|
||||
using (IDataReader result = cmd.ExecuteReader())
|
||||
{
|
||||
while (result.Read())
|
||||
{
|
||||
RegionData ret = new RegionData();
|
||||
|
@ -171,9 +185,8 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
retList.Add(ret);
|
||||
}
|
||||
|
||||
result.Close();
|
||||
CloseReaderCommand(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
return retList;
|
||||
}
|
||||
|
@ -201,15 +214,15 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
string[] fields = new List<string>(data.Data.Keys).ToArray();
|
||||
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
|
||||
string update = "update `"+m_Realm+"` set locX=?posX, locY=?posY, sizeX=?sizeX, sizeY=?sizeY";
|
||||
using (MySqlCommand cmd = new MySqlCommand())
|
||||
{
|
||||
string update = "update `" + m_Realm + "` set locX=?posX, locY=?posY, sizeX=?sizeX, sizeY=?sizeY";
|
||||
foreach (string field in fields)
|
||||
{
|
||||
update += ", ";
|
||||
update += "`" + field + "` = ?"+field;
|
||||
update += "`" + field + "` = ?" + field;
|
||||
|
||||
cmd.Parameters.AddWithValue("?"+field, data.Data[field]);
|
||||
cmd.Parameters.AddWithValue("?" + field, data.Data[field]);
|
||||
}
|
||||
|
||||
update += " where uuid = ?regionID";
|
||||
|
@ -236,41 +249,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");
|
||||
|
||||
|
||||
cmd.Parameters.AddWithValue("?"+item, 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());
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -38,17 +38,22 @@ namespace OpenSim.Data.MySQL
|
|||
public class MySqlUserAccountData : MySqlFramework, IUserAccountData
|
||||
{
|
||||
private string m_Realm;
|
||||
private List<string> m_ColumnNames = null;
|
||||
// private int m_LastExpire = 0;
|
||||
private List<string> m_ColumnNames;
|
||||
// private string m_connectionString;
|
||||
|
||||
public MySqlUserAccountData(string connectionString, string realm)
|
||||
: base(connectionString)
|
||||
{
|
||||
m_Realm = realm;
|
||||
m_connectionString = connectionString;
|
||||
|
||||
Migration m = new Migration(m_Connection, GetType().Assembly, "UserStore");
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
Migration m = new Migration(dbcon, GetType().Assembly, "UserStore");
|
||||
m.Update();
|
||||
}
|
||||
}
|
||||
|
||||
public List<UserAccountData> Query(UUID principalID, UUID scopeID, string query)
|
||||
{
|
||||
|
@ -64,12 +69,15 @@ namespace OpenSim.Data.MySQL
|
|||
if (scopeID != UUID.Zero)
|
||||
command += " and ScopeID = ?scopeID";
|
||||
|
||||
MySqlCommand cmd = new MySqlCommand(command);
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
MySqlCommand cmd = new MySqlCommand(command, dbcon);
|
||||
|
||||
cmd.Parameters.AddWithValue("?principalID", principalID.ToString());
|
||||
cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
|
||||
|
||||
IDataReader result = ExecuteReader(cmd);
|
||||
IDataReader result = cmd.ExecuteReader();
|
||||
|
||||
if (result.Read())
|
||||
{
|
||||
|
@ -97,17 +105,14 @@ namespace OpenSim.Data.MySQL
|
|||
ret.Data[s] = result[s].ToString();
|
||||
}
|
||||
|
||||
result.Close();
|
||||
CloseReaderCommand(cmd);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
result.Close();
|
||||
CloseReaderCommand(cmd);
|
||||
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Store(UserAccountData data)
|
||||
{
|
||||
|
@ -118,19 +123,19 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
string[] fields = new List<string>(data.Data.Keys).ToArray();
|
||||
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
|
||||
string update = "update `"+m_Realm+"` set ";
|
||||
using (MySqlCommand cmd = new MySqlCommand())
|
||||
{
|
||||
string update = "update `" + m_Realm + "` set ";
|
||||
bool first = true;
|
||||
foreach (string field in fields)
|
||||
{
|
||||
if (!first)
|
||||
update += ", ";
|
||||
update += "`" + field + "` = ?"+field;
|
||||
update += "`" + field + "` = ?" + field;
|
||||
|
||||
first = false;
|
||||
|
||||
cmd.Parameters.AddWithValue("?"+field, data.Data[field]);
|
||||
cmd.Parameters.AddWithValue("?" + field, data.Data[field]);
|
||||
}
|
||||
|
||||
update += " where UUID = ?principalID";
|
||||
|
@ -156,23 +161,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");
|
||||
|
||||
|
||||
cmd.Parameters.AddWithValue("?"+item, 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());
|
||||
|
||||
if (ExecuteNonQuery(cmd) > 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ using System.Reflection;
|
|||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using log4net;
|
||||
using MySql.Data.MySqlClient;
|
||||
using OpenMetaverse;
|
||||
using OpenSim.Framework;
|
||||
|
||||
|
@ -45,15 +46,9 @@ namespace OpenSim.Data.MySQL
|
|||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
/// <summary>
|
||||
/// Database manager for MySQL
|
||||
/// </summary>
|
||||
public MySQLManager database;
|
||||
|
||||
/// <summary>
|
||||
/// Better DB manager. Swap-in replacement too.
|
||||
/// </summary>
|
||||
public Dictionary<int, MySQLSuperManager> m_dbconnections = new Dictionary<int, MySQLSuperManager>();
|
||||
private MySQLManager m_database;
|
||||
private string m_connectionString;
|
||||
private object m_dbLock = new object();
|
||||
|
||||
public int m_maxConnections = 10;
|
||||
public int m_lastConnect;
|
||||
|
@ -63,7 +58,6 @@ namespace OpenSim.Data.MySQL
|
|||
private string m_userFriendsTableName = "userfriends";
|
||||
private string m_appearanceTableName = "avatarappearance";
|
||||
private string m_attachmentsTableName = "avatarattachments";
|
||||
private string m_connectString;
|
||||
|
||||
public override void Initialise()
|
||||
{
|
||||
|
@ -71,41 +65,6 @@ namespace OpenSim.Data.MySQL
|
|||
throw new PluginNotInitialisedException(Name);
|
||||
}
|
||||
|
||||
public MySQLSuperManager GetLockedConnection(string why)
|
||||
{
|
||||
int lockedCons = 0;
|
||||
while (true)
|
||||
{
|
||||
m_lastConnect++;
|
||||
|
||||
// Overflow protection
|
||||
if (m_lastConnect == int.MaxValue)
|
||||
m_lastConnect = 0;
|
||||
|
||||
MySQLSuperManager x = m_dbconnections[m_lastConnect%m_maxConnections];
|
||||
if (!x.Locked)
|
||||
{
|
||||
x.GetLock();
|
||||
x.Running = why;
|
||||
return x;
|
||||
}
|
||||
|
||||
lockedCons++;
|
||||
if (lockedCons > m_maxConnections)
|
||||
{
|
||||
lockedCons = 0;
|
||||
Thread.Sleep(1000); // Wait some time before searching them again.
|
||||
m_log.Debug(
|
||||
"WARNING: All threads are in use. Probable cause: Something didnt release a mutex properly, or high volume of requests inbound.");
|
||||
m_log.Debug("Current connections-in-use dump:");
|
||||
foreach (KeyValuePair<int, MySQLSuperManager> kvp in m_dbconnections)
|
||||
{
|
||||
m_log.Debug(kvp.Value.Running);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialise User Interface
|
||||
/// Loads and initialises the MySQL storage plugin
|
||||
|
@ -115,56 +74,19 @@ namespace OpenSim.Data.MySQL
|
|||
/// <param name="connect">connect string.</param>
|
||||
public override void Initialise(string connect)
|
||||
{
|
||||
if (connect == String.Empty)
|
||||
{
|
||||
// TODO: actually do something with our connect string
|
||||
// instead of loading the second config
|
||||
|
||||
m_log.Warn("Using obsoletely mysql_connection.ini, try using user_source connect string instead");
|
||||
IniFile iniFile = new IniFile("mysql_connection.ini");
|
||||
string settingHostname = iniFile.ParseFileReadValue("hostname");
|
||||
string settingDatabase = iniFile.ParseFileReadValue("database");
|
||||
string settingUsername = iniFile.ParseFileReadValue("username");
|
||||
string settingPassword = iniFile.ParseFileReadValue("password");
|
||||
string settingPooling = iniFile.ParseFileReadValue("pooling");
|
||||
string settingPort = iniFile.ParseFileReadValue("port");
|
||||
|
||||
m_connectString = "Server=" + settingHostname + ";Port=" + settingPort + ";Database=" + settingDatabase +
|
||||
";User ID=" +
|
||||
settingUsername + ";Password=" + settingPassword + ";Pooling=" + settingPooling + ";";
|
||||
|
||||
m_log.Info("Creating " + m_maxConnections + " DB connections...");
|
||||
for (int i = 0; i < m_maxConnections; i++)
|
||||
{
|
||||
m_log.Info("Connecting to DB... [" + i + "]");
|
||||
MySQLSuperManager msm = new MySQLSuperManager();
|
||||
msm.Manager = new MySQLManager(m_connectString);
|
||||
m_dbconnections.Add(i, msm);
|
||||
}
|
||||
|
||||
database = new MySQLManager(m_connectString);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_connectString = connect;
|
||||
database = new MySQLManager(m_connectString);
|
||||
|
||||
m_log.Info("Creating " + m_maxConnections + " DB connections...");
|
||||
for (int i = 0; i < m_maxConnections; i++)
|
||||
{
|
||||
m_log.Info("Connecting to DB... [" + i + "]");
|
||||
MySQLSuperManager msm = new MySQLSuperManager();
|
||||
msm.Manager = new MySQLManager(m_connectString);
|
||||
m_dbconnections.Add(i, msm);
|
||||
}
|
||||
}
|
||||
m_connectionString = connect;
|
||||
m_database = new MySQLManager(connect);
|
||||
|
||||
// This actually does the roll forward assembly stuff
|
||||
Assembly assem = GetType().Assembly;
|
||||
Migration m = new Migration(database.Connection, assem, "UserStore");
|
||||
|
||||
using (MySql.Data.MySqlClient.MySqlConnection dbcon = new MySql.Data.MySqlClient.MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
Migration m = new Migration(dbcon, assem, "UserStore");
|
||||
m.Update();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
|
@ -173,35 +95,32 @@ namespace OpenSim.Data.MySQL
|
|||
// see IUserDataPlugin
|
||||
public override UserProfileData GetUserByName(string user, string last)
|
||||
{
|
||||
MySQLSuperManager dbm = GetLockedConnection("GetUserByName");
|
||||
|
||||
try
|
||||
{
|
||||
Dictionary<string, object> param = new Dictionary<string, object>();
|
||||
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 (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
UserProfileData row = dbm.Manager.readUserRow(reader);
|
||||
|
||||
reader.Dispose();
|
||||
result.Dispose();
|
||||
using (IDbCommand result = m_database.Query(dbcon,
|
||||
"SELECT * FROM " + m_usersTableName + " WHERE username = ?first AND lastname = ?second", param))
|
||||
{
|
||||
using (IDataReader reader = result.ExecuteReader())
|
||||
{
|
||||
UserProfileData row = m_database.readUserRow(reader);
|
||||
return row;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
dbm.Manager.Reconnect();
|
||||
m_log.Error(e.ToString());
|
||||
m_log.Error(e.Message, e);
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
dbm.Release();
|
||||
}
|
||||
}
|
||||
|
||||
#region User Friends List Data
|
||||
|
@ -216,38 +135,38 @@ namespace OpenSim.Data.MySQL
|
|||
param["?friendPerms"] = perms.ToString();
|
||||
param["?datetimestamp"] = dtvalue.ToString();
|
||||
|
||||
MySQLSuperManager dbm = GetLockedConnection("AddNewUserFriend");
|
||||
|
||||
try
|
||||
{
|
||||
IDbCommand adder =
|
||||
dbm.Manager.Query(
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (IDbCommand adder = m_database.Query(dbcon,
|
||||
"INSERT INTO `" + m_userFriendsTableName + "` " +
|
||||
"(`ownerID`,`friendID`,`friendPerms`,`datetimestamp`) " +
|
||||
"VALUES " +
|
||||
"(?ownerID,?friendID,?friendPerms,?datetimestamp)",
|
||||
param);
|
||||
param))
|
||||
{
|
||||
adder.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
adder =
|
||||
dbm.Manager.Query(
|
||||
using (IDbCommand adder = m_database.Query(dbcon,
|
||||
"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
|
||||
{
|
||||
dbm.Release();
|
||||
}
|
||||
}
|
||||
|
||||
public override void RemoveUserFriend(UUID friendlistowner, UUID friend)
|
||||
|
@ -256,32 +175,32 @@ namespace OpenSim.Data.MySQL
|
|||
param["?ownerID"] = friendlistowner.ToString();
|
||||
param["?friendID"] = friend.ToString();
|
||||
|
||||
MySQLSuperManager dbm = GetLockedConnection("RemoveUserFriend");
|
||||
|
||||
try
|
||||
{
|
||||
IDbCommand updater =
|
||||
dbm.Manager.Query(
|
||||
"delete from " + m_userFriendsTableName + " where ownerID = ?ownerID and friendID = ?friendID",
|
||||
param);
|
||||
updater.ExecuteNonQuery();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
updater =
|
||||
dbm.Manager.Query(
|
||||
"delete from " + m_userFriendsTableName + " where ownerID = ?friendID and friendID = ?ownerID",
|
||||
param);
|
||||
using (IDbCommand updater = m_database.Query(dbcon,
|
||||
"delete from " + m_userFriendsTableName + " where ownerID = ?ownerID and friendID = ?friendID",
|
||||
param))
|
||||
{
|
||||
updater.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
using (IDbCommand updater = m_database.Query(dbcon,
|
||||
"delete from " + m_userFriendsTableName + " where ownerID = ?friendID and friendID = ?ownerID",
|
||||
param))
|
||||
{
|
||||
updater.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
dbm.Manager.Reconnect();
|
||||
m_log.Error(e.ToString());
|
||||
m_log.Error(e.Message, e);
|
||||
return;
|
||||
}
|
||||
finally
|
||||
{
|
||||
dbm.Release();
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms)
|
||||
|
@ -291,28 +210,27 @@ namespace OpenSim.Data.MySQL
|
|||
param["?friendID"] = friend.ToString();
|
||||
param["?friendPerms"] = perms.ToString();
|
||||
|
||||
MySQLSuperManager dbm = GetLockedConnection("UpdateUserFriendPerms");
|
||||
|
||||
try
|
||||
{
|
||||
IDbCommand updater =
|
||||
dbm.Manager.Query(
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (IDbCommand updater = m_database.Query(dbcon,
|
||||
"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
|
||||
{
|
||||
dbm.Release();
|
||||
}
|
||||
}
|
||||
|
||||
public override List<FriendListItem> GetUserFriendList(UUID friendlistowner)
|
||||
|
@ -322,65 +240,66 @@ namespace OpenSim.Data.MySQL
|
|||
Dictionary<string, object> param = new Dictionary<string, object>();
|
||||
param["?ownerID"] = friendlistowner.ToString();
|
||||
|
||||
MySQLSuperManager dbm = GetLockedConnection("GetUserFriendList");
|
||||
|
||||
try
|
||||
{
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
//Left Join userfriends to itself
|
||||
IDbCommand result =
|
||||
dbm.Manager.Query(
|
||||
using (IDbCommand result = m_database.Query(dbcon,
|
||||
"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();
|
||||
fli.FriendListOwner = new UUID((string) reader["ownerID"]);
|
||||
fli.Friend = new UUID((string) reader["friendID"]);
|
||||
fli.FriendPerms = (uint) Convert.ToInt32(reader["friendPerms"]);
|
||||
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"]);
|
||||
fli.FriendListOwnerPerms = (uint)Convert.ToInt32(reader["ownerperms"]);
|
||||
|
||||
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
|
||||
{
|
||||
dbm.Release();
|
||||
}
|
||||
|
||||
return Lfli;
|
||||
}
|
||||
|
||||
override public Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos (List<UUID> uuids)
|
||||
{
|
||||
MySQLSuperManager dbm = GetLockedConnection("GetFriendRegionInfos");
|
||||
Dictionary<UUID, FriendRegionInfo> infos = new Dictionary<UUID,FriendRegionInfo>();
|
||||
|
||||
try
|
||||
{
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
foreach (UUID uuid in uuids)
|
||||
{
|
||||
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 = m_database.Query(dbcon, "select agentOnline,currentHandle from " + m_agentsTableName +
|
||||
" where UUID = ?uuid", param))
|
||||
{
|
||||
using (IDataReader reader = result.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
FriendRegionInfo fri = new FriendRegionInfo();
|
||||
|
@ -389,20 +308,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());
|
||||
}
|
||||
finally
|
||||
{
|
||||
dbm.Release();
|
||||
m_log.Error(e.Message, e);
|
||||
}
|
||||
|
||||
return infos;
|
||||
|
@ -423,76 +337,73 @@ namespace OpenSim.Data.MySQL
|
|||
Dictionary<string, object> param = new Dictionary<string, object>();
|
||||
param["?first"] = objAlphaNumericPattern.Replace(querysplit[0], String.Empty) + "%";
|
||||
param["?second"] = objAlphaNumericPattern.Replace(querysplit[1], String.Empty) + "%";
|
||||
MySQLSuperManager dbm = GetLockedConnection("GeneratePickerResults");
|
||||
|
||||
try
|
||||
{
|
||||
IDbCommand result =
|
||||
dbm.Manager.Query(
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (IDbCommand result = m_database.Query(dbcon,
|
||||
"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();
|
||||
user.AvatarID = new UUID((string) reader["UUID"]);
|
||||
user.firstName = (string) reader["username"];
|
||||
user.lastName = (string) reader["lastname"];
|
||||
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.ToString());
|
||||
m_log.Error(e.Message, e);
|
||||
return returnlist;
|
||||
}
|
||||
finally
|
||||
{
|
||||
dbm.Release();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MySQLSuperManager dbm = GetLockedConnection("GeneratePickerResults");
|
||||
|
||||
try
|
||||
{
|
||||
Dictionary<string, object> param = new Dictionary<string, object>();
|
||||
param["?first"] = objAlphaNumericPattern.Replace(querysplit[0], String.Empty) + "%";
|
||||
|
||||
IDbCommand result =
|
||||
dbm.Manager.Query(
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (IDbCommand result = m_database.Query(dbcon,
|
||||
"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();
|
||||
user.AvatarID = new UUID((string) reader["UUID"]);
|
||||
user.firstName = (string) reader["username"];
|
||||
user.lastName = (string) reader["lastname"];
|
||||
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.ToString());
|
||||
m_log.Error(e.Message, e);
|
||||
return returnlist;
|
||||
}
|
||||
finally
|
||||
{
|
||||
dbm.Release();
|
||||
}
|
||||
}
|
||||
return returnlist;
|
||||
}
|
||||
|
@ -504,32 +415,30 @@ namespace OpenSim.Data.MySQL
|
|||
/// <returns>User profile data</returns>
|
||||
public override UserProfileData GetUserByUUID(UUID uuid)
|
||||
{
|
||||
MySQLSuperManager dbm = GetLockedConnection("GetUserByUUID");
|
||||
try
|
||||
{
|
||||
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();
|
||||
|
||||
UserProfileData row = dbm.Manager.readUserRow(reader);
|
||||
|
||||
reader.Dispose();
|
||||
result.Dispose();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (IDbCommand result = m_database.Query(dbcon, "SELECT * FROM " + m_usersTableName + " WHERE UUID = ?uuid", param))
|
||||
{
|
||||
using (IDataReader reader = result.ExecuteReader())
|
||||
{
|
||||
UserProfileData row = m_database.readUserRow(reader);
|
||||
return row;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
dbm.Manager.Reconnect();
|
||||
m_log.Error(e.ToString());
|
||||
m_log.Error(e.Message, e);
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
dbm.Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -565,25 +474,18 @@ namespace OpenSim.Data.MySQL
|
|||
param["?UUID"] = AgentID.ToString();
|
||||
param["?webLoginKey"] = WebLoginKey.ToString();
|
||||
|
||||
MySQLSuperManager dbm = GetLockedConnection("StoreWebLoginKey");
|
||||
|
||||
try
|
||||
{
|
||||
dbm.Manager.ExecuteParameterizedSql(
|
||||
m_database.ExecuteParameterizedSql(
|
||||
"update " + m_usersTableName + " SET webLoginKey = ?webLoginKey " +
|
||||
"where UUID = ?UUID",
|
||||
param);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
dbm.Manager.Reconnect();
|
||||
m_log.Error(e.ToString());
|
||||
m_log.Error(e.Message, e);
|
||||
return;
|
||||
}
|
||||
finally
|
||||
{
|
||||
dbm.Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -593,34 +495,30 @@ namespace OpenSim.Data.MySQL
|
|||
/// <returns>The users session</returns>
|
||||
public override UserAgentData GetAgentByUUID(UUID uuid)
|
||||
{
|
||||
MySQLSuperManager dbm = GetLockedConnection("GetAgentByUUID");
|
||||
|
||||
try
|
||||
{
|
||||
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();
|
||||
|
||||
UserAgentData row = dbm.Manager.readAgentRow(reader);
|
||||
|
||||
reader.Dispose();
|
||||
result.Dispose();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (IDbCommand result = m_database.Query(dbcon, "SELECT * FROM " + m_agentsTableName + " WHERE UUID = ?uuid", param))
|
||||
{
|
||||
using (IDataReader reader = result.ExecuteReader())
|
||||
{
|
||||
UserAgentData row = m_database.readAgentRow(reader);
|
||||
return row;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
dbm.Manager.Reconnect();
|
||||
m_log.Error(e.ToString());
|
||||
m_log.Error(e.Message, e);
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
dbm.Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -634,11 +532,11 @@ namespace OpenSim.Data.MySQL
|
|||
{
|
||||
return;
|
||||
}
|
||||
MySQLSuperManager dbm = GetLockedConnection("AddNewUserProfile");
|
||||
|
||||
try
|
||||
{
|
||||
dbm.Manager.insertUserRow(user.ID, user.FirstName, user.SurName, user.Email, user.PasswordHash, user.PasswordSalt,
|
||||
m_database.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,
|
||||
|
@ -649,12 +547,7 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
dbm.Manager.Reconnect();
|
||||
m_log.Error(e.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
dbm.Release();
|
||||
m_log.Error(e.Message, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -668,19 +561,13 @@ namespace OpenSim.Data.MySQL
|
|||
if (agent.ProfileID == zero || agent.SessionID == zero)
|
||||
return;
|
||||
|
||||
MySQLSuperManager dbm = GetLockedConnection("AddNewUserAgent");
|
||||
try
|
||||
{
|
||||
dbm.Manager.insertAgentRow(agent);
|
||||
m_database.insertAgentRow(agent);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
dbm.Manager.Reconnect();
|
||||
m_log.Error(e.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
dbm.Release();
|
||||
m_log.Error(e.Message, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -690,10 +577,10 @@ namespace OpenSim.Data.MySQL
|
|||
/// <param name="user">The profile data to use to update the DB</param>
|
||||
public override bool UpdateUserProfile(UserProfileData user)
|
||||
{
|
||||
MySQLSuperManager dbm = GetLockedConnection("UpdateUserProfile");
|
||||
try
|
||||
{
|
||||
dbm.Manager.updateUserRow(user.ID, user.FirstName, user.SurName, user.Email, user.PasswordHash, user.PasswordSalt,
|
||||
m_database.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,
|
||||
|
@ -701,14 +588,14 @@ namespace OpenSim.Data.MySQL
|
|||
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
|
||||
{
|
||||
dbm.Release();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs a money transfer request between two accounts
|
||||
|
@ -742,41 +629,40 @@ namespace OpenSim.Data.MySQL
|
|||
/// </summary>
|
||||
public override AvatarAppearance GetUserAppearance(UUID user)
|
||||
{
|
||||
MySQLSuperManager dbm = GetLockedConnection("GetUserAppearance");
|
||||
try
|
||||
{
|
||||
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 (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
AvatarAppearance appearance = dbm.Manager.readAppearanceRow(reader);
|
||||
using (IDbCommand result = m_database.Query(dbcon, "SELECT * FROM " + m_appearanceTableName + " WHERE owner = ?owner", param))
|
||||
{
|
||||
using (IDataReader reader = result.ExecuteReader())
|
||||
{
|
||||
AvatarAppearance appearance = m_database.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
|
||||
{
|
||||
dbm.Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -787,22 +673,16 @@ namespace OpenSim.Data.MySQL
|
|||
// override
|
||||
public override void UpdateUserAppearance(UUID user, AvatarAppearance appearance)
|
||||
{
|
||||
MySQLSuperManager dbm = GetLockedConnection("UpdateUserAppearance");
|
||||
try
|
||||
{
|
||||
appearance.Owner = user;
|
||||
dbm.Manager.insertAppearanceRow(appearance);
|
||||
m_database.insertAppearanceRow(appearance);
|
||||
|
||||
UpdateUserAttachments(user, appearance.GetAttachments());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
dbm.Manager.Reconnect();
|
||||
m_log.Error(e.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
dbm.Release();
|
||||
m_log.Error(e.Message, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -829,43 +709,33 @@ namespace OpenSim.Data.MySQL
|
|||
Dictionary<string, object> param = new Dictionary<string, object>();
|
||||
param["?uuid"] = agentID.ToString();
|
||||
|
||||
MySQLSuperManager dbm = GetLockedConnection("GetUserAttachments");
|
||||
|
||||
try
|
||||
{
|
||||
IDbCommand result = dbm.Manager.Query(
|
||||
"SELECT attachpoint, item, asset from " + m_attachmentsTableName + " WHERE UUID = ?uuid", param);
|
||||
IDataReader reader = result.ExecuteReader();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
Hashtable ret = dbm.Manager.readAttachments(reader);
|
||||
|
||||
reader.Dispose();
|
||||
result.Dispose();
|
||||
using (IDbCommand result = m_database.Query(dbcon,
|
||||
"SELECT attachpoint, item, asset from " + m_attachmentsTableName + " WHERE UUID = ?uuid", param))
|
||||
{
|
||||
using (IDataReader reader = result.ExecuteReader())
|
||||
{
|
||||
Hashtable ret = m_database.readAttachments(reader);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
dbm.Manager.Reconnect();
|
||||
m_log.Error(e.ToString());
|
||||
m_log.Error(e.Message, e);
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
dbm.Release();
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateUserAttachments(UUID agentID, Hashtable data)
|
||||
{
|
||||
MySQLSuperManager dbm = GetLockedConnection("UpdateUserAttachments");
|
||||
try
|
||||
{
|
||||
dbm.Manager.writeAttachments(agentID, data);
|
||||
}
|
||||
finally
|
||||
{
|
||||
dbm.Release();
|
||||
}
|
||||
m_database.writeAttachments(agentID, data);
|
||||
}
|
||||
|
||||
public override void ResetAttachments(UUID userID)
|
||||
|
@ -873,45 +743,29 @@ namespace OpenSim.Data.MySQL
|
|||
Dictionary<string, string> param = new Dictionary<string, string>();
|
||||
param["?uuid"] = userID.ToString();
|
||||
|
||||
MySQLSuperManager dbm = GetLockedConnection("ResetAttachments");
|
||||
|
||||
try
|
||||
{
|
||||
dbm.Manager.ExecuteParameterizedSql(
|
||||
m_database.ExecuteParameterizedSql(
|
||||
"UPDATE " + m_attachmentsTableName +
|
||||
" SET asset = '00000000-0000-0000-0000-000000000000' WHERE UUID = ?uuid",
|
||||
param);
|
||||
}
|
||||
finally
|
||||
{
|
||||
dbm.Release();
|
||||
}
|
||||
}
|
||||
|
||||
public override void LogoutUsers(UUID regionID)
|
||||
{
|
||||
Dictionary<string, string> param = new Dictionary<string, string>();
|
||||
param["?regionID"] = regionID.ToString();
|
||||
|
||||
MySQLSuperManager dbm = GetLockedConnection("LogoutUsers");
|
||||
|
||||
try
|
||||
{
|
||||
dbm.Manager.ExecuteParameterizedSql(
|
||||
m_database.ExecuteParameterizedSql(
|
||||
"update " + m_agentsTableName + " SET agentOnline = 0 " +
|
||||
"where currentRegion = ?regionID",
|
||||
param);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
dbm.Manager.Reconnect();
|
||||
m_log.Error(e.ToString());
|
||||
m_log.Error(e.Message, e);
|
||||
return;
|
||||
}
|
||||
finally
|
||||
{
|
||||
dbm.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,7 +110,8 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
public bool MoveItem(string id, string newParent)
|
||||
{
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
using (MySqlCommand cmd = new MySqlCommand())
|
||||
{
|
||||
|
||||
cmd.CommandText = String.Format("update {0} set parentFolderID = ?ParentFolderID where inventoryID = ?InventoryID", m_Realm);
|
||||
cmd.Parameters.AddWithValue("?ParentFolderID", newParent);
|
||||
|
@ -118,10 +119,12 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
return ExecuteNonQuery(cmd) == 0 ? false : true;
|
||||
}
|
||||
}
|
||||
|
||||
public XInventoryItem[] GetActiveGestures(UUID principalID)
|
||||
{
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
using (MySqlCommand cmd = new MySqlCommand())
|
||||
{
|
||||
cmd.CommandText = String.Format("select * from inventoryitems where avatarId = ?uuid and assetType = ?type and flags = 1", m_Realm);
|
||||
|
||||
cmd.Parameters.AddWithValue("?uuid", principalID.ToString());
|
||||
|
@ -129,16 +132,24 @@ namespace OpenSim.Data.MySQL
|
|||
|
||||
return DoQuery(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
public int GetAssetPermissions(UUID principalID, UUID assetID)
|
||||
{
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||
{
|
||||
dbcon.Open();
|
||||
|
||||
using (MySqlCommand cmd = new MySqlCommand())
|
||||
{
|
||||
cmd.Connection = dbcon;
|
||||
|
||||
cmd.CommandText = String.Format("select bit_or(inventoryCurrentPermissions) as inventoryCurrentPermissions from inventoryitems where avatarID = ?PrincipalID and assetID = ?AssetID group by assetID", m_Realm);
|
||||
cmd.Parameters.AddWithValue("?PrincipalID", principalID.ToString());
|
||||
cmd.Parameters.AddWithValue("?AssetID", assetID.ToString());
|
||||
|
||||
IDataReader reader = ExecuteReader(cmd);
|
||||
using (IDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
|
||||
int perms = 0;
|
||||
|
||||
|
@ -147,10 +158,10 @@ namespace OpenSim.Data.MySQL
|
|||
perms = Convert.ToInt32(reader["inventoryCurrentPermissions"]);
|
||||
}
|
||||
|
||||
reader.Close();
|
||||
CloseReaderCommand(cmd);
|
||||
|
||||
return perms;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ using OpenSim.Data.Tests;
|
|||
using log4net;
|
||||
using System.Reflection;
|
||||
using OpenSim.Tests.Common;
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
namespace OpenSim.Data.MySQL.Tests
|
||||
{
|
||||
|
@ -65,10 +66,14 @@ namespace OpenSim.Data.MySQL.Tests
|
|||
|
||||
// This actually does the roll forward assembly stuff
|
||||
Assembly assem = GetType().Assembly;
|
||||
Migration m = new Migration(database.Connection, assem, "GridStore");
|
||||
|
||||
using (MySqlConnection dbcon = new MySqlConnection(connect))
|
||||
{
|
||||
dbcon.Open();
|
||||
Migration m = new Migration(dbcon, assem, "AssetStore");
|
||||
m.Update();
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixtureTearDown]
|
||||
public void Cleanup()
|
||||
|
|
Loading…
Reference in New Issue