MSSQL Additions for Presence Refactor branch. Most functionality tested and works, some outstanding issues around login location and border crossings on y axis.
Signed-off-by: Melanie <melanie@t-data.com>slimupdates
parent
267f3b8147
commit
2fa5694ec9
|
@ -1,219 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) Contributors, http://opensimulator.org/
|
|
||||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
* * Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* * Neither the name of the OpenSimulator Project nor the
|
|
||||||
* names of its contributors may be used to endorse or promote products
|
|
||||||
* derived from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
|
||||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
using System.Data;
|
|
||||||
using System.Data.SqlClient;
|
|
||||||
|
|
||||||
namespace OpenSim.Data.MSSQL
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Encapsulates a SqlCommand object but ensures that when it is disposed, its connection is closed and disposed also.
|
|
||||||
/// </summary>
|
|
||||||
internal class AutoClosingSqlCommand : IDbCommand
|
|
||||||
{
|
|
||||||
private SqlCommand realCommand;
|
|
||||||
|
|
||||||
public AutoClosingSqlCommand(SqlCommand cmd)
|
|
||||||
{
|
|
||||||
realCommand = cmd;
|
|
||||||
}
|
|
||||||
|
|
||||||
#region IDbCommand Members
|
|
||||||
|
|
||||||
public void Cancel()
|
|
||||||
{
|
|
||||||
realCommand.Cancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
public string CommandText
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return realCommand.CommandText;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
realCommand.CommandText = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int CommandTimeout
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return realCommand.CommandTimeout;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
realCommand.CommandTimeout = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public CommandType CommandType
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return realCommand.CommandType;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
realCommand.CommandType = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
IDbConnection IDbCommand.Connection
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return realCommand.Connection;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
realCommand.Connection = (SqlConnection) value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public SqlConnection Connection
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return realCommand.Connection;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
IDbDataParameter IDbCommand.CreateParameter()
|
|
||||||
{
|
|
||||||
return realCommand.CreateParameter();
|
|
||||||
}
|
|
||||||
|
|
||||||
public SqlParameter CreateParameter()
|
|
||||||
{
|
|
||||||
return realCommand.CreateParameter();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int ExecuteNonQuery()
|
|
||||||
{
|
|
||||||
return realCommand.ExecuteNonQuery();
|
|
||||||
}
|
|
||||||
|
|
||||||
IDataReader IDbCommand.ExecuteReader(CommandBehavior behavior)
|
|
||||||
{
|
|
||||||
return realCommand.ExecuteReader(behavior);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SqlDataReader ExecuteReader(CommandBehavior behavior)
|
|
||||||
{
|
|
||||||
return realCommand.ExecuteReader(behavior);
|
|
||||||
}
|
|
||||||
|
|
||||||
IDataReader IDbCommand.ExecuteReader()
|
|
||||||
{
|
|
||||||
return realCommand.ExecuteReader();
|
|
||||||
}
|
|
||||||
|
|
||||||
public SqlDataReader ExecuteReader()
|
|
||||||
{
|
|
||||||
return realCommand.ExecuteReader();
|
|
||||||
}
|
|
||||||
|
|
||||||
public object ExecuteScalar()
|
|
||||||
{
|
|
||||||
return realCommand.ExecuteScalar();
|
|
||||||
}
|
|
||||||
|
|
||||||
IDataParameterCollection IDbCommand.Parameters
|
|
||||||
{
|
|
||||||
get { return realCommand.Parameters; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public SqlParameterCollection Parameters
|
|
||||||
{
|
|
||||||
get { return realCommand.Parameters; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Prepare()
|
|
||||||
{
|
|
||||||
realCommand.Prepare();
|
|
||||||
}
|
|
||||||
|
|
||||||
// IDbTransaction IDbCommand.Transaction
|
|
||||||
// {
|
|
||||||
// get
|
|
||||||
// {
|
|
||||||
// return realCommand.Transaction;
|
|
||||||
// }
|
|
||||||
// set
|
|
||||||
// {
|
|
||||||
// realCommand.Transaction = (SqlTransaction) value;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
public IDbTransaction Transaction
|
|
||||||
{
|
|
||||||
get { return realCommand.Transaction; }
|
|
||||||
set { realCommand.Transaction = (SqlTransaction)value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateRowSource IDbCommand.UpdatedRowSource
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return realCommand.UpdatedRowSource;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
realCommand.UpdatedRowSource = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IDisposable Members
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
SqlConnection conn = realCommand.Connection;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
realCommand.Dispose();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
conn.Close();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
conn.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -49,6 +49,7 @@ namespace OpenSim.Data.MSSQL
|
||||||
/// Database manager
|
/// Database manager
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private MSSQLManager m_database;
|
private MSSQLManager m_database;
|
||||||
|
private string m_connectionString;
|
||||||
|
|
||||||
#region IPlugin Members
|
#region IPlugin Members
|
||||||
|
|
||||||
|
@ -75,23 +76,8 @@ namespace OpenSim.Data.MSSQL
|
||||||
{
|
{
|
||||||
m_ticksToEpoch = new System.DateTime(1970, 1, 1).Ticks;
|
m_ticksToEpoch = new System.DateTime(1970, 1, 1).Ticks;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(connectionString))
|
m_database = new MSSQLManager(connectionString);
|
||||||
{
|
m_connectionString = connectionString;
|
||||||
m_database = new MSSQLManager(connectionString);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
IniFile gridDataMSSqlFile = new IniFile("mssql_connection.ini");
|
|
||||||
string settingDataSource = gridDataMSSqlFile.ParseFileReadValue("data_source");
|
|
||||||
string settingInitialCatalog = gridDataMSSqlFile.ParseFileReadValue("initial_catalog");
|
|
||||||
string settingPersistSecurityInfo = gridDataMSSqlFile.ParseFileReadValue("persist_security_info");
|
|
||||||
string settingUserId = gridDataMSSqlFile.ParseFileReadValue("user_id");
|
|
||||||
string settingPassword = gridDataMSSqlFile.ParseFileReadValue("password");
|
|
||||||
|
|
||||||
m_database =
|
|
||||||
new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId,
|
|
||||||
settingPassword);
|
|
||||||
}
|
|
||||||
|
|
||||||
//New migration to check for DB changes
|
//New migration to check for DB changes
|
||||||
m_database.CheckMigration(_migrationStore);
|
m_database.CheckMigration(_migrationStore);
|
||||||
|
@ -125,18 +111,19 @@ namespace OpenSim.Data.MSSQL
|
||||||
override public AssetBase GetAsset(UUID assetID)
|
override public AssetBase GetAsset(UUID assetID)
|
||||||
{
|
{
|
||||||
string sql = "SELECT * FROM assets WHERE id = @id";
|
string sql = "SELECT * FROM assets WHERE id = @id";
|
||||||
using (AutoClosingSqlCommand command = m_database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
command.Parameters.Add(m_database.CreateParameter("id", assetID));
|
cmd.Parameters.Add(m_database.CreateParameter("id", assetID));
|
||||||
using (SqlDataReader reader = command.ExecuteReader())
|
conn.Open();
|
||||||
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
if (reader.Read())
|
if (reader.Read())
|
||||||
{
|
{
|
||||||
AssetBase asset = new AssetBase(
|
AssetBase asset = new AssetBase(
|
||||||
new UUID((Guid)reader["id"]),
|
new UUID((Guid)reader["id"]),
|
||||||
(string)reader["name"],
|
(string)reader["name"],
|
||||||
Convert.ToSByte(reader["assetType"]),
|
Convert.ToSByte(reader["assetType"])
|
||||||
UUID.Zero.ToString()
|
|
||||||
);
|
);
|
||||||
// Region Main
|
// Region Main
|
||||||
asset.Description = (string)reader["description"];
|
asset.Description = (string)reader["description"];
|
||||||
|
@ -191,7 +178,8 @@ namespace OpenSim.Data.MSSQL
|
||||||
m_log.Warn("[ASSET DB]: Description field truncated from " + asset.Description.Length + " to " + assetDescription.Length + " characters on add");
|
m_log.Warn("[ASSET DB]: Description field truncated from " + asset.Description.Length + " to " + assetDescription.Length + " characters on add");
|
||||||
}
|
}
|
||||||
|
|
||||||
using (AutoClosingSqlCommand command = m_database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand command = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
int now = (int)((System.DateTime.Now.Ticks - m_ticksToEpoch) / 10000000);
|
int now = (int)((System.DateTime.Now.Ticks - m_ticksToEpoch) / 10000000);
|
||||||
command.Parameters.Add(m_database.CreateParameter("id", asset.FullID));
|
command.Parameters.Add(m_database.CreateParameter("id", asset.FullID));
|
||||||
|
@ -203,7 +191,7 @@ namespace OpenSim.Data.MSSQL
|
||||||
command.Parameters.Add(m_database.CreateParameter("access_time", now));
|
command.Parameters.Add(m_database.CreateParameter("access_time", now));
|
||||||
command.Parameters.Add(m_database.CreateParameter("create_time", now));
|
command.Parameters.Add(m_database.CreateParameter("create_time", now));
|
||||||
command.Parameters.Add(m_database.CreateParameter("data", asset.Data));
|
command.Parameters.Add(m_database.CreateParameter("data", asset.Data));
|
||||||
|
conn.Open();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
|
@ -239,7 +227,8 @@ namespace OpenSim.Data.MSSQL
|
||||||
m_log.Warn("[ASSET DB]: Description field truncated from " + asset.Description.Length + " to " + assetDescription.Length + " characters on update");
|
m_log.Warn("[ASSET DB]: Description field truncated from " + asset.Description.Length + " to " + assetDescription.Length + " characters on update");
|
||||||
}
|
}
|
||||||
|
|
||||||
using (AutoClosingSqlCommand command = m_database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand command = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
command.Parameters.Add(m_database.CreateParameter("id", asset.FullID));
|
command.Parameters.Add(m_database.CreateParameter("id", asset.FullID));
|
||||||
command.Parameters.Add(m_database.CreateParameter("name", assetName));
|
command.Parameters.Add(m_database.CreateParameter("name", assetName));
|
||||||
|
@ -249,7 +238,7 @@ namespace OpenSim.Data.MSSQL
|
||||||
command.Parameters.Add(m_database.CreateParameter("temporary", asset.Temporary));
|
command.Parameters.Add(m_database.CreateParameter("temporary", asset.Temporary));
|
||||||
command.Parameters.Add(m_database.CreateParameter("data", asset.Data));
|
command.Parameters.Add(m_database.CreateParameter("data", asset.Data));
|
||||||
command.Parameters.Add(m_database.CreateParameter("@keyId", asset.FullID));
|
command.Parameters.Add(m_database.CreateParameter("@keyId", asset.FullID));
|
||||||
|
conn.Open();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
|
@ -309,12 +298,13 @@ namespace OpenSim.Data.MSSQL
|
||||||
OVER (ORDER BY (some column to order by))
|
OVER (ORDER BY (some column to order by))
|
||||||
WHERE Row >= @Start AND Row < @Start + @Count";
|
WHERE Row >= @Start AND Row < @Start + @Count";
|
||||||
|
|
||||||
using (AutoClosingSqlCommand command = m_database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
command.Parameters.Add(m_database.CreateParameter("start", start));
|
cmd.Parameters.Add(m_database.CreateParameter("start", start));
|
||||||
command.Parameters.Add(m_database.CreateParameter("count", count));
|
cmd.Parameters.Add(m_database.CreateParameter("count", count));
|
||||||
|
conn.Open();
|
||||||
using (SqlDataReader reader = command.ExecuteReader())
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
|
|
|
@ -53,6 +53,7 @@ namespace OpenSim.Data.MSSQL
|
||||||
{
|
{
|
||||||
conn.Open();
|
conn.Open();
|
||||||
Migration m = new Migration(conn, GetType().Assembly, "AuthStore");
|
Migration m = new Migration(conn, GetType().Assembly, "AuthStore");
|
||||||
|
m_database = new MSSQLManager(m_ConnectionString);
|
||||||
m.Update();
|
m.Update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,13 +169,14 @@ namespace OpenSim.Data.MSSQL
|
||||||
{
|
{
|
||||||
if (System.Environment.TickCount - m_LastExpire > 30000)
|
if (System.Environment.TickCount - m_LastExpire > 30000)
|
||||||
DoExpire();
|
DoExpire();
|
||||||
string sql = "insert into tokens (UUID, token, validity) values (@principalID, @token, date_add(now(), interval @lifetime minute))";
|
|
||||||
|
string sql = "insert into tokens (UUID, token, validity) values (@principalID, @token, @lifetime)";
|
||||||
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(m_database.CreateParameter("@principalID", principalID));
|
cmd.Parameters.Add(m_database.CreateParameter("@principalID", principalID));
|
||||||
cmd.Parameters.Add(m_database.CreateParameter("@token", token));
|
cmd.Parameters.Add(m_database.CreateParameter("@token", token));
|
||||||
cmd.Parameters.Add(m_database.CreateParameter("@lifetime", lifetime));
|
cmd.Parameters.Add(m_database.CreateParameter("@lifetime", DateTime.Now.AddMinutes(lifetime)));
|
||||||
conn.Open();
|
conn.Open();
|
||||||
|
|
||||||
if (cmd.ExecuteNonQuery() > 0)
|
if (cmd.ExecuteNonQuery() > 0)
|
||||||
|
@ -189,13 +191,15 @@ namespace OpenSim.Data.MSSQL
|
||||||
{
|
{
|
||||||
if (System.Environment.TickCount - m_LastExpire > 30000)
|
if (System.Environment.TickCount - m_LastExpire > 30000)
|
||||||
DoExpire();
|
DoExpire();
|
||||||
string sql = "update tokens set validity = date_add(now(), interval @lifetime minute) where UUID = @principalID and token = @token and validity > now()";
|
|
||||||
|
DateTime validDate = DateTime.Now.AddMinutes(lifetime);
|
||||||
|
string sql = "update tokens set validity = @validDate where UUID = @principalID and token = @token and validity > GetDate()";
|
||||||
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(m_database.CreateParameter("@principalID", principalID));
|
cmd.Parameters.Add(m_database.CreateParameter("@principalID", principalID));
|
||||||
cmd.Parameters.Add(m_database.CreateParameter("@token", token));
|
cmd.Parameters.Add(m_database.CreateParameter("@token", token));
|
||||||
cmd.Parameters.Add(m_database.CreateParameter("@lifetime", lifetime));
|
cmd.Parameters.Add(m_database.CreateParameter("@validDate", validDate));
|
||||||
conn.Open();
|
conn.Open();
|
||||||
|
|
||||||
if (cmd.ExecuteNonQuery() > 0)
|
if (cmd.ExecuteNonQuery() > 0)
|
||||||
|
@ -208,11 +212,13 @@ namespace OpenSim.Data.MSSQL
|
||||||
|
|
||||||
private void DoExpire()
|
private void DoExpire()
|
||||||
{
|
{
|
||||||
string sql = "delete from tokens where validity < now()";
|
DateTime currentDateTime = DateTime.Now;
|
||||||
|
string sql = "delete from tokens where validity < @currentDateTime";
|
||||||
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
conn.Open();
|
conn.Open();
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@currentDateTime", currentDateTime));
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
m_LastExpire = System.Environment.TickCount;
|
m_LastExpire = System.Environment.TickCount;
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) Contributors, http://opensimulator.org/
|
||||||
|
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* * Neither the name of the OpenSimulator Project nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||||
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||||
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Threading;
|
||||||
|
using log4net;
|
||||||
|
using OpenMetaverse;
|
||||||
|
using OpenSim.Framework;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
|
||||||
|
namespace OpenSim.Data.MSSQL
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A MSSQL Interface for Avatar Storage
|
||||||
|
/// </summary>
|
||||||
|
public class MSSQLAvatarData : MSSQLGenericTableHandler<AvatarBaseData>,
|
||||||
|
IAvatarData
|
||||||
|
{
|
||||||
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
|
public MSSQLAvatarData(string connectionString, string realm) :
|
||||||
|
base(connectionString, realm, "Avatar")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Delete(UUID principalID, string name)
|
||||||
|
{
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand())
|
||||||
|
{
|
||||||
|
|
||||||
|
cmd.CommandText = String.Format("DELETE FROM {0} where [PrincipalID] = @PrincipalID and [Name] = @Name", m_Realm);
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@PrincipalID", principalID.ToString()));
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@Name", name));
|
||||||
|
cmd.Connection = conn;
|
||||||
|
conn.Open();
|
||||||
|
if (cmd.ExecuteNonQuery() > 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -44,7 +44,7 @@ namespace OpenSim.Data.MSSQL
|
||||||
private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
private MSSQLManager _Database;
|
private MSSQLManager _Database;
|
||||||
|
private string m_connectionString;
|
||||||
private FieldInfo[] _Fields;
|
private FieldInfo[] _Fields;
|
||||||
private Dictionary<string, FieldInfo> _FieldMap = new Dictionary<string, FieldInfo>();
|
private Dictionary<string, FieldInfo> _FieldMap = new Dictionary<string, FieldInfo>();
|
||||||
|
|
||||||
|
@ -58,22 +58,9 @@ namespace OpenSim.Data.MSSQL
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(connectionString))
|
if (!string.IsNullOrEmpty(connectionString))
|
||||||
{
|
{
|
||||||
|
m_connectionString = connectionString;
|
||||||
_Database = new MSSQLManager(connectionString);
|
_Database = new MSSQLManager(connectionString);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
//TODO when can this be deleted
|
|
||||||
IniFile iniFile = new IniFile("mssql_connection.ini");
|
|
||||||
string settingDataSource = iniFile.ParseFileReadValue("data_source");
|
|
||||||
string settingInitialCatalog = iniFile.ParseFileReadValue("initial_catalog");
|
|
||||||
string settingPersistSecurityInfo = iniFile.ParseFileReadValue("persist_security_info");
|
|
||||||
string settingUserId = iniFile.ParseFileReadValue("user_id");
|
|
||||||
string settingPassword = iniFile.ParseFileReadValue("password");
|
|
||||||
|
|
||||||
_Database =
|
|
||||||
new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId,
|
|
||||||
settingPassword);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Migration settings
|
//Migration settings
|
||||||
_Database.CheckMigration(_migrationStore);
|
_Database.CheckMigration(_migrationStore);
|
||||||
|
@ -103,11 +90,11 @@ namespace OpenSim.Data.MSSQL
|
||||||
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";
|
||||||
|
|
||||||
bool insertEstate = false;
|
bool insertEstate = false;
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(_Database.CreateParameter("@RegionID", regionID));
|
cmd.Parameters.Add(_Database.CreateParameter("@RegionID", regionID));
|
||||||
|
conn.Open();
|
||||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
if (reader.Read())
|
if (reader.Read())
|
||||||
|
@ -124,7 +111,7 @@ namespace OpenSim.Data.MSSQL
|
||||||
}
|
}
|
||||||
else if (_FieldMap[name].GetValue(es) is UUID)
|
else if (_FieldMap[name].GetValue(es) is UUID)
|
||||||
{
|
{
|
||||||
_FieldMap[name].SetValue(es, new UUID((Guid) reader[name])); // uuid);
|
_FieldMap[name].SetValue(es, new UUID((Guid)reader[name])); // uuid);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -149,34 +136,36 @@ namespace OpenSim.Data.MSSQL
|
||||||
sql = string.Format("insert into estate_settings ({0}) values ( @{1})", String.Join(",", names.ToArray()), String.Join(", @", names.ToArray()));
|
sql = string.Format("insert into estate_settings ({0}) values ( @{1})", String.Join(",", names.ToArray()), String.Join(", @", names.ToArray()));
|
||||||
|
|
||||||
//_Log.Debug("[DB ESTATE]: SQL: " + sql);
|
//_Log.Debug("[DB ESTATE]: SQL: " + sql);
|
||||||
using (SqlConnection connection = _Database.DatabaseConnection())
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand insertCommand = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
using (SqlCommand insertCommand = connection.CreateCommand())
|
insertCommand.CommandText = sql + " SET @ID = SCOPE_IDENTITY()";
|
||||||
|
|
||||||
|
foreach (string name in names)
|
||||||
{
|
{
|
||||||
insertCommand.CommandText = sql + " SET @ID = SCOPE_IDENTITY()";
|
insertCommand.Parameters.Add(_Database.CreateParameter("@" + name, _FieldMap[name].GetValue(es)));
|
||||||
|
|
||||||
foreach (string name in names)
|
|
||||||
{
|
|
||||||
insertCommand.Parameters.Add(_Database.CreateParameter("@" + name, _FieldMap[name].GetValue(es)));
|
|
||||||
}
|
|
||||||
SqlParameter idParameter = new SqlParameter("@ID", SqlDbType.Int);
|
|
||||||
idParameter.Direction = ParameterDirection.Output;
|
|
||||||
insertCommand.Parameters.Add(idParameter);
|
|
||||||
|
|
||||||
insertCommand.ExecuteNonQuery();
|
|
||||||
|
|
||||||
es.EstateID = Convert.ToUInt32(idParameter.Value);
|
|
||||||
}
|
}
|
||||||
|
SqlParameter idParameter = new SqlParameter("@ID", SqlDbType.Int);
|
||||||
|
idParameter.Direction = ParameterDirection.Output;
|
||||||
|
insertCommand.Parameters.Add(idParameter);
|
||||||
|
conn.Open();
|
||||||
|
insertCommand.ExecuteNonQuery();
|
||||||
|
|
||||||
|
es.EstateID = Convert.ToUInt32(idParameter.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
using (AutoClosingSqlCommand cmd = _Database.Query("INSERT INTO [estate_map] ([RegionID] ,[EstateID]) VALUES (@RegionID, @EstateID)"))
|
sql = "INSERT INTO [estate_map] ([RegionID] ,[EstateID]) VALUES (@RegionID, @EstateID)";
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
|
|
||||||
cmd.Parameters.Add(_Database.CreateParameter("@RegionID", regionID));
|
cmd.Parameters.Add(_Database.CreateParameter("@RegionID", regionID));
|
||||||
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID));
|
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID));
|
||||||
// This will throw on dupe key
|
// This will throw on dupe key
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
cmd.ExecuteNonQuery();
|
conn.Open();
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -187,12 +176,14 @@ namespace OpenSim.Data.MSSQL
|
||||||
// Munge and transfer the ban list
|
// Munge and transfer the ban list
|
||||||
|
|
||||||
sql = string.Format("insert into estateban select {0}, bannedUUID, bannedIp, bannedIpHostMask, '' from regionban where regionban.regionUUID = @UUID", es.EstateID);
|
sql = string.Format("insert into estateban select {0}, bannedUUID, bannedIp, bannedIpHostMask, '' from regionban where regionban.regionUUID = @UUID", es.EstateID);
|
||||||
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
|
|
||||||
cmd.Parameters.Add(_Database.CreateParameter("@UUID", regionID));
|
cmd.Parameters.Add(_Database.CreateParameter("@UUID", regionID));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
conn.Open();
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
@ -226,7 +217,7 @@ namespace OpenSim.Data.MSSQL
|
||||||
|
|
||||||
names.Remove("EstateID");
|
names.Remove("EstateID");
|
||||||
|
|
||||||
string sql = string.Format("UPDATE estate_settings SET ") ;
|
string sql = string.Format("UPDATE estate_settings SET ");
|
||||||
foreach (string name in names)
|
foreach (string name in names)
|
||||||
{
|
{
|
||||||
sql += name + " = @" + name + ", ";
|
sql += name + " = @" + name + ", ";
|
||||||
|
@ -234,7 +225,8 @@ namespace OpenSim.Data.MSSQL
|
||||||
sql = sql.Remove(sql.LastIndexOf(","));
|
sql = sql.Remove(sql.LastIndexOf(","));
|
||||||
sql += " WHERE EstateID = @EstateID";
|
sql += " WHERE EstateID = @EstateID";
|
||||||
|
|
||||||
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
foreach (string name in names)
|
foreach (string name in names)
|
||||||
{
|
{
|
||||||
|
@ -242,6 +234,7 @@ namespace OpenSim.Data.MSSQL
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID));
|
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID));
|
||||||
|
conn.Open();
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,12 +259,13 @@ namespace OpenSim.Data.MSSQL
|
||||||
|
|
||||||
string sql = "select bannedUUID from estateban where EstateID = @EstateID";
|
string sql = "select bannedUUID from estateban where EstateID = @EstateID";
|
||||||
|
|
||||||
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
SqlParameter idParameter = new SqlParameter("@EstateID", SqlDbType.Int);
|
SqlParameter idParameter = new SqlParameter("@EstateID", SqlDbType.Int);
|
||||||
idParameter.Value = es.EstateID;
|
idParameter.Value = es.EstateID;
|
||||||
cmd.Parameters.Add(idParameter);
|
cmd.Parameters.Add(idParameter);
|
||||||
|
conn.Open();
|
||||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
|
@ -293,10 +287,11 @@ namespace OpenSim.Data.MSSQL
|
||||||
|
|
||||||
string sql = string.Format("select uuid from {0} where EstateID = @EstateID", table);
|
string sql = string.Format("select uuid from {0} where EstateID = @EstateID", table);
|
||||||
|
|
||||||
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID));
|
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID));
|
||||||
|
conn.Open();
|
||||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
|
@ -313,20 +308,24 @@ namespace OpenSim.Data.MSSQL
|
||||||
{
|
{
|
||||||
//Delete first
|
//Delete first
|
||||||
string sql = "delete from estateban where EstateID = @EstateID";
|
string sql = "delete from estateban where EstateID = @EstateID";
|
||||||
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID));
|
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID));
|
||||||
|
conn.Open();
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Insert after
|
//Insert after
|
||||||
sql = "insert into estateban (EstateID, bannedUUID) values ( @EstateID, @bannedUUID )";
|
sql = "insert into estateban (EstateID, bannedUUID) values ( @EstateID, @bannedUUID )";
|
||||||
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
foreach (EstateBan b in es.EstateBans)
|
foreach (EstateBan b in es.EstateBans)
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID));
|
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID));
|
||||||
cmd.Parameters.Add(_Database.CreateParameter("@bannedUUID", b.BannedUserID));
|
cmd.Parameters.Add(_Database.CreateParameter("@bannedUUID", b.BannedUserID));
|
||||||
|
conn.Open();
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
cmd.Parameters.Clear();
|
cmd.Parameters.Clear();
|
||||||
}
|
}
|
||||||
|
@ -337,14 +336,16 @@ namespace OpenSim.Data.MSSQL
|
||||||
{
|
{
|
||||||
//Delete first
|
//Delete first
|
||||||
string sql = string.Format("delete from {0} where EstateID = @EstateID", table);
|
string sql = string.Format("delete from {0} where EstateID = @EstateID", table);
|
||||||
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID));
|
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID));
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
sql = string.Format("insert into {0} (EstateID, uuid) values ( @EstateID, @uuid )", table);
|
sql = string.Format("insert into {0} (EstateID, uuid) values ( @EstateID, @uuid )", table);
|
||||||
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID));
|
cmd.Parameters.Add(_Database.CreateParameter("@EstateID", estateID));
|
||||||
|
|
||||||
|
@ -359,7 +360,7 @@ namespace OpenSim.Data.MSSQL
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cmd.Parameters["@uuid"].Value = uuid.Guid; //.ToString(); //TODO check if this works
|
cmd.Parameters["@uuid"].Value = uuid.Guid; //.ToString(); //TODO check if this works
|
||||||
|
conn.Open();
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) Contributors, http://opensimulator.org/
|
||||||
|
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* * Neither the name of the OpenSimulator Project nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ''AS IS'' AND ANY
|
||||||
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||||
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using OpenMetaverse;
|
||||||
|
using OpenSim.Framework;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OpenSim.Data.MSSQL
|
||||||
|
{
|
||||||
|
public class MSSQLFriendsData : MSSQLGenericTableHandler<FriendsData>, IFriendsData
|
||||||
|
{
|
||||||
|
public MSSQLFriendsData(string connectionString, string realm)
|
||||||
|
: base(connectionString, realm, "FriendsStore")
|
||||||
|
{
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
Migration m = new Migration(conn, GetType().Assembly, "FriendsStore");
|
||||||
|
m.Update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Delete(UUID principalID, string friend)
|
||||||
|
{
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand())
|
||||||
|
{
|
||||||
|
cmd.CommandText = String.Format("delete from {0} where PrincipalID = @PrincipalID and Friend = @Friend", m_Realm);
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@PrincipalID", principalID.ToString()));
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@Friend", friend));
|
||||||
|
cmd.Connection = conn;
|
||||||
|
conn.Open();
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public FriendsData[] GetFriends(UUID principalID)
|
||||||
|
{
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand())
|
||||||
|
{
|
||||||
|
|
||||||
|
cmd.CommandText = String.Format("select a.*,b.Flags as TheirFlags from {0} as a left join {0} as b on a.PrincipalID = b.Friend and a.Friend = b.PrincipalID where a.PrincipalID = ?PrincipalID and b.Flags is not null", m_Realm);
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@PrincipalID", principalID.ToString()));
|
||||||
|
cmd.Connection = conn;
|
||||||
|
conn.Open();
|
||||||
|
return DoQuery(cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,359 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) Contributors, http://opensimulator.org/
|
||||||
|
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* * Neither the name of the OpenSimulator Project nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||||
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||||
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Reflection;
|
||||||
|
using log4net;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
using OpenMetaverse;
|
||||||
|
using OpenSim.Framework;
|
||||||
|
using OpenSim.Region.Framework.Interfaces;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OpenSim.Data.MSSQL
|
||||||
|
{
|
||||||
|
public class MSSQLGenericTableHandler<T> where T : class, new()
|
||||||
|
{
|
||||||
|
private static readonly ILog m_log =
|
||||||
|
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
|
protected string m_ConnectionString;
|
||||||
|
protected MSSQLManager m_database; //used for parameter type translation
|
||||||
|
protected Dictionary<string, FieldInfo> m_Fields =
|
||||||
|
new Dictionary<string, FieldInfo>();
|
||||||
|
|
||||||
|
protected List<string> m_ColumnNames = null;
|
||||||
|
protected string m_Realm;
|
||||||
|
protected FieldInfo m_DataField = null;
|
||||||
|
|
||||||
|
public MSSQLGenericTableHandler(string connectionString,
|
||||||
|
string realm, string storeName)
|
||||||
|
{
|
||||||
|
m_Realm = realm;
|
||||||
|
|
||||||
|
if (storeName != String.Empty)
|
||||||
|
{
|
||||||
|
Assembly assem = GetType().Assembly;
|
||||||
|
m_ConnectionString = connectionString;
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
Migration m = new Migration(conn, assem, storeName);
|
||||||
|
m.Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
m_database = new MSSQLManager(m_ConnectionString);
|
||||||
|
|
||||||
|
Type t = typeof(T);
|
||||||
|
FieldInfo[] fields = t.GetFields(BindingFlags.Public |
|
||||||
|
BindingFlags.Instance |
|
||||||
|
BindingFlags.DeclaredOnly);
|
||||||
|
|
||||||
|
if (fields.Length == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
foreach (FieldInfo f in fields)
|
||||||
|
{
|
||||||
|
if (f.Name != "Data")
|
||||||
|
m_Fields[f.Name] = f;
|
||||||
|
else
|
||||||
|
m_DataField = f;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckColumnNames(SqlDataReader reader)
|
||||||
|
{
|
||||||
|
if (m_ColumnNames != null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_ColumnNames = new List<string>();
|
||||||
|
|
||||||
|
DataTable schemaTable = reader.GetSchemaTable();
|
||||||
|
foreach (DataRow row in schemaTable.Rows)
|
||||||
|
{
|
||||||
|
if (row["ColumnName"] != null &&
|
||||||
|
(!m_Fields.ContainsKey(row["ColumnName"].ToString())))
|
||||||
|
m_ColumnNames.Add(row["ColumnName"].ToString());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<string> GetConstraints()
|
||||||
|
{
|
||||||
|
List<string> constraints = new List<string>();
|
||||||
|
string query = string.Format(@"SELECT
|
||||||
|
COL_NAME(ic.object_id,ic.column_id) AS column_name
|
||||||
|
FROM sys.indexes AS i
|
||||||
|
INNER JOIN sys.index_columns AS ic
|
||||||
|
ON i.object_id = ic.object_id AND i.index_id = ic.index_id
|
||||||
|
WHERE i.is_primary_key = 1
|
||||||
|
AND i.object_id = OBJECT_ID('{0}');", m_Realm);
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(query, conn))
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
using (SqlDataReader rdr = cmd.ExecuteReader())
|
||||||
|
{
|
||||||
|
while (rdr.Read())
|
||||||
|
{
|
||||||
|
// query produces 0 to many rows of single column, so always add the first item in each row
|
||||||
|
constraints.Add((string)rdr[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return constraints;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual T[] Get(string field, string key)
|
||||||
|
{
|
||||||
|
return Get(new string[] { field }, new string[] { key });
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual T[] Get(string[] fields, string[] keys)
|
||||||
|
{
|
||||||
|
if (fields.Length != keys.Length)
|
||||||
|
return new T[0];
|
||||||
|
|
||||||
|
List<string> terms = new List<string>();
|
||||||
|
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand())
|
||||||
|
{
|
||||||
|
|
||||||
|
for (int i = 0; i < fields.Length; i++)
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter(fields[i], keys[i]));
|
||||||
|
terms.Add("[" + fields[i] + "] = @" + fields[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
string where = String.Join(" AND ", terms.ToArray());
|
||||||
|
|
||||||
|
string query = String.Format("SELECT * FROM {0} WHERE {1}",
|
||||||
|
m_Realm, where);
|
||||||
|
|
||||||
|
cmd.Connection = conn;
|
||||||
|
cmd.CommandText = query;
|
||||||
|
conn.Open();
|
||||||
|
return DoQuery(cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected T[] DoQuery(SqlCommand cmd)
|
||||||
|
{
|
||||||
|
using (SqlDataReader 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();
|
||||||
|
|
||||||
|
foreach (string name in m_Fields.Keys)
|
||||||
|
{
|
||||||
|
if (m_Fields[name].GetValue(row) is bool)
|
||||||
|
{
|
||||||
|
int v = Convert.ToInt32(reader[name]);
|
||||||
|
m_Fields[name].SetValue(row, v != 0 ? true : false);
|
||||||
|
}
|
||||||
|
else if (m_Fields[name].GetValue(row) is UUID)
|
||||||
|
{
|
||||||
|
UUID uuid = UUID.Zero;
|
||||||
|
|
||||||
|
UUID.TryParse(reader[name].ToString(), out uuid);
|
||||||
|
m_Fields[name].SetValue(row, uuid);
|
||||||
|
}
|
||||||
|
else if (m_Fields[name].GetValue(row) is int)
|
||||||
|
{
|
||||||
|
int v = Convert.ToInt32(reader[name]);
|
||||||
|
m_Fields[name].SetValue(row, v);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_Fields[name].SetValue(row, reader[name]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_DataField != null)
|
||||||
|
{
|
||||||
|
Dictionary<string, string> data =
|
||||||
|
new Dictionary<string, string>();
|
||||||
|
|
||||||
|
foreach (string col in m_ColumnNames)
|
||||||
|
{
|
||||||
|
data[col] = reader[col].ToString();
|
||||||
|
if (data[col] == null)
|
||||||
|
data[col] = String.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_DataField.SetValue(row, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
result.Add(row);
|
||||||
|
}
|
||||||
|
return result.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual T[] Get(string where)
|
||||||
|
{
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand())
|
||||||
|
{
|
||||||
|
|
||||||
|
string query = String.Format("SELECT * FROM {0} WHERE {1}",
|
||||||
|
m_Realm, where);
|
||||||
|
cmd.Connection = conn;
|
||||||
|
cmd.CommandText = query;
|
||||||
|
|
||||||
|
//m_log.WarnFormat("[MSSQLGenericTable]: SELECT {0} WHERE {1}", m_Realm, where);
|
||||||
|
|
||||||
|
conn.Open();
|
||||||
|
return DoQuery(cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual bool Store(T row)
|
||||||
|
{
|
||||||
|
List<string> constraintFields = GetConstraints();
|
||||||
|
List<KeyValuePair<string, string>> constraints = new List<KeyValuePair<string, string>>();
|
||||||
|
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand())
|
||||||
|
{
|
||||||
|
|
||||||
|
StringBuilder query = new StringBuilder();
|
||||||
|
List<String> names = new List<String>();
|
||||||
|
List<String> values = new List<String>();
|
||||||
|
|
||||||
|
foreach (FieldInfo fi in m_Fields.Values)
|
||||||
|
{
|
||||||
|
names.Add(fi.Name);
|
||||||
|
values.Add("@" + fi.Name);
|
||||||
|
if (constraintFields.Count > 0 && constraintFields.Contains(fi.Name))
|
||||||
|
{
|
||||||
|
constraints.Add(new KeyValuePair<string, string>(fi.Name, fi.GetValue(row).ToString()));
|
||||||
|
}
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter(fi.Name, fi.GetValue(row).ToString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_DataField != null)
|
||||||
|
{
|
||||||
|
Dictionary<string, string> data =
|
||||||
|
(Dictionary<string, string>)m_DataField.GetValue(row);
|
||||||
|
|
||||||
|
foreach (KeyValuePair<string, string> kvp in data)
|
||||||
|
{
|
||||||
|
if (constraintFields.Count > 0 && constraintFields.Contains(kvp.Key))
|
||||||
|
{
|
||||||
|
constraints.Add(new KeyValuePair<string, string>(kvp.Key, kvp.Key));
|
||||||
|
}
|
||||||
|
names.Add(kvp.Key);
|
||||||
|
values.Add("@" + kvp.Key);
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@" + kvp.Key, kvp.Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
query.AppendFormat("UPDATE {0} SET ", m_Realm);
|
||||||
|
int i = 0;
|
||||||
|
for (i = 0; i < names.Count - 1; i++)
|
||||||
|
{
|
||||||
|
query.AppendFormat("[{0}] = {1}, ", names[i], values[i]);
|
||||||
|
}
|
||||||
|
query.AppendFormat("[{0}] = {1} ", names[i], values[i]);
|
||||||
|
if (constraints.Count > 0)
|
||||||
|
{
|
||||||
|
List<string> terms = new List<string>();
|
||||||
|
for (int j = 0; j < constraints.Count; j++)
|
||||||
|
{
|
||||||
|
terms.Add(" [" + constraints[j].Key + "] = @" + constraints[j].Key);
|
||||||
|
}
|
||||||
|
string where = String.Join(" AND ", terms.ToArray());
|
||||||
|
query.AppendFormat(" WHERE {0} ", where);
|
||||||
|
|
||||||
|
}
|
||||||
|
cmd.Connection = conn;
|
||||||
|
cmd.CommandText = query.ToString();
|
||||||
|
|
||||||
|
conn.Open();
|
||||||
|
if (cmd.ExecuteNonQuery() > 0)
|
||||||
|
{
|
||||||
|
//m_log.WarnFormat("[MSSQLGenericTable]: Updating {0}", m_Realm);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// assume record has not yet been inserted
|
||||||
|
|
||||||
|
query = new StringBuilder();
|
||||||
|
query.AppendFormat("INSERT INTO {0} ([", m_Realm);
|
||||||
|
query.Append(String.Join("],[", names.ToArray()));
|
||||||
|
query.Append("]) values (" + String.Join(",", values.ToArray()) + ")");
|
||||||
|
cmd.Connection = conn;
|
||||||
|
cmd.CommandText = query.ToString();
|
||||||
|
//m_log.WarnFormat("[MSSQLGenericTable]: Inserting into {0}", m_Realm);
|
||||||
|
if (conn.State != ConnectionState.Open)
|
||||||
|
conn.Open();
|
||||||
|
if (cmd.ExecuteNonQuery() > 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual bool Delete(string field, string val)
|
||||||
|
{
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand())
|
||||||
|
{
|
||||||
|
string deleteCommand = String.Format("DELETE FROM {0} WHERE [{1}] = @{1}", m_Realm, field);
|
||||||
|
cmd.CommandText = deleteCommand;
|
||||||
|
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter(field, val));
|
||||||
|
cmd.Connection = conn;
|
||||||
|
conn.Open();
|
||||||
|
|
||||||
|
if (cmd.ExecuteNonQuery() > 0)
|
||||||
|
{
|
||||||
|
//m_log.Warn("[MSSQLGenericTable]: " + deleteCommand);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,582 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) Contributors, http://opensimulator.org/
|
||||||
|
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* * Neither the name of the OpenSimulator Project nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||||
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||||
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
using System.Reflection;
|
||||||
|
using log4net;
|
||||||
|
using OpenMetaverse;
|
||||||
|
using OpenSim.Framework;
|
||||||
|
|
||||||
|
namespace OpenSim.Data.MSSQL
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A grid data interface for MSSQL Server
|
||||||
|
/// </summary>
|
||||||
|
public class MSSQLGridData : GridDataBase
|
||||||
|
{
|
||||||
|
private const string _migrationStore = "GridStore";
|
||||||
|
|
||||||
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Database manager
|
||||||
|
/// </summary>
|
||||||
|
private MSSQLManager database;
|
||||||
|
private string m_connectionString;
|
||||||
|
|
||||||
|
private string m_regionsTableName = "regions";
|
||||||
|
|
||||||
|
#region IPlugin Members
|
||||||
|
|
||||||
|
// [Obsolete("Cannot be default-initialized!")]
|
||||||
|
override public void Initialise()
|
||||||
|
{
|
||||||
|
m_log.Info("[GRID DB]: " + Name + " cannot be default-initialized!");
|
||||||
|
throw new PluginNotInitialisedException(Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initialises the Grid Interface
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connectionString">connect string</param>
|
||||||
|
/// <remarks>use mssql_connection.ini</remarks>
|
||||||
|
override public void Initialise(string connectionString)
|
||||||
|
{
|
||||||
|
m_connectionString = connectionString;
|
||||||
|
database = new MSSQLManager(connectionString);
|
||||||
|
|
||||||
|
//New migrations check of store
|
||||||
|
database.CheckMigration(_migrationStore);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shuts down the grid interface
|
||||||
|
/// </summary>
|
||||||
|
override public void Dispose()
|
||||||
|
{
|
||||||
|
database = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The name of this DB provider.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A string containing the storage system name</returns>
|
||||||
|
override public string Name
|
||||||
|
{
|
||||||
|
get { return "MSSQL OpenGridData"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Database provider version.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A string containing the storage system version</returns>
|
||||||
|
override public string Version
|
||||||
|
{
|
||||||
|
get { return "0.1"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Public override GridDataBase methods
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a list of regions within the specified ranges
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="xmin">minimum X coordinate</param>
|
||||||
|
/// <param name="ymin">minimum Y coordinate</param>
|
||||||
|
/// <param name="xmax">maximum X coordinate</param>
|
||||||
|
/// <param name="ymax">maximum Y coordinate</param>
|
||||||
|
/// <returns>null</returns>
|
||||||
|
/// <remarks>always return null</remarks>
|
||||||
|
override public RegionProfileData[] GetProfilesInRange(uint xmin, uint ymin, uint xmax, uint ymax)
|
||||||
|
{
|
||||||
|
string sql = "SELECT * FROM regions WHERE locX >= @xmin AND locX <= @xmax AND locY >= @ymin AND locY <= @ymax";
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(database.CreateParameter("xmin", xmin));
|
||||||
|
cmd.Parameters.Add(database.CreateParameter("ymin", ymin));
|
||||||
|
cmd.Parameters.Add(database.CreateParameter("xmax", xmax));
|
||||||
|
cmd.Parameters.Add(database.CreateParameter("ymax", ymax));
|
||||||
|
|
||||||
|
List<RegionProfileData> rows = new List<RegionProfileData>();
|
||||||
|
conn.Open();
|
||||||
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
rows.Add(ReadSimRow(reader));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rows.Count > 0)
|
||||||
|
{
|
||||||
|
return rows.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_log.Info("[GRID DB] : Found no regions within range.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns up to maxNum profiles of regions that have a name starting with namePrefix
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="namePrefix">The name to match against</param>
|
||||||
|
/// <param name="maxNum">Maximum number of profiles to return</param>
|
||||||
|
/// <returns>A list of sim profiles</returns>
|
||||||
|
override public List<RegionProfileData> GetRegionsByName (string namePrefix, uint maxNum)
|
||||||
|
{
|
||||||
|
string sql = "SELECT * FROM regions WHERE regionName LIKE @name";
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(database.CreateParameter("name", namePrefix + "%"));
|
||||||
|
|
||||||
|
List<RegionProfileData> rows = new List<RegionProfileData>();
|
||||||
|
conn.Open();
|
||||||
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||||
|
{
|
||||||
|
while (rows.Count < maxNum && reader.Read())
|
||||||
|
{
|
||||||
|
rows.Add(ReadSimRow(reader));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a sim profile from its location
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="handle">Region location handle</param>
|
||||||
|
/// <returns>Sim profile</returns>
|
||||||
|
override public RegionProfileData GetProfileByHandle(ulong handle)
|
||||||
|
{
|
||||||
|
string sql = "SELECT * FROM " + m_regionsTableName + " WHERE regionHandle = @handle";
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(database.CreateParameter("handle", handle));
|
||||||
|
conn.Open();
|
||||||
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||||
|
{
|
||||||
|
if (reader.Read())
|
||||||
|
{
|
||||||
|
return ReadSimRow(reader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_log.InfoFormat("[GRID DB] : No region found with handle : {0}", handle);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a sim profile from its UUID
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="uuid">The region UUID</param>
|
||||||
|
/// <returns>The sim profile</returns>
|
||||||
|
override public RegionProfileData GetProfileByUUID(UUID uuid)
|
||||||
|
{
|
||||||
|
string sql = "SELECT * FROM " + m_regionsTableName + " WHERE uuid = @uuid";
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(database.CreateParameter("uuid", uuid));
|
||||||
|
conn.Open();
|
||||||
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||||
|
{
|
||||||
|
if (reader.Read())
|
||||||
|
{
|
||||||
|
return ReadSimRow(reader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_log.InfoFormat("[GRID DB] : No region found with UUID : {0}", uuid);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a sim profile from it's Region name string
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="regionName">The region name search query</param>
|
||||||
|
/// <returns>The sim profile</returns>
|
||||||
|
override public RegionProfileData GetProfileByString(string regionName)
|
||||||
|
{
|
||||||
|
if (regionName.Length > 2)
|
||||||
|
{
|
||||||
|
string sql = "SELECT top 1 * FROM " + m_regionsTableName + " WHERE regionName like @regionName order by regionName";
|
||||||
|
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(database.CreateParameter("regionName", regionName + "%"));
|
||||||
|
conn.Open();
|
||||||
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||||
|
{
|
||||||
|
if (reader.Read())
|
||||||
|
{
|
||||||
|
return ReadSimRow(reader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_log.InfoFormat("[GRID DB] : No region found with regionName : {0}", regionName);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_log.Error("[GRID DB]: Searched for a Region Name shorter then 3 characters");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a new specified region to the database
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="profile">The profile to add</param>
|
||||||
|
/// <returns>A dataresponse enum indicating success</returns>
|
||||||
|
override public DataResponse StoreProfile(RegionProfileData profile)
|
||||||
|
{
|
||||||
|
if (GetProfileByUUID(profile.UUID) == null)
|
||||||
|
{
|
||||||
|
if (InsertRegionRow(profile))
|
||||||
|
{
|
||||||
|
return DataResponse.RESPONSE_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (UpdateRegionRow(profile))
|
||||||
|
{
|
||||||
|
return DataResponse.RESPONSE_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return DataResponse.RESPONSE_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes a sim profile from the database
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="uuid">the sim UUID</param>
|
||||||
|
/// <returns>Successful?</returns>
|
||||||
|
//public DataResponse DeleteProfile(RegionProfileData profile)
|
||||||
|
override public DataResponse DeleteProfile(string uuid)
|
||||||
|
{
|
||||||
|
string sql = "DELETE FROM regions WHERE uuid = @uuid;";
|
||||||
|
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(database.CreateParameter("uuid", uuid));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
return DataResponse.RESPONSE_OK;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[GRID DB] : Error deleting region info, error is : {0}", e.Message);
|
||||||
|
return DataResponse.RESPONSE_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods that are not used or deprecated (still needed because of base class)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// DEPRECATED. Attempts to authenticate a region by comparing a shared secret.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="uuid">The UUID of the challenger</param>
|
||||||
|
/// <param name="handle">The attempted regionHandle of the challenger</param>
|
||||||
|
/// <param name="authkey">The secret</param>
|
||||||
|
/// <returns>Whether the secret and regionhandle match the database entry for UUID</returns>
|
||||||
|
override public bool AuthenticateSim(UUID uuid, ulong handle, string authkey)
|
||||||
|
{
|
||||||
|
bool throwHissyFit = false; // Should be true by 1.0
|
||||||
|
|
||||||
|
if (throwHissyFit)
|
||||||
|
throw new Exception("CRYPTOWEAK AUTHENTICATE: Refusing to authenticate due to replay potential.");
|
||||||
|
|
||||||
|
RegionProfileData data = GetProfileByUUID(uuid);
|
||||||
|
|
||||||
|
return (handle == data.regionHandle && authkey == data.regionSecret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// NOT YET FUNCTIONAL. Provides a cryptographic authentication of a region
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>This requires a security audit.</remarks>
|
||||||
|
/// <param name="uuid"></param>
|
||||||
|
/// <param name="handle"></param>
|
||||||
|
/// <param name="authhash"></param>
|
||||||
|
/// <param name="challenge"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool AuthenticateSim(UUID uuid, ulong handle, string authhash, string challenge)
|
||||||
|
{
|
||||||
|
// SHA512Managed HashProvider = new SHA512Managed();
|
||||||
|
// Encoding TextProvider = new UTF8Encoding();
|
||||||
|
|
||||||
|
// byte[] stream = TextProvider.GetBytes(uuid.ToString() + ":" + handle.ToString() + ":" + challenge);
|
||||||
|
// byte[] hash = HashProvider.ComputeHash(stream);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// NOT IMPLEMENTED
|
||||||
|
/// WHEN IS THIS GONNA BE IMPLEMENTED.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x"></param>
|
||||||
|
/// <param name="y"></param>
|
||||||
|
/// <returns>null</returns>
|
||||||
|
override public ReservationData GetReservationAtPoint(uint x, uint y)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region private methods
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads a region row from a database reader
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="reader">An active database reader</param>
|
||||||
|
/// <returns>A region profile</returns>
|
||||||
|
private static RegionProfileData ReadSimRow(IDataRecord reader)
|
||||||
|
{
|
||||||
|
RegionProfileData retval = new RegionProfileData();
|
||||||
|
|
||||||
|
// Region Main gotta-have-or-we-return-null parts
|
||||||
|
UInt64 tmp64;
|
||||||
|
if (!UInt64.TryParse(reader["regionHandle"].ToString(), out tmp64))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
retval.regionHandle = tmp64;
|
||||||
|
|
||||||
|
// UUID tmp_uuid;
|
||||||
|
// if (!UUID.TryParse((string)reader["uuid"], out tmp_uuid))
|
||||||
|
// {
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
|
||||||
|
retval.UUID = new UUID((Guid)reader["uuid"]); // tmp_uuid;
|
||||||
|
|
||||||
|
// non-critical parts
|
||||||
|
retval.regionName = reader["regionName"].ToString();
|
||||||
|
retval.originUUID = new UUID((Guid)reader["originUUID"]);
|
||||||
|
|
||||||
|
// Secrets
|
||||||
|
retval.regionRecvKey = reader["regionRecvKey"].ToString();
|
||||||
|
retval.regionSecret = reader["regionSecret"].ToString();
|
||||||
|
retval.regionSendKey = reader["regionSendKey"].ToString();
|
||||||
|
|
||||||
|
// Region Server
|
||||||
|
retval.regionDataURI = reader["regionDataURI"].ToString();
|
||||||
|
retval.regionOnline = false; // Needs to be pinged before this can be set.
|
||||||
|
retval.serverIP = reader["serverIP"].ToString();
|
||||||
|
retval.serverPort = Convert.ToUInt32(reader["serverPort"]);
|
||||||
|
retval.serverURI = reader["serverURI"].ToString();
|
||||||
|
retval.httpPort = Convert.ToUInt32(reader["serverHttpPort"].ToString());
|
||||||
|
retval.remotingPort = Convert.ToUInt32(reader["serverRemotingPort"].ToString());
|
||||||
|
|
||||||
|
// Location
|
||||||
|
retval.regionLocX = Convert.ToUInt32(reader["locX"].ToString());
|
||||||
|
retval.regionLocY = Convert.ToUInt32(reader["locY"].ToString());
|
||||||
|
retval.regionLocZ = Convert.ToUInt32(reader["locZ"].ToString());
|
||||||
|
|
||||||
|
// Neighbours - 0 = No Override
|
||||||
|
retval.regionEastOverrideHandle = Convert.ToUInt64(reader["eastOverrideHandle"].ToString());
|
||||||
|
retval.regionWestOverrideHandle = Convert.ToUInt64(reader["westOverrideHandle"].ToString());
|
||||||
|
retval.regionSouthOverrideHandle = Convert.ToUInt64(reader["southOverrideHandle"].ToString());
|
||||||
|
retval.regionNorthOverrideHandle = Convert.ToUInt64(reader["northOverrideHandle"].ToString());
|
||||||
|
|
||||||
|
// Assets
|
||||||
|
retval.regionAssetURI = reader["regionAssetURI"].ToString();
|
||||||
|
retval.regionAssetRecvKey = reader["regionAssetRecvKey"].ToString();
|
||||||
|
retval.regionAssetSendKey = reader["regionAssetSendKey"].ToString();
|
||||||
|
|
||||||
|
// Userserver
|
||||||
|
retval.regionUserURI = reader["regionUserURI"].ToString();
|
||||||
|
retval.regionUserRecvKey = reader["regionUserRecvKey"].ToString();
|
||||||
|
retval.regionUserSendKey = reader["regionUserSendKey"].ToString();
|
||||||
|
|
||||||
|
// World Map Addition
|
||||||
|
retval.regionMapTextureID = new UUID((Guid)reader["regionMapTexture"]);
|
||||||
|
retval.owner_uuid = new UUID((Guid)reader["owner_uuid"]);
|
||||||
|
retval.maturity = Convert.ToUInt32(reader["access"]);
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update the specified region in the database
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="profile">The profile to update</param>
|
||||||
|
/// <returns>success ?</returns>
|
||||||
|
private bool UpdateRegionRow(RegionProfileData profile)
|
||||||
|
{
|
||||||
|
bool returnval = false;
|
||||||
|
|
||||||
|
//Insert new region
|
||||||
|
string sql =
|
||||||
|
"UPDATE " + m_regionsTableName + @" SET
|
||||||
|
[regionHandle]=@regionHandle, [regionName]=@regionName,
|
||||||
|
[regionRecvKey]=@regionRecvKey, [regionSecret]=@regionSecret, [regionSendKey]=@regionSendKey,
|
||||||
|
[regionDataURI]=@regionDataURI, [serverIP]=@serverIP, [serverPort]=@serverPort, [serverURI]=@serverURI,
|
||||||
|
[locX]=@locX, [locY]=@locY, [locZ]=@locZ, [eastOverrideHandle]=@eastOverrideHandle,
|
||||||
|
[westOverrideHandle]=@westOverrideHandle, [southOverrideHandle]=@southOverrideHandle,
|
||||||
|
[northOverrideHandle]=@northOverrideHandle, [regionAssetURI]=@regionAssetURI,
|
||||||
|
[regionAssetRecvKey]=@regionAssetRecvKey, [regionAssetSendKey]=@regionAssetSendKey,
|
||||||
|
[regionUserURI]=@regionUserURI, [regionUserRecvKey]=@regionUserRecvKey, [regionUserSendKey]=@regionUserSendKey,
|
||||||
|
[regionMapTexture]=@regionMapTexture, [serverHttpPort]=@serverHttpPort,
|
||||||
|
[serverRemotingPort]=@serverRemotingPort, [owner_uuid]=@owner_uuid , [originUUID]=@originUUID
|
||||||
|
where [uuid]=@uuid";
|
||||||
|
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand command = new SqlCommand(sql, conn))
|
||||||
|
{
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionHandle", profile.regionHandle));
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionName", profile.regionName));
|
||||||
|
command.Parameters.Add(database.CreateParameter("uuid", profile.UUID));
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionRecvKey", profile.regionRecvKey));
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionSecret", profile.regionSecret));
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionSendKey", profile.regionSendKey));
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionDataURI", profile.regionDataURI));
|
||||||
|
command.Parameters.Add(database.CreateParameter("serverIP", profile.serverIP));
|
||||||
|
command.Parameters.Add(database.CreateParameter("serverPort", profile.serverPort));
|
||||||
|
command.Parameters.Add(database.CreateParameter("serverURI", profile.serverURI));
|
||||||
|
command.Parameters.Add(database.CreateParameter("locX", profile.regionLocX));
|
||||||
|
command.Parameters.Add(database.CreateParameter("locY", profile.regionLocY));
|
||||||
|
command.Parameters.Add(database.CreateParameter("locZ", profile.regionLocZ));
|
||||||
|
command.Parameters.Add(database.CreateParameter("eastOverrideHandle", profile.regionEastOverrideHandle));
|
||||||
|
command.Parameters.Add(database.CreateParameter("westOverrideHandle", profile.regionWestOverrideHandle));
|
||||||
|
command.Parameters.Add(database.CreateParameter("northOverrideHandle", profile.regionNorthOverrideHandle));
|
||||||
|
command.Parameters.Add(database.CreateParameter("southOverrideHandle", profile.regionSouthOverrideHandle));
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionAssetURI", profile.regionAssetURI));
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionAssetRecvKey", profile.regionAssetRecvKey));
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionAssetSendKey", profile.regionAssetSendKey));
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionUserURI", profile.regionUserURI));
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionUserRecvKey", profile.regionUserRecvKey));
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionUserSendKey", profile.regionUserSendKey));
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionMapTexture", profile.regionMapTextureID));
|
||||||
|
command.Parameters.Add(database.CreateParameter("serverHttpPort", profile.httpPort));
|
||||||
|
command.Parameters.Add(database.CreateParameter("serverRemotingPort", profile.remotingPort));
|
||||||
|
command.Parameters.Add(database.CreateParameter("owner_uuid", profile.owner_uuid));
|
||||||
|
command.Parameters.Add(database.CreateParameter("originUUID", profile.originUUID));
|
||||||
|
conn.Open();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
command.ExecuteNonQuery();
|
||||||
|
returnval = true;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
m_log.Error("[GRID DB] : Error updating region, error: " + e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnval;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new region in the database
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="profile">The region profile to insert</param>
|
||||||
|
/// <returns>Successful?</returns>
|
||||||
|
private bool InsertRegionRow(RegionProfileData profile)
|
||||||
|
{
|
||||||
|
bool returnval = false;
|
||||||
|
|
||||||
|
//Insert new region
|
||||||
|
string sql =
|
||||||
|
"INSERT INTO " + m_regionsTableName + @" ([regionHandle], [regionName], [uuid], [regionRecvKey], [regionSecret], [regionSendKey], [regionDataURI],
|
||||||
|
[serverIP], [serverPort], [serverURI], [locX], [locY], [locZ], [eastOverrideHandle], [westOverrideHandle],
|
||||||
|
[southOverrideHandle], [northOverrideHandle], [regionAssetURI], [regionAssetRecvKey], [regionAssetSendKey],
|
||||||
|
[regionUserURI], [regionUserRecvKey], [regionUserSendKey], [regionMapTexture], [serverHttpPort],
|
||||||
|
[serverRemotingPort], [owner_uuid], [originUUID], [access])
|
||||||
|
VALUES (@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI,
|
||||||
|
@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle,
|
||||||
|
@southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, @regionAssetSendKey,
|
||||||
|
@regionUserURI, @regionUserRecvKey, @regionUserSendKey, @regionMapTexture, @serverHttpPort, @serverRemotingPort, @owner_uuid, @originUUID, @access);";
|
||||||
|
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand command = new SqlCommand(sql, conn))
|
||||||
|
{
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionHandle", profile.regionHandle));
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionName", profile.regionName));
|
||||||
|
command.Parameters.Add(database.CreateParameter("uuid", profile.UUID));
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionRecvKey", profile.regionRecvKey));
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionSecret", profile.regionSecret));
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionSendKey", profile.regionSendKey));
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionDataURI", profile.regionDataURI));
|
||||||
|
command.Parameters.Add(database.CreateParameter("serverIP", profile.serverIP));
|
||||||
|
command.Parameters.Add(database.CreateParameter("serverPort", profile.serverPort));
|
||||||
|
command.Parameters.Add(database.CreateParameter("serverURI", profile.serverURI));
|
||||||
|
command.Parameters.Add(database.CreateParameter("locX", profile.regionLocX));
|
||||||
|
command.Parameters.Add(database.CreateParameter("locY", profile.regionLocY));
|
||||||
|
command.Parameters.Add(database.CreateParameter("locZ", profile.regionLocZ));
|
||||||
|
command.Parameters.Add(database.CreateParameter("eastOverrideHandle", profile.regionEastOverrideHandle));
|
||||||
|
command.Parameters.Add(database.CreateParameter("westOverrideHandle", profile.regionWestOverrideHandle));
|
||||||
|
command.Parameters.Add(database.CreateParameter("northOverrideHandle", profile.regionNorthOverrideHandle));
|
||||||
|
command.Parameters.Add(database.CreateParameter("southOverrideHandle", profile.regionSouthOverrideHandle));
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionAssetURI", profile.regionAssetURI));
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionAssetRecvKey", profile.regionAssetRecvKey));
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionAssetSendKey", profile.regionAssetSendKey));
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionUserURI", profile.regionUserURI));
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionUserRecvKey", profile.regionUserRecvKey));
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionUserSendKey", profile.regionUserSendKey));
|
||||||
|
command.Parameters.Add(database.CreateParameter("regionMapTexture", profile.regionMapTextureID));
|
||||||
|
command.Parameters.Add(database.CreateParameter("serverHttpPort", profile.httpPort));
|
||||||
|
command.Parameters.Add(database.CreateParameter("serverRemotingPort", profile.remotingPort));
|
||||||
|
command.Parameters.Add(database.CreateParameter("owner_uuid", profile.owner_uuid));
|
||||||
|
command.Parameters.Add(database.CreateParameter("originUUID", profile.originUUID));
|
||||||
|
command.Parameters.Add(database.CreateParameter("access", profile.maturity));
|
||||||
|
conn.Open();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
command.ExecuteNonQuery();
|
||||||
|
returnval = true;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
m_log.Error("[GRID DB] : Error inserting region, error: " + e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnval;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
|
@ -49,6 +49,7 @@ namespace OpenSim.Data.MSSQL
|
||||||
/// The database manager
|
/// The database manager
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private MSSQLManager database;
|
private MSSQLManager database;
|
||||||
|
private string m_connectionString;
|
||||||
|
|
||||||
#region IPlugin members
|
#region IPlugin members
|
||||||
|
|
||||||
|
@ -66,23 +67,8 @@ namespace OpenSim.Data.MSSQL
|
||||||
/// <remarks>use mssql_connection.ini</remarks>
|
/// <remarks>use mssql_connection.ini</remarks>
|
||||||
public void Initialise(string connectionString)
|
public void Initialise(string connectionString)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(connectionString))
|
m_connectionString = connectionString;
|
||||||
{
|
database = new MSSQLManager(connectionString);
|
||||||
database = new MSSQLManager(connectionString);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
IniFile gridDataMSSqlFile = new IniFile("mssql_connection.ini");
|
|
||||||
string settingDataSource = gridDataMSSqlFile.ParseFileReadValue("data_source");
|
|
||||||
string settingInitialCatalog = gridDataMSSqlFile.ParseFileReadValue("initial_catalog");
|
|
||||||
string settingPersistSecurityInfo = gridDataMSSqlFile.ParseFileReadValue("persist_security_info");
|
|
||||||
string settingUserId = gridDataMSSqlFile.ParseFileReadValue("user_id");
|
|
||||||
string settingPassword = gridDataMSSqlFile.ParseFileReadValue("password");
|
|
||||||
|
|
||||||
database =
|
|
||||||
new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId,
|
|
||||||
settingPassword);
|
|
||||||
}
|
|
||||||
|
|
||||||
//New migrations check of store
|
//New migrations check of store
|
||||||
database.CheckMigration(_migrationStore);
|
database.CheckMigration(_migrationStore);
|
||||||
|
@ -169,11 +155,13 @@ namespace OpenSim.Data.MSSQL
|
||||||
/// <returns>A folder class</returns>
|
/// <returns>A folder class</returns>
|
||||||
public InventoryFolderBase getInventoryFolder(UUID folderID)
|
public InventoryFolderBase getInventoryFolder(UUID folderID)
|
||||||
{
|
{
|
||||||
using (AutoClosingSqlCommand command = database.Query("SELECT * FROM inventoryfolders WHERE folderID = @folderID"))
|
string sql = "SELECT * FROM inventoryfolders WHERE folderID = @folderID";
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
command.Parameters.Add(database.CreateParameter("folderID", folderID));
|
cmd.Parameters.Add(database.CreateParameter("folderID", folderID));
|
||||||
|
conn.Open();
|
||||||
using (IDataReader reader = command.ExecuteReader())
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
if (reader.Read())
|
if (reader.Read())
|
||||||
{
|
{
|
||||||
|
@ -197,18 +185,19 @@ namespace OpenSim.Data.MSSQL
|
||||||
//Note this is changed so it opens only one connection to the database and not everytime it wants to get data.
|
//Note this is changed so it opens only one connection to the database and not everytime it wants to get data.
|
||||||
|
|
||||||
List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
|
List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
|
||||||
|
string sql = "SELECT * FROM inventoryfolders WHERE parentFolderID = @parentID";
|
||||||
using (AutoClosingSqlCommand command = database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = @parentID"))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
command.Parameters.Add(database.CreateParameter("@parentID", parentID));
|
cmd.Parameters.Add(database.CreateParameter("@parentID", parentID));
|
||||||
|
conn.Open();
|
||||||
folders.AddRange(getInventoryFolders(command));
|
folders.AddRange(getInventoryFolders(cmd));
|
||||||
|
|
||||||
List<InventoryFolderBase> tempFolders = new List<InventoryFolderBase>();
|
List<InventoryFolderBase> tempFolders = new List<InventoryFolderBase>();
|
||||||
|
|
||||||
foreach (InventoryFolderBase folderBase in folders)
|
foreach (InventoryFolderBase folderBase in folders)
|
||||||
{
|
{
|
||||||
tempFolders.AddRange(getFolderHierarchy(folderBase.ID, command));
|
tempFolders.AddRange(getFolderHierarchy(folderBase.ID, cmd));
|
||||||
}
|
}
|
||||||
if (tempFolders.Count > 0)
|
if (tempFolders.Count > 0)
|
||||||
{
|
{
|
||||||
|
@ -233,20 +222,19 @@ namespace OpenSim.Data.MSSQL
|
||||||
folderName = folderName.Substring(0, 64);
|
folderName = folderName.Substring(0, 64);
|
||||||
m_log.Warn("[INVENTORY DB]: Name field truncated from " + folder.Name.Length.ToString() + " to " + folderName.Length + " characters on add");
|
m_log.Warn("[INVENTORY DB]: Name field truncated from " + folder.Name.Length.ToString() + " to " + folderName.Length + " characters on add");
|
||||||
}
|
}
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
using (AutoClosingSqlCommand command = database.Query(sql))
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
command.Parameters.Add(database.CreateParameter("folderID", folder.ID));
|
cmd.Parameters.Add(database.CreateParameter("folderID", folder.ID));
|
||||||
command.Parameters.Add(database.CreateParameter("agentID", folder.Owner));
|
cmd.Parameters.Add(database.CreateParameter("agentID", folder.Owner));
|
||||||
command.Parameters.Add(database.CreateParameter("parentFolderID", folder.ParentID));
|
cmd.Parameters.Add(database.CreateParameter("parentFolderID", folder.ParentID));
|
||||||
command.Parameters.Add(database.CreateParameter("folderName", folderName));
|
cmd.Parameters.Add(database.CreateParameter("folderName", folderName));
|
||||||
command.Parameters.Add(database.CreateParameter("type", folder.Type));
|
cmd.Parameters.Add(database.CreateParameter("type", folder.Type));
|
||||||
command.Parameters.Add(database.CreateParameter("version", folder.Version));
|
cmd.Parameters.Add(database.CreateParameter("version", folder.Version));
|
||||||
|
conn.Open();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//IDbCommand result = database.Query(sql, param);
|
cmd.ExecuteNonQuery();
|
||||||
command.ExecuteNonQuery();
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -275,20 +263,20 @@ namespace OpenSim.Data.MSSQL
|
||||||
folderName = folderName.Substring(0, 64);
|
folderName = folderName.Substring(0, 64);
|
||||||
m_log.Warn("[INVENTORY DB]: Name field truncated from " + folder.Name.Length.ToString() + " to " + folderName.Length + " characters on update");
|
m_log.Warn("[INVENTORY DB]: Name field truncated from " + folder.Name.Length.ToString() + " to " + folderName.Length + " characters on update");
|
||||||
}
|
}
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
using (AutoClosingSqlCommand command = database.Query(sql))
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
command.Parameters.Add(database.CreateParameter("folderID", folder.ID));
|
cmd.Parameters.Add(database.CreateParameter("folderID", folder.ID));
|
||||||
command.Parameters.Add(database.CreateParameter("agentID", folder.Owner));
|
cmd.Parameters.Add(database.CreateParameter("agentID", folder.Owner));
|
||||||
command.Parameters.Add(database.CreateParameter("parentFolderID", folder.ParentID));
|
cmd.Parameters.Add(database.CreateParameter("parentFolderID", folder.ParentID));
|
||||||
command.Parameters.Add(database.CreateParameter("folderName", folderName));
|
cmd.Parameters.Add(database.CreateParameter("folderName", folderName));
|
||||||
command.Parameters.Add(database.CreateParameter("type", folder.Type));
|
cmd.Parameters.Add(database.CreateParameter("type", folder.Type));
|
||||||
command.Parameters.Add(database.CreateParameter("version", folder.Version));
|
cmd.Parameters.Add(database.CreateParameter("version", folder.Version));
|
||||||
command.Parameters.Add(database.CreateParameter("@keyFolderID", folder.ID));
|
cmd.Parameters.Add(database.CreateParameter("@keyFolderID", folder.ID));
|
||||||
|
conn.Open();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
command.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -304,14 +292,15 @@ namespace OpenSim.Data.MSSQL
|
||||||
public void moveInventoryFolder(InventoryFolderBase folder)
|
public void moveInventoryFolder(InventoryFolderBase folder)
|
||||||
{
|
{
|
||||||
string sql = @"UPDATE inventoryfolders SET parentFolderID = @parentFolderID WHERE folderID = @folderID";
|
string sql = @"UPDATE inventoryfolders SET parentFolderID = @parentFolderID WHERE folderID = @folderID";
|
||||||
using (IDbCommand command = database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
command.Parameters.Add(database.CreateParameter("parentFolderID", folder.ParentID));
|
cmd.Parameters.Add(database.CreateParameter("parentFolderID", folder.ParentID));
|
||||||
command.Parameters.Add(database.CreateParameter("@folderID", folder.ID));
|
cmd.Parameters.Add(database.CreateParameter("@folderID", folder.ID));
|
||||||
|
conn.Open();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
command.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -326,30 +315,27 @@ namespace OpenSim.Data.MSSQL
|
||||||
/// <param name="folderID">Id of folder to delete</param>
|
/// <param name="folderID">Id of folder to delete</param>
|
||||||
public void deleteInventoryFolder(UUID folderID)
|
public void deleteInventoryFolder(UUID folderID)
|
||||||
{
|
{
|
||||||
using (SqlConnection connection = database.DatabaseConnection())
|
string sql = "SELECT * FROM inventoryfolders WHERE parentFolderID = @parentID";
|
||||||
|
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
List<InventoryFolderBase> subFolders;
|
List<InventoryFolderBase> subFolders;
|
||||||
using (SqlCommand command = new SqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = @parentID", connection))
|
cmd.Parameters.Add(database.CreateParameter("@parentID", UUID.Zero));
|
||||||
{
|
conn.Open();
|
||||||
command.Parameters.Add(database.CreateParameter("@parentID", UUID.Zero));
|
subFolders = getFolderHierarchy(folderID, cmd);
|
||||||
|
|
||||||
AutoClosingSqlCommand autoCommand = new AutoClosingSqlCommand(command);
|
|
||||||
|
|
||||||
subFolders = getFolderHierarchy(folderID, autoCommand);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Delete all sub-folders
|
//Delete all sub-folders
|
||||||
foreach (InventoryFolderBase f in subFolders)
|
foreach (InventoryFolderBase f in subFolders)
|
||||||
{
|
{
|
||||||
DeleteOneFolder(f.ID, connection);
|
DeleteOneFolder(f.ID, conn);
|
||||||
DeleteItemsInFolder(f.ID, connection);
|
DeleteItemsInFolder(f.ID, conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Delete the actual row
|
//Delete the actual row
|
||||||
DeleteOneFolder(folderID, connection);
|
DeleteOneFolder(folderID, conn);
|
||||||
DeleteItemsInFolder(folderID, connection);
|
DeleteItemsInFolder(folderID, conn);
|
||||||
|
|
||||||
connection.Close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,13 +350,15 @@ namespace OpenSim.Data.MSSQL
|
||||||
/// <returns>A list containing inventory items</returns>
|
/// <returns>A list containing inventory items</returns>
|
||||||
public List<InventoryItemBase> getInventoryInFolder(UUID folderID)
|
public List<InventoryItemBase> getInventoryInFolder(UUID folderID)
|
||||||
{
|
{
|
||||||
using (AutoClosingSqlCommand command = database.Query("SELECT * FROM inventoryitems WHERE parentFolderID = @parentFolderID"))
|
string sql = "SELECT * FROM inventoryitems WHERE parentFolderID = @parentFolderID";
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
command.Parameters.Add(database.CreateParameter("parentFolderID", folderID));
|
cmd.Parameters.Add(database.CreateParameter("parentFolderID", folderID));
|
||||||
|
conn.Open();
|
||||||
List<InventoryItemBase> items = new List<InventoryItemBase>();
|
List<InventoryItemBase> items = new List<InventoryItemBase>();
|
||||||
|
|
||||||
using (SqlDataReader reader = command.ExecuteReader())
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
|
@ -388,11 +376,13 @@ namespace OpenSim.Data.MSSQL
|
||||||
/// <returns>An inventory item</returns>
|
/// <returns>An inventory item</returns>
|
||||||
public InventoryItemBase getInventoryItem(UUID itemID)
|
public InventoryItemBase getInventoryItem(UUID itemID)
|
||||||
{
|
{
|
||||||
using (AutoClosingSqlCommand result = database.Query("SELECT * FROM inventoryitems WHERE inventoryID = @inventoryID"))
|
string sql = "SELECT * FROM inventoryitems WHERE inventoryID = @inventoryID";
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
result.Parameters.Add(database.CreateParameter("inventoryID", itemID));
|
cmd.Parameters.Add(database.CreateParameter("inventoryID", itemID));
|
||||||
|
conn.Open();
|
||||||
using (IDataReader reader = result.ExecuteReader())
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
if (reader.Read())
|
if (reader.Read())
|
||||||
{
|
{
|
||||||
|
@ -442,7 +432,8 @@ namespace OpenSim.Data.MSSQL
|
||||||
m_log.Warn("[INVENTORY DB]: Description field truncated from " + item.Description.Length.ToString() + " to " + itemDesc.Length.ToString() + " characters");
|
m_log.Warn("[INVENTORY DB]: Description field truncated from " + item.Description.Length.ToString() + " to " + itemDesc.Length.ToString() + " characters");
|
||||||
}
|
}
|
||||||
|
|
||||||
using (AutoClosingSqlCommand command = database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand command = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
command.Parameters.Add(database.CreateParameter("inventoryID", item.ID));
|
command.Parameters.Add(database.CreateParameter("inventoryID", item.ID));
|
||||||
command.Parameters.Add(database.CreateParameter("assetID", item.AssetID));
|
command.Parameters.Add(database.CreateParameter("assetID", item.AssetID));
|
||||||
|
@ -464,7 +455,7 @@ namespace OpenSim.Data.MSSQL
|
||||||
command.Parameters.Add(database.CreateParameter("groupID", item.GroupID));
|
command.Parameters.Add(database.CreateParameter("groupID", item.GroupID));
|
||||||
command.Parameters.Add(database.CreateParameter("groupOwned", item.GroupOwned));
|
command.Parameters.Add(database.CreateParameter("groupOwned", item.GroupOwned));
|
||||||
command.Parameters.Add(database.CreateParameter("flags", item.Flags));
|
command.Parameters.Add(database.CreateParameter("flags", item.Flags));
|
||||||
|
conn.Open();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
|
@ -476,9 +467,11 @@ namespace OpenSim.Data.MSSQL
|
||||||
}
|
}
|
||||||
|
|
||||||
sql = "UPDATE inventoryfolders SET version = version + 1 WHERE folderID = @folderID";
|
sql = "UPDATE inventoryfolders SET version = version + 1 WHERE folderID = @folderID";
|
||||||
using (AutoClosingSqlCommand command = database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand command = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
command.Parameters.Add(database.CreateParameter("folderID", item.Folder.ToString()));
|
command.Parameters.Add(database.CreateParameter("folderID", item.Folder.ToString()));
|
||||||
|
conn.Open();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
|
@ -531,7 +524,8 @@ namespace OpenSim.Data.MSSQL
|
||||||
m_log.Warn("[INVENTORY DB]: Description field truncated from " + item.Description.Length.ToString() + " to " + itemDesc.Length.ToString() + " characters on update");
|
m_log.Warn("[INVENTORY DB]: Description field truncated from " + item.Description.Length.ToString() + " to " + itemDesc.Length.ToString() + " characters on update");
|
||||||
}
|
}
|
||||||
|
|
||||||
using (AutoClosingSqlCommand command = database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand command = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
command.Parameters.Add(database.CreateParameter("inventoryID", item.ID));
|
command.Parameters.Add(database.CreateParameter("inventoryID", item.ID));
|
||||||
command.Parameters.Add(database.CreateParameter("assetID", item.AssetID));
|
command.Parameters.Add(database.CreateParameter("assetID", item.AssetID));
|
||||||
|
@ -552,8 +546,8 @@ namespace OpenSim.Data.MSSQL
|
||||||
command.Parameters.Add(database.CreateParameter("groupID", item.GroupID));
|
command.Parameters.Add(database.CreateParameter("groupID", item.GroupID));
|
||||||
command.Parameters.Add(database.CreateParameter("groupOwned", item.GroupOwned));
|
command.Parameters.Add(database.CreateParameter("groupOwned", item.GroupOwned));
|
||||||
command.Parameters.Add(database.CreateParameter("flags", item.Flags));
|
command.Parameters.Add(database.CreateParameter("flags", item.Flags));
|
||||||
command.Parameters.Add(database.CreateParameter("@keyInventoryID", item.ID));
|
command.Parameters.Add(database.CreateParameter("keyInventoryID", item.ID));
|
||||||
|
conn.Open();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
|
@ -573,13 +567,15 @@ namespace OpenSim.Data.MSSQL
|
||||||
/// <param name="itemID">the item UUID</param>
|
/// <param name="itemID">the item UUID</param>
|
||||||
public void deleteInventoryItem(UUID itemID)
|
public void deleteInventoryItem(UUID itemID)
|
||||||
{
|
{
|
||||||
using (AutoClosingSqlCommand command = database.Query("DELETE FROM inventoryitems WHERE inventoryID=@inventoryID"))
|
string sql = "DELETE FROM inventoryitems WHERE inventoryID=@inventoryID";
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
command.Parameters.Add(database.CreateParameter("inventoryID", itemID));
|
cmd.Parameters.Add(database.CreateParameter("inventoryID", itemID));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
conn.Open();
|
||||||
command.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -607,12 +603,14 @@ namespace OpenSim.Data.MSSQL
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public List<InventoryItemBase> fetchActiveGestures(UUID avatarID)
|
public List<InventoryItemBase> fetchActiveGestures(UUID avatarID)
|
||||||
{
|
{
|
||||||
using (AutoClosingSqlCommand command = database.Query("SELECT * FROM inventoryitems WHERE avatarId = @uuid AND assetType = @assetType and flags = 1"))
|
string sql = "SELECT * FROM inventoryitems WHERE avatarId = @uuid AND assetType = @assetType and flags = 1";
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
command.Parameters.Add(database.CreateParameter("uuid", avatarID));
|
cmd.Parameters.Add(database.CreateParameter("uuid", avatarID));
|
||||||
command.Parameters.Add(database.CreateParameter("assetType", (int)AssetType.Gesture));
|
cmd.Parameters.Add(database.CreateParameter("assetType", (int)AssetType.Gesture));
|
||||||
|
conn.Open();
|
||||||
using (IDataReader reader = command.ExecuteReader())
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
List<InventoryItemBase> gestureList = new List<InventoryItemBase>();
|
List<InventoryItemBase> gestureList = new List<InventoryItemBase>();
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
|
@ -656,7 +654,7 @@ namespace OpenSim.Data.MSSQL
|
||||||
/// <param name="parentID">parent ID.</param>
|
/// <param name="parentID">parent ID.</param>
|
||||||
/// <param name="command">SQL command/connection to database</param>
|
/// <param name="command">SQL command/connection to database</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private static List<InventoryFolderBase> getFolderHierarchy(UUID parentID, AutoClosingSqlCommand command)
|
private static List<InventoryFolderBase> getFolderHierarchy(UUID parentID, SqlCommand command)
|
||||||
{
|
{
|
||||||
command.Parameters["@parentID"].Value = parentID.Guid; //.ToString();
|
command.Parameters["@parentID"].Value = parentID.Guid; //.ToString();
|
||||||
|
|
||||||
|
@ -687,7 +685,9 @@ namespace OpenSim.Data.MSSQL
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private List<InventoryFolderBase> getInventoryFolders(UUID parentID, UUID user)
|
private List<InventoryFolderBase> getInventoryFolders(UUID parentID, UUID user)
|
||||||
{
|
{
|
||||||
using (AutoClosingSqlCommand command = database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = @parentID AND agentID LIKE @uuid"))
|
string sql = "SELECT * FROM inventoryfolders WHERE parentFolderID = @parentID AND agentID LIKE @uuid";
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand command = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
if (user == UUID.Zero)
|
if (user == UUID.Zero)
|
||||||
{
|
{
|
||||||
|
@ -698,7 +698,7 @@ namespace OpenSim.Data.MSSQL
|
||||||
command.Parameters.Add(database.CreateParameter("uuid", user));
|
command.Parameters.Add(database.CreateParameter("uuid", user));
|
||||||
}
|
}
|
||||||
command.Parameters.Add(database.CreateParameter("parentID", parentID));
|
command.Parameters.Add(database.CreateParameter("parentID", parentID));
|
||||||
|
conn.Open();
|
||||||
return getInventoryFolders(command);
|
return getInventoryFolders(command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -708,9 +708,9 @@ namespace OpenSim.Data.MSSQL
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="command">SQLcommand.</param>
|
/// <param name="command">SQLcommand.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private static List<InventoryFolderBase> getInventoryFolders(AutoClosingSqlCommand command)
|
private static List<InventoryFolderBase> getInventoryFolders(SqlCommand command)
|
||||||
{
|
{
|
||||||
using (IDataReader reader = command.ExecuteReader())
|
using (SqlDataReader reader = command.ExecuteReader())
|
||||||
{
|
{
|
||||||
|
|
||||||
List<InventoryFolderBase> items = new List<InventoryFolderBase>();
|
List<InventoryFolderBase> items = new List<InventoryFolderBase>();
|
||||||
|
@ -727,7 +727,7 @@ namespace OpenSim.Data.MSSQL
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="reader">A MSSQL Data Reader</param>
|
/// <param name="reader">A MSSQL Data Reader</param>
|
||||||
/// <returns>A List containing inventory folders</returns>
|
/// <returns>A List containing inventory folders</returns>
|
||||||
protected static InventoryFolderBase readInventoryFolder(IDataReader reader)
|
protected static InventoryFolderBase readInventoryFolder(SqlDataReader reader)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -54,28 +54,16 @@ namespace OpenSim.Data.MSSQL
|
||||||
/// The database manager
|
/// The database manager
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private MSSQLManager _Database;
|
private MSSQLManager _Database;
|
||||||
|
private string m_connectionString;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initialises the region datastore
|
/// Initialises the region datastore
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="connectionString">The connection string.</param>
|
/// <param name="connectionString">The connection string.</param>
|
||||||
public void Initialise(string connectionString)
|
public void Initialise(string connectionString)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(connectionString))
|
m_connectionString = connectionString;
|
||||||
{
|
_Database = new MSSQLManager(connectionString);
|
||||||
_Database = new MSSQLManager(connectionString);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
IniFile iniFile = new IniFile("mssql_connection.ini");
|
|
||||||
string settingDataSource = iniFile.ParseFileReadValue("data_source");
|
|
||||||
string settingInitialCatalog = iniFile.ParseFileReadValue("initial_catalog");
|
|
||||||
string settingPersistSecurityInfo = iniFile.ParseFileReadValue("persist_security_info");
|
|
||||||
string settingUserId = iniFile.ParseFileReadValue("user_id");
|
|
||||||
string settingPassword = iniFile.ParseFileReadValue("password");
|
|
||||||
|
|
||||||
_Database = new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, settingPassword);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Migration settings
|
//Migration settings
|
||||||
_Database.CheckMigration(_migrationStore);
|
_Database.CheckMigration(_migrationStore);
|
||||||
|
@ -102,17 +90,18 @@ namespace OpenSim.Data.MSSQL
|
||||||
SceneObjectGroup grp = null;
|
SceneObjectGroup grp = null;
|
||||||
|
|
||||||
|
|
||||||
string query = "SELECT *, " +
|
string sql = "SELECT *, " +
|
||||||
"sort = CASE WHEN prims.UUID = prims.SceneGroupID THEN 0 ELSE 1 END " +
|
"sort = CASE WHEN prims.UUID = prims.SceneGroupID THEN 0 ELSE 1 END " +
|
||||||
"FROM prims " +
|
"FROM prims " +
|
||||||
"LEFT JOIN primshapes ON prims.UUID = primshapes.UUID " +
|
"LEFT JOIN primshapes ON prims.UUID = primshapes.UUID " +
|
||||||
"WHERE RegionUUID = @RegionUUID " +
|
"WHERE RegionUUID = @RegionUUID " +
|
||||||
"ORDER BY SceneGroupID asc, sort asc, LinkNumber asc";
|
"ORDER BY SceneGroupID asc, sort asc, LinkNumber asc";
|
||||||
|
|
||||||
using (AutoClosingSqlCommand command = _Database.Query(query))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand command = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
command.Parameters.Add(_Database.CreateParameter("@regionUUID", regionUUID));
|
command.Parameters.Add(_Database.CreateParameter("@regionUUID", regionUUID));
|
||||||
|
conn.Open();
|
||||||
using (SqlDataReader reader = command.ExecuteReader())
|
using (SqlDataReader reader = command.ExecuteReader())
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
|
@ -174,8 +163,10 @@ namespace OpenSim.Data.MSSQL
|
||||||
// LoadItems only on those
|
// LoadItems only on those
|
||||||
List<SceneObjectPart> primsWithInventory = new List<SceneObjectPart>();
|
List<SceneObjectPart> primsWithInventory = new List<SceneObjectPart>();
|
||||||
string qry = "select distinct primID from primitems";
|
string qry = "select distinct primID from primitems";
|
||||||
using (AutoClosingSqlCommand command = _Database.Query(qry))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand command = new SqlCommand(qry, conn))
|
||||||
{
|
{
|
||||||
|
conn.Open();
|
||||||
using (SqlDataReader itemReader = command.ExecuteReader())
|
using (SqlDataReader itemReader = command.ExecuteReader())
|
||||||
{
|
{
|
||||||
while (itemReader.Read())
|
while (itemReader.Read())
|
||||||
|
@ -205,9 +196,11 @@ namespace OpenSim.Data.MSSQL
|
||||||
/// <param name="allPrims">all prims with inventory on a region</param>
|
/// <param name="allPrims">all prims with inventory on a region</param>
|
||||||
private void LoadItems(List<SceneObjectPart> allPrimsWithInventory)
|
private void LoadItems(List<SceneObjectPart> allPrimsWithInventory)
|
||||||
{
|
{
|
||||||
|
string sql = "SELECT * FROM primitems WHERE PrimID = @PrimID";
|
||||||
using (AutoClosingSqlCommand command = _Database.Query("SELECT * FROM primitems WHERE PrimID = @PrimID"))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand command = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
|
conn.Open();
|
||||||
foreach (SceneObjectPart objectPart in allPrimsWithInventory)
|
foreach (SceneObjectPart objectPart in allPrimsWithInventory)
|
||||||
{
|
{
|
||||||
command.Parameters.Clear();
|
command.Parameters.Clear();
|
||||||
|
@ -241,8 +234,9 @@ namespace OpenSim.Data.MSSQL
|
||||||
{
|
{
|
||||||
_Log.InfoFormat("[MSSQL]: Adding/Changing SceneObjectGroup: {0} to region: {1}, object has {2} prims.", obj.UUID, regionUUID, obj.Children.Count);
|
_Log.InfoFormat("[MSSQL]: Adding/Changing SceneObjectGroup: {0} to region: {1}, object has {2} prims.", obj.UUID, regionUUID, obj.Children.Count);
|
||||||
|
|
||||||
using (SqlConnection conn = _Database.DatabaseConnection())
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
{
|
{
|
||||||
|
conn.Open();
|
||||||
SqlTransaction transaction = conn.BeginTransaction();
|
SqlTransaction transaction = conn.BeginTransaction();
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -437,8 +431,12 @@ ELSE
|
||||||
lock (_Database)
|
lock (_Database)
|
||||||
{
|
{
|
||||||
//Using the non transaction mode.
|
//Using the non transaction mode.
|
||||||
using (AutoClosingSqlCommand cmd = _Database.Query(sqlPrimShapes))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand())
|
||||||
{
|
{
|
||||||
|
cmd.Connection = conn;
|
||||||
|
cmd.CommandText = sqlPrimShapes;
|
||||||
|
conn.Open();
|
||||||
cmd.Parameters.Add(_Database.CreateParameter("objectID", objectID));
|
cmd.Parameters.Add(_Database.CreateParameter("objectID", objectID));
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
@ -466,24 +464,30 @@ ELSE
|
||||||
|
|
||||||
//Delete everything from PrimID
|
//Delete everything from PrimID
|
||||||
//TODO add index on PrimID in DB, if not already exist
|
//TODO add index on PrimID in DB, if not already exist
|
||||||
using (AutoClosingSqlCommand cmd = _Database.Query("DELETE PRIMITEMS WHERE primID = @primID"))
|
|
||||||
|
string sql = "DELETE PRIMITEMS WHERE primID = @primID";
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(_Database.CreateParameter("@primID", primID));
|
cmd.Parameters.Add(_Database.CreateParameter("@primID", primID));
|
||||||
|
conn.Open();
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
string sql =
|
sql =
|
||||||
@"INSERT INTO primitems (
|
@"INSERT INTO primitems (
|
||||||
itemID,primID,assetID,parentFolderID,invType,assetType,name,description,creationDate,creatorID,ownerID,lastOwnerID,groupID,
|
itemID,primID,assetID,parentFolderID,invType,assetType,name,description,creationDate,creatorID,ownerID,lastOwnerID,groupID,
|
||||||
nextPermissions,currentPermissions,basePermissions,everyonePermissions,groupPermissions,flags)
|
nextPermissions,currentPermissions,basePermissions,everyonePermissions,groupPermissions,flags)
|
||||||
VALUES (@itemID,@primID,@assetID,@parentFolderID,@invType,@assetType,@name,@description,@creationDate,@creatorID,@ownerID,
|
VALUES (@itemID,@primID,@assetID,@parentFolderID,@invType,@assetType,@name,@description,@creationDate,@creatorID,@ownerID,
|
||||||
@lastOwnerID,@groupID,@nextPermissions,@currentPermissions,@basePermissions,@everyonePermissions,@groupPermissions,@flags)";
|
@lastOwnerID,@groupID,@nextPermissions,@currentPermissions,@basePermissions,@everyonePermissions,@groupPermissions,@flags)";
|
||||||
|
|
||||||
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
foreach (TaskInventoryItem taskItem in items)
|
foreach (TaskInventoryItem taskItem in items)
|
||||||
{
|
{
|
||||||
cmd.Parameters.AddRange(CreatePrimInventoryParameters(taskItem));
|
cmd.Parameters.AddRange(CreatePrimInventoryParameters(taskItem));
|
||||||
|
conn.Open();
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
|
|
||||||
cmd.Parameters.Clear();
|
cmd.Parameters.Clear();
|
||||||
|
@ -505,11 +509,12 @@ ELSE
|
||||||
|
|
||||||
string sql = "select top 1 RegionUUID, Revision, Heightfield from terrain where RegionUUID = @RegionUUID order by Revision desc";
|
string sql = "select top 1 RegionUUID, Revision, Heightfield from terrain where RegionUUID = @RegionUUID order by Revision desc";
|
||||||
|
|
||||||
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
// MySqlParameter param = new MySqlParameter();
|
// MySqlParameter param = new MySqlParameter();
|
||||||
cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
|
cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
|
||||||
|
conn.Open();
|
||||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
int rev;
|
int rev;
|
||||||
|
@ -549,19 +554,23 @@ ELSE
|
||||||
|
|
||||||
//Delete old terrain map
|
//Delete old terrain map
|
||||||
string sql = "delete from terrain where RegionUUID=@RegionUUID";
|
string sql = "delete from terrain where RegionUUID=@RegionUUID";
|
||||||
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
|
cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
|
||||||
|
conn.Open();
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
sql = "insert into terrain(RegionUUID, Revision, Heightfield) values(@RegionUUID, @Revision, @Heightfield)";
|
sql = "insert into terrain(RegionUUID, Revision, Heightfield) values(@RegionUUID, @Revision, @Heightfield)";
|
||||||
|
|
||||||
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
|
cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
|
||||||
cmd.Parameters.Add(_Database.CreateParameter("@Revision", revision));
|
cmd.Parameters.Add(_Database.CreateParameter("@Revision", revision));
|
||||||
cmd.Parameters.Add(_Database.CreateParameter("@Heightfield", serializeTerrain(terrain)));
|
cmd.Parameters.Add(_Database.CreateParameter("@Heightfield", serializeTerrain(terrain)));
|
||||||
|
conn.Open();
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -580,11 +589,12 @@ ELSE
|
||||||
string sql = "select * from land where RegionUUID = @RegionUUID";
|
string sql = "select * from land where RegionUUID = @RegionUUID";
|
||||||
|
|
||||||
//Retrieve all land data from region
|
//Retrieve all land data from region
|
||||||
using (AutoClosingSqlCommand cmdLandData = _Database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
cmdLandData.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionUUID));
|
cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionUUID));
|
||||||
|
conn.Open();
|
||||||
using (SqlDataReader readerLandData = cmdLandData.ExecuteReader())
|
using (SqlDataReader readerLandData = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
while (readerLandData.Read())
|
while (readerLandData.Read())
|
||||||
{
|
{
|
||||||
|
@ -597,10 +607,12 @@ ELSE
|
||||||
foreach (LandData LandData in LandDataForRegion)
|
foreach (LandData LandData in LandDataForRegion)
|
||||||
{
|
{
|
||||||
sql = "select * from landaccesslist where LandUUID = @LandUUID";
|
sql = "select * from landaccesslist where LandUUID = @LandUUID";
|
||||||
using (AutoClosingSqlCommand cmdAccessList = _Database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
cmdAccessList.Parameters.Add(_Database.CreateParameter("@LandUUID", LandData.GlobalID));
|
cmd.Parameters.Add(_Database.CreateParameter("@LandUUID", LandData.GlobalID));
|
||||||
using (SqlDataReader readerAccessList = cmdAccessList.ExecuteReader())
|
conn.Open();
|
||||||
|
using (SqlDataReader readerAccessList = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
while (readerAccessList.Read())
|
while (readerAccessList.Read())
|
||||||
{
|
{
|
||||||
|
@ -632,17 +644,20 @@ ELSE
|
||||||
VALUES
|
VALUES
|
||||||
(@UUID,@RegionUUID,@LocalLandID,@Bitmap,@Name,@Description,@OwnerUUID,@IsGroupOwned,@Area,@AuctionID,@Category,@ClaimDate,@ClaimPrice,@GroupUUID,@SalePrice,@LandStatus,@LandFlags,@LandingType,@MediaAutoScale,@MediaTextureUUID,@MediaURL,@MusicURL,@PassHours,@PassPrice,@SnapshotUUID,@UserLocationX,@UserLocationY,@UserLocationZ,@UserLookAtX,@UserLookAtY,@UserLookAtZ,@AuthbuyerID,@OtherCleanTime,@Dwell)";
|
(@UUID,@RegionUUID,@LocalLandID,@Bitmap,@Name,@Description,@OwnerUUID,@IsGroupOwned,@Area,@AuctionID,@Category,@ClaimDate,@ClaimPrice,@GroupUUID,@SalePrice,@LandStatus,@LandFlags,@LandingType,@MediaAutoScale,@MediaTextureUUID,@MediaURL,@MusicURL,@PassHours,@PassPrice,@SnapshotUUID,@UserLocationX,@UserLocationY,@UserLocationZ,@UserLookAtX,@UserLookAtY,@UserLookAtZ,@AuthbuyerID,@OtherCleanTime,@Dwell)";
|
||||||
|
|
||||||
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.AddRange(CreateLandParameters(parcel.LandData, parcel.RegionUUID));
|
cmd.Parameters.AddRange(CreateLandParameters(parcel.LandData, parcel.RegionUUID));
|
||||||
|
conn.Open();
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
sql = "INSERT INTO [landaccesslist] ([LandUUID],[AccessUUID],[Flags]) VALUES (@LandUUID,@AccessUUID,@Flags)";
|
sql = "INSERT INTO [landaccesslist] ([LandUUID],[AccessUUID],[Flags]) VALUES (@LandUUID,@AccessUUID,@Flags)";
|
||||||
|
|
||||||
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
|
conn.Open();
|
||||||
foreach (ParcelManager.ParcelAccessEntry parcelAccessEntry in parcel.LandData.ParcelAccessList)
|
foreach (ParcelManager.ParcelAccessEntry parcelAccessEntry in parcel.LandData.ParcelAccessList)
|
||||||
{
|
{
|
||||||
cmd.Parameters.AddRange(CreateLandAccessParameters(parcelAccessEntry, parcel.RegionUUID));
|
cmd.Parameters.AddRange(CreateLandAccessParameters(parcelAccessEntry, parcel.RegionUUID));
|
||||||
|
@ -659,15 +674,20 @@ VALUES
|
||||||
/// <param name="globalID">UUID of landobject</param>
|
/// <param name="globalID">UUID of landobject</param>
|
||||||
public void RemoveLandObject(UUID globalID)
|
public void RemoveLandObject(UUID globalID)
|
||||||
{
|
{
|
||||||
using (AutoClosingSqlCommand cmd = _Database.Query("delete from land where UUID=@UUID"))
|
string sql = "delete from land where UUID=@UUID";
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(_Database.CreateParameter("@UUID", globalID));
|
cmd.Parameters.Add(_Database.CreateParameter("@UUID", globalID));
|
||||||
|
conn.Open();
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
sql = "delete from landaccesslist where LandUUID=@UUID";
|
||||||
using (AutoClosingSqlCommand cmd = _Database.Query("delete from landaccesslist where LandUUID=@UUID"))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(_Database.CreateParameter("@UUID", globalID));
|
cmd.Parameters.Add(_Database.CreateParameter("@UUID", globalID));
|
||||||
|
conn.Open();
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -681,9 +701,11 @@ VALUES
|
||||||
{
|
{
|
||||||
string sql = "select * from regionsettings where regionUUID = @regionUUID";
|
string sql = "select * from regionsettings where regionUUID = @regionUUID";
|
||||||
RegionSettings regionSettings;
|
RegionSettings regionSettings;
|
||||||
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(_Database.CreateParameter("@regionUUID", regionUUID));
|
cmd.Parameters.Add(_Database.CreateParameter("@regionUUID", regionUUID));
|
||||||
|
conn.Open();
|
||||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
if (reader.Read())
|
if (reader.Read())
|
||||||
|
@ -715,9 +737,12 @@ VALUES
|
||||||
{
|
{
|
||||||
//Little check if regionUUID already exist in DB
|
//Little check if regionUUID already exist in DB
|
||||||
string regionUUID;
|
string regionUUID;
|
||||||
using (AutoClosingSqlCommand cmd = _Database.Query("SELECT regionUUID FROM regionsettings WHERE regionUUID = @regionUUID"))
|
string sql = "SELECT regionUUID FROM regionsettings WHERE regionUUID = @regionUUID";
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(_Database.CreateParameter("@regionUUID", regionSettings.RegionUUID));
|
cmd.Parameters.Add(_Database.CreateParameter("@regionUUID", regionSettings.RegionUUID));
|
||||||
|
conn.Open();
|
||||||
regionUUID = cmd.ExecuteScalar().ToString();
|
regionUUID = cmd.ExecuteScalar().ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -728,8 +753,8 @@ VALUES
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//This method only updates region settings!!! First call LoadRegionSettings to create new region settings in DB
|
//This method only updates region settings!!! First call LoadRegionSettings to create new region settings in DB
|
||||||
string sql =
|
sql =
|
||||||
@"UPDATE [regionsettings] SET [block_terraform] = @block_terraform ,[block_fly] = @block_fly ,[allow_damage] = @allow_damage
|
@"UPDATE [regionsettings] SET [block_terraform] = @block_terraform ,[block_fly] = @block_fly ,[allow_damage] = @allow_damage
|
||||||
,[restrict_pushing] = @restrict_pushing ,[allow_land_resell] = @allow_land_resell ,[allow_land_join_divide] = @allow_land_join_divide
|
,[restrict_pushing] = @restrict_pushing ,[allow_land_resell] = @allow_land_resell ,[allow_land_join_divide] = @allow_land_join_divide
|
||||||
,[block_show_in_search] = @block_show_in_search ,[agent_limit] = @agent_limit ,[object_bonus] = @object_bonus ,[maturity] = @maturity
|
,[block_show_in_search] = @block_show_in_search ,[agent_limit] = @agent_limit ,[object_bonus] = @object_bonus ,[maturity] = @maturity
|
||||||
,[disable_scripts] = @disable_scripts ,[disable_collisions] = @disable_collisions ,[disable_physics] = @disable_physics
|
,[disable_scripts] = @disable_scripts ,[disable_collisions] = @disable_collisions ,[disable_physics] = @disable_physics
|
||||||
|
@ -741,10 +766,11 @@ VALUES
|
||||||
,[covenant] = @covenant , [sunvectorx] = @sunvectorx, [sunvectory] = @sunvectory, [sunvectorz] = @sunvectorz, [Sandbox] = @Sandbox, [loaded_creation_datetime] = @loaded_creation_datetime, [loaded_creation_id] = @loaded_creation_id
|
,[covenant] = @covenant , [sunvectorx] = @sunvectorx, [sunvectory] = @sunvectory, [sunvectorz] = @sunvectorz, [Sandbox] = @Sandbox, [loaded_creation_datetime] = @loaded_creation_datetime, [loaded_creation_id] = @loaded_creation_id
|
||||||
WHERE [regionUUID] = @regionUUID";
|
WHERE [regionUUID] = @regionUUID";
|
||||||
|
|
||||||
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
|
cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
|
||||||
|
conn.Open();
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -801,9 +827,11 @@ VALUES
|
||||||
@elevation_2_ne,@elevation_1_se,@elevation_2_se,@elevation_1_sw,@elevation_2_sw,@water_height,@terrain_raise_limit,
|
@elevation_2_ne,@elevation_1_se,@elevation_2_se,@elevation_1_sw,@elevation_2_sw,@water_height,@terrain_raise_limit,
|
||||||
@terrain_lower_limit,@use_estate_sun,@fixed_sun,@sun_position,@covenant,@sunvectorx,@sunvectory, @sunvectorz, @Sandbox, @loaded_creation_datetime, @loaded_creation_id)";
|
@terrain_lower_limit,@use_estate_sun,@fixed_sun,@sun_position,@covenant,@sunvectorx,@sunvectory, @sunvectorz, @Sandbox, @loaded_creation_datetime, @loaded_creation_id)";
|
||||||
|
|
||||||
using (AutoClosingSqlCommand cmd = _Database.Query(sql))
|
using (SqlConnection conn = new SqlConnection(m_connectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
|
cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
|
||||||
|
conn.Open();
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -907,15 +935,15 @@ VALUES
|
||||||
newData.PassHours = Convert.ToSingle(row["PassHours"]);
|
newData.PassHours = Convert.ToSingle(row["PassHours"]);
|
||||||
newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
|
newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
|
||||||
|
|
||||||
// UUID authedbuyer;
|
// UUID authedbuyer;
|
||||||
// UUID snapshotID;
|
// UUID snapshotID;
|
||||||
//
|
//
|
||||||
// if (UUID.TryParse((string)row["AuthBuyerID"], out authedbuyer))
|
// if (UUID.TryParse((string)row["AuthBuyerID"], out authedbuyer))
|
||||||
// newData.AuthBuyerID = authedbuyer;
|
// newData.AuthBuyerID = authedbuyer;
|
||||||
//
|
//
|
||||||
// if (UUID.TryParse((string)row["SnapshotUUID"], out snapshotID))
|
// if (UUID.TryParse((string)row["SnapshotUUID"], out snapshotID))
|
||||||
// newData.SnapshotID = snapshotID;
|
// newData.SnapshotID = snapshotID;
|
||||||
newData.AuthBuyerID = new UUID((Guid) row["AuthBuyerID"]);
|
newData.AuthBuyerID = new UUID((Guid)row["AuthBuyerID"]);
|
||||||
newData.SnapshotID = new UUID((Guid)row["SnapshotUUID"]);
|
newData.SnapshotID = new UUID((Guid)row["SnapshotUUID"]);
|
||||||
|
|
||||||
newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
|
newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
|
||||||
|
@ -1468,7 +1496,7 @@ VALUES
|
||||||
|
|
||||||
parameters.Add(_Database.CreateParameter("CollisionSound", prim.CollisionSound));
|
parameters.Add(_Database.CreateParameter("CollisionSound", prim.CollisionSound));
|
||||||
parameters.Add(_Database.CreateParameter("CollisionSoundVolume", prim.CollisionSoundVolume));
|
parameters.Add(_Database.CreateParameter("CollisionSoundVolume", prim.CollisionSoundVolume));
|
||||||
if (prim.PassTouches)
|
if (prim.PassTouches)
|
||||||
parameters.Add(_Database.CreateParameter("PassTouches", 1));
|
parameters.Add(_Database.CreateParameter("PassTouches", 1));
|
||||||
else
|
else
|
||||||
parameters.Add(_Database.CreateParameter("PassTouches", 0));
|
parameters.Add(_Database.CreateParameter("PassTouches", 0));
|
||||||
|
|
|
@ -48,21 +48,6 @@ namespace OpenSim.Data.MSSQL
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly string connectionString;
|
private readonly string connectionString;
|
||||||
|
|
||||||
public MSSQLManager(string dataSource, string initialCatalog, string persistSecurityInfo, string userId,
|
|
||||||
string password)
|
|
||||||
{
|
|
||||||
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
|
|
||||||
|
|
||||||
builder.DataSource = dataSource;
|
|
||||||
builder.InitialCatalog = initialCatalog;
|
|
||||||
builder.PersistSecurityInfo = Convert.ToBoolean(persistSecurityInfo);
|
|
||||||
builder.UserID = userId;
|
|
||||||
builder.Password = password;
|
|
||||||
builder.ApplicationName = Assembly.GetEntryAssembly().Location;
|
|
||||||
|
|
||||||
connectionString = builder.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initialize the manager and set the connectionstring
|
/// Initialize the manager and set the connectionstring
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -72,94 +57,6 @@ namespace OpenSim.Data.MSSQL
|
||||||
connectionString = connection;
|
connectionString = connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SqlConnection DatabaseConnection()
|
|
||||||
{
|
|
||||||
SqlConnection conn = new SqlConnection(connectionString);
|
|
||||||
|
|
||||||
//TODO is this good??? Opening connection here
|
|
||||||
conn.Open();
|
|
||||||
|
|
||||||
return conn;
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Obsolete functions, can be removed!
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="dt"></param>
|
|
||||||
/// <param name="name"></param>
|
|
||||||
/// <param name="type"></param>
|
|
||||||
[Obsolete("Do not use!")]
|
|
||||||
protected static void createCol(DataTable dt, string name, Type type)
|
|
||||||
{
|
|
||||||
DataColumn col = new DataColumn(name, type);
|
|
||||||
dt.Columns.Add(col);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Define Table function
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="dt"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
/*
|
|
||||||
[Obsolete("Do not use!")]
|
|
||||||
protected static string defineTable(DataTable dt)
|
|
||||||
{
|
|
||||||
string sql = "create table " + dt.TableName + "(";
|
|
||||||
string subsql = String.Empty;
|
|
||||||
foreach (DataColumn col in dt.Columns)
|
|
||||||
{
|
|
||||||
if (subsql.Length > 0)
|
|
||||||
{
|
|
||||||
// a map function would rock so much here
|
|
||||||
subsql += ",\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
subsql += col.ColumnName + " " + SqlType(col.DataType);
|
|
||||||
if (col == dt.PrimaryKey[0])
|
|
||||||
{
|
|
||||||
subsql += " primary key";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sql += subsql;
|
|
||||||
sql += ")";
|
|
||||||
return sql;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Type conversion function
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="type">a type</param>
|
|
||||||
/// <returns>a sqltype</returns>
|
|
||||||
/// <remarks>this is something we'll need to implement for each db slightly differently.</remarks>
|
|
||||||
/*
|
|
||||||
[Obsolete("Used by a obsolete methods")]
|
|
||||||
public static string SqlType(Type type)
|
|
||||||
{
|
|
||||||
if (type == typeof(String))
|
|
||||||
{
|
|
||||||
return "varchar(255)";
|
|
||||||
}
|
|
||||||
if (type == typeof(Int32))
|
|
||||||
{
|
|
||||||
return "integer";
|
|
||||||
}
|
|
||||||
if (type == typeof(Double))
|
|
||||||
{
|
|
||||||
return "float";
|
|
||||||
}
|
|
||||||
if (type == typeof(Byte[]))
|
|
||||||
{
|
|
||||||
return "image";
|
|
||||||
}
|
|
||||||
return "varchar(255)";
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Type conversion to a SQLDbType functions
|
/// Type conversion to a SQLDbType functions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -285,136 +182,22 @@ namespace OpenSim.Data.MSSQL
|
||||||
|
|
||||||
private static readonly Dictionary<string, string> emptyDictionary = new Dictionary<string, string>();
|
private static readonly Dictionary<string, string> emptyDictionary = new Dictionary<string, string>();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Run a query and return a sql db command
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sql">The SQL query.</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
internal AutoClosingSqlCommand Query(string sql)
|
|
||||||
{
|
|
||||||
return Query(sql, emptyDictionary);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Runs a query with protection against SQL Injection by using parameterised input.
|
|
||||||
/// </summary>
|
|
||||||
/// <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 Sql DB Command</returns>
|
|
||||||
internal AutoClosingSqlCommand Query(string sql, Dictionary<string, string> parameters)
|
|
||||||
{
|
|
||||||
SqlCommand dbcommand = DatabaseConnection().CreateCommand();
|
|
||||||
dbcommand.CommandText = sql;
|
|
||||||
foreach (KeyValuePair<string, string> param in parameters)
|
|
||||||
{
|
|
||||||
dbcommand.Parameters.AddWithValue(param.Key, param.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new AutoClosingSqlCommand(dbcommand);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Runs a query with protection against SQL Injection by using parameterised input.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param>
|
|
||||||
/// <param name="sqlParameter">A parameter - use createparameter to create parameter</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
internal AutoClosingSqlCommand Query(string sql, SqlParameter sqlParameter)
|
|
||||||
{
|
|
||||||
SqlCommand dbcommand = DatabaseConnection().CreateCommand();
|
|
||||||
dbcommand.CommandText = sql;
|
|
||||||
dbcommand.Parameters.Add(sqlParameter);
|
|
||||||
|
|
||||||
return new AutoClosingSqlCommand(dbcommand);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if we need to do some migrations to the database
|
/// Checks if we need to do some migrations to the database
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="migrationStore">migrationStore.</param>
|
/// <param name="migrationStore">migrationStore.</param>
|
||||||
public void CheckMigration(string migrationStore)
|
public void CheckMigration(string migrationStore)
|
||||||
{
|
{
|
||||||
using (SqlConnection connection = DatabaseConnection())
|
using (SqlConnection connection = new SqlConnection(connectionString))
|
||||||
{
|
{
|
||||||
|
connection.Open();
|
||||||
Assembly assem = GetType().Assembly;
|
Assembly assem = GetType().Assembly;
|
||||||
MSSQLMigration migration = new MSSQLMigration(connection, assem, migrationStore);
|
MSSQLMigration migration = new MSSQLMigration(connection, assem, migrationStore);
|
||||||
|
|
||||||
migration.Update();
|
migration.Update();
|
||||||
|
|
||||||
connection.Close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Old Testtable functions
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Execute a SQL statement stored in a resource, as a string
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">the ressource string</param>
|
|
||||||
public void ExecuteResourceSql(string name)
|
|
||||||
{
|
|
||||||
using (IDbCommand cmd = Query(getResourceString(name), new Dictionary<string, string>()))
|
|
||||||
{
|
|
||||||
cmd.ExecuteNonQuery();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Given a list of tables, return the version of the tables, as seen in the database
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="tableList"></param>
|
|
||||||
public void GetTableVersion(Dictionary<string, string> tableList)
|
|
||||||
{
|
|
||||||
Dictionary<string, string> param = new Dictionary<string, string>();
|
|
||||||
param["dbname"] = new SqlConnectionStringBuilder(connectionString).InitialCatalog;
|
|
||||||
|
|
||||||
using (IDbCommand tablesCmd =
|
|
||||||
Query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_CATALOG=@dbname", param))
|
|
||||||
using (IDataReader tables = tablesCmd.ExecuteReader())
|
|
||||||
{
|
|
||||||
while (tables.Read())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
string tableName = (string)tables["TABLE_NAME"];
|
|
||||||
if (tableList.ContainsKey(tableName))
|
|
||||||
tableList[tableName] = tableName;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
m_log.Error(e.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tables.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
private string getResourceString(string name)
|
|
||||||
{
|
|
||||||
Assembly assem = GetType().Assembly;
|
|
||||||
string[] names = assem.GetManifestResourceNames();
|
|
||||||
|
|
||||||
foreach (string s in names)
|
|
||||||
if (s.EndsWith(name))
|
|
||||||
using (Stream resource = assem.GetManifestResourceStream(s))
|
|
||||||
{
|
|
||||||
using (StreamReader resourceReader = new StreamReader(resource))
|
|
||||||
{
|
|
||||||
string resourceString = resourceReader.ReadToEnd();
|
|
||||||
return resourceString;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new Exception(string.Format("Resource '{0}' was not found", name));
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the version of this DB provider
|
/// Returns the version of this DB provider
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -0,0 +1,170 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) Contributors, http://opensimulator.org/
|
||||||
|
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* * Neither the name of the OpenSimulator Project nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||||
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||||
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Threading;
|
||||||
|
using log4net;
|
||||||
|
using OpenMetaverse;
|
||||||
|
using OpenSim.Framework;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
|
||||||
|
namespace OpenSim.Data.MSSQL
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A MySQL Interface for the Presence Server
|
||||||
|
/// </summary>
|
||||||
|
public class MSSQLPresenceData : MSSQLGenericTableHandler<PresenceData>,
|
||||||
|
IPresenceData
|
||||||
|
{
|
||||||
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
|
public MSSQLPresenceData(string connectionString, string realm) :
|
||||||
|
base(connectionString, realm, "Presence")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public PresenceData Get(UUID sessionID)
|
||||||
|
{
|
||||||
|
PresenceData[] ret = Get("SessionID",
|
||||||
|
sessionID.ToString());
|
||||||
|
|
||||||
|
if (ret.Length == 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return ret[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LogoutRegionAgents(UUID regionID)
|
||||||
|
{
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand())
|
||||||
|
{
|
||||||
|
|
||||||
|
cmd.CommandText = String.Format("UPDATE {0} SET Online='false' WHERE [RegionID]=@RegionID", m_Realm);
|
||||||
|
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@RegionID", regionID.ToString()));
|
||||||
|
cmd.Connection = conn;
|
||||||
|
conn.Open();
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ReportAgent(UUID sessionID, UUID regionID, string position,
|
||||||
|
string lookAt)
|
||||||
|
{
|
||||||
|
PresenceData[] pd = Get("SessionID", sessionID.ToString());
|
||||||
|
if (pd.Length == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand())
|
||||||
|
{
|
||||||
|
|
||||||
|
cmd.CommandText = String.Format(@"UPDATE {0} SET
|
||||||
|
[RegionID] = @RegionID,
|
||||||
|
[Position] = @Position,
|
||||||
|
[LookAt] = @LookAt,
|
||||||
|
[Online] = 'true'
|
||||||
|
WHERE [SessionID] = @SessionID", m_Realm);
|
||||||
|
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@SessionID", sessionID.ToString()));
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@RegionID", regionID.ToString()));
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@Position", position.ToString()));
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@LookAt", lookAt.ToString()));
|
||||||
|
cmd.Connection = conn;
|
||||||
|
conn.Open();
|
||||||
|
if (cmd.ExecuteNonQuery() == 0)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
|
||||||
|
{
|
||||||
|
PresenceData[] pd = Get("UserID", userID);
|
||||||
|
if (pd.Length == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand())
|
||||||
|
{
|
||||||
|
|
||||||
|
cmd.CommandText = String.Format(@"UPDATE {0} SET
|
||||||
|
[HomeRegionID] = @HomeRegionID,
|
||||||
|
[HomePosition] = @HomePosition,
|
||||||
|
[HomeLookAt] = @HomeLookAt
|
||||||
|
WHERE [UserID] = @UserID", m_Realm);
|
||||||
|
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@UserID", userID));
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@HomeRegionID", regionID.ToString()));
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@HomePosition", position));
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@HomeLookAt", lookAt));
|
||||||
|
cmd.Connection = conn;
|
||||||
|
conn.Open();
|
||||||
|
if (cmd.ExecuteNonQuery() == 0)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Prune(string userID)
|
||||||
|
{
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand())
|
||||||
|
{
|
||||||
|
cmd.CommandText = String.Format("SELECT * from {0} WHERE [UserID] = @UserID", m_Realm);
|
||||||
|
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@UserID", userID));
|
||||||
|
cmd.Connection = conn;
|
||||||
|
conn.Open();
|
||||||
|
|
||||||
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||||
|
{
|
||||||
|
List<UUID> deleteSessions = new List<UUID>();
|
||||||
|
int online = 0;
|
||||||
|
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
if (bool.Parse(reader["Online"].ToString()))
|
||||||
|
online++;
|
||||||
|
else
|
||||||
|
deleteSessions.Add(new UUID(reader["SessionID"].ToString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (online == 0 && deleteSessions.Count > 0)
|
||||||
|
deleteSessions.RemoveAt(0);
|
||||||
|
|
||||||
|
foreach (UUID s in deleteSessions)
|
||||||
|
Delete("SessionID", s.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -129,10 +129,10 @@ namespace OpenSim.Data.MSSQL
|
||||||
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(m_database.CreateParameter("@startX", startX.ToString()));
|
cmd.Parameters.Add(m_database.CreateParameter("@startX", startX));
|
||||||
cmd.Parameters.Add(m_database.CreateParameter("@startY", startY.ToString()));
|
cmd.Parameters.Add(m_database.CreateParameter("@startY", startY));
|
||||||
cmd.Parameters.Add(m_database.CreateParameter("@endX", endX.ToString()));
|
cmd.Parameters.Add(m_database.CreateParameter("@endX", endX));
|
||||||
cmd.Parameters.Add(m_database.CreateParameter("@endY", endY.ToString()));
|
cmd.Parameters.Add(m_database.CreateParameter("@endY", endY));
|
||||||
cmd.Parameters.Add(m_database.CreateParameter("@scopeID", scopeID));
|
cmd.Parameters.Add(m_database.CreateParameter("@scopeID", scopeID));
|
||||||
conn.Open();
|
conn.Open();
|
||||||
return RunCommand(cmd);
|
return RunCommand(cmd);
|
||||||
|
@ -310,12 +310,34 @@ namespace OpenSim.Data.MSSQL
|
||||||
|
|
||||||
public List<RegionData> GetDefaultRegions(UUID scopeID)
|
public List<RegionData> GetDefaultRegions(UUID scopeID)
|
||||||
{
|
{
|
||||||
return null;
|
string sql = "SELECT * FROM [" + m_Realm + "] WHERE (flags & 1) <> 0";
|
||||||
|
if (scopeID != UUID.Zero)
|
||||||
|
sql += " AND ScopeID = @scopeID";
|
||||||
|
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@scopeID", scopeID));
|
||||||
|
conn.Open();
|
||||||
|
return RunCommand(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<RegionData> GetFallbackRegions(UUID scopeID, int x, int y)
|
public List<RegionData> GetFallbackRegions(UUID scopeID, int x, int y)
|
||||||
{
|
{
|
||||||
return null;
|
string sql = "SELECT * FROM [" + m_Realm + "] WHERE (flags & 2) <> 0";
|
||||||
|
if (scopeID != UUID.Zero)
|
||||||
|
sql += " AND ScopeID = @scopeID";
|
||||||
|
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@scopeID", scopeID));
|
||||||
|
conn.Open();
|
||||||
|
// TODO: distance-sort results
|
||||||
|
return RunCommand(cmd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,168 +36,207 @@ using System.Text;
|
||||||
|
|
||||||
namespace OpenSim.Data.MSSQL
|
namespace OpenSim.Data.MSSQL
|
||||||
{
|
{
|
||||||
public class MSSQLUserAccountData : IUserAccountData
|
public class MSSQLUserAccountData : MSSQLGenericTableHandler<UserAccountData>,IUserAccountData
|
||||||
{
|
{
|
||||||
private string m_Realm;
|
public MSSQLUserAccountData(string connectionString, string realm) :
|
||||||
private List<string> m_ColumnNames = null;
|
base(connectionString, realm, "UserAccount")
|
||||||
private string m_ConnectionString;
|
|
||||||
private MSSQLManager m_database;
|
|
||||||
|
|
||||||
public MSSQLUserAccountData(string connectionString, string realm)
|
|
||||||
{
|
{
|
||||||
m_Realm = realm;
|
|
||||||
m_ConnectionString = connectionString;
|
|
||||||
m_database = new MSSQLManager(connectionString);
|
|
||||||
|
|
||||||
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
|
||||||
{
|
|
||||||
conn.Open();
|
|
||||||
Migration m = new Migration(conn, GetType().Assembly, "UserStore");
|
|
||||||
m.Update();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
//private string m_Realm;
|
||||||
|
//private List<string> m_ColumnNames = null;
|
||||||
|
//private MSSQLManager m_database;
|
||||||
|
|
||||||
public List<UserAccountData> Query(UUID principalID, UUID scopeID, string query)
|
//public MSSQLUserAccountData(string connectionString, string realm)
|
||||||
|
//{
|
||||||
|
// m_Realm = realm;
|
||||||
|
// m_ConnectionString = connectionString;
|
||||||
|
// m_database = new MSSQLManager(connectionString);
|
||||||
|
|
||||||
|
// using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
|
// {
|
||||||
|
// conn.Open();
|
||||||
|
// Migration m = new Migration(conn, GetType().Assembly, "UserStore");
|
||||||
|
// m.Update();
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
//public List<UserAccountData> Query(UUID principalID, UUID scopeID, string query)
|
||||||
|
//{
|
||||||
|
// return null;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//public UserAccountData Get(UUID principalID, UUID scopeID)
|
||||||
|
//{
|
||||||
|
// UserAccountData ret = new UserAccountData();
|
||||||
|
// ret.Data = new Dictionary<string, string>();
|
||||||
|
|
||||||
|
// string sql = string.Format("select * from {0} where UUID = @principalID", m_Realm);
|
||||||
|
// if (scopeID != UUID.Zero)
|
||||||
|
// sql += " and ScopeID = @scopeID";
|
||||||
|
|
||||||
|
// using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
|
// using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
|
// {
|
||||||
|
// cmd.Parameters.Add(m_database.CreateParameter("@principalID", principalID));
|
||||||
|
// cmd.Parameters.Add(m_database.CreateParameter("@scopeID", scopeID));
|
||||||
|
|
||||||
|
// conn.Open();
|
||||||
|
// using (SqlDataReader result = cmd.ExecuteReader())
|
||||||
|
// {
|
||||||
|
// if (result.Read())
|
||||||
|
// {
|
||||||
|
// ret.PrincipalID = principalID;
|
||||||
|
// UUID scope;
|
||||||
|
// UUID.TryParse(result["ScopeID"].ToString(), out scope);
|
||||||
|
// ret.ScopeID = scope;
|
||||||
|
|
||||||
|
// if (m_ColumnNames == null)
|
||||||
|
// {
|
||||||
|
// m_ColumnNames = new List<string>();
|
||||||
|
|
||||||
|
// DataTable schemaTable = result.GetSchemaTable();
|
||||||
|
// foreach (DataRow row in schemaTable.Rows)
|
||||||
|
// m_ColumnNames.Add(row["ColumnName"].ToString());
|
||||||
|
// }
|
||||||
|
|
||||||
|
// foreach (string s in m_ColumnNames)
|
||||||
|
// {
|
||||||
|
// if (s == "UUID")
|
||||||
|
// continue;
|
||||||
|
// if (s == "ScopeID")
|
||||||
|
// continue;
|
||||||
|
|
||||||
|
// ret.Data[s] = result[s].ToString();
|
||||||
|
// }
|
||||||
|
// return ret;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return null;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//public bool Store(UserAccountData data)
|
||||||
|
//{
|
||||||
|
// if (data.Data.ContainsKey("UUID"))
|
||||||
|
// data.Data.Remove("UUID");
|
||||||
|
// if (data.Data.ContainsKey("ScopeID"))
|
||||||
|
// data.Data.Remove("ScopeID");
|
||||||
|
|
||||||
|
// string[] fields = new List<string>(data.Data.Keys).ToArray();
|
||||||
|
|
||||||
|
// using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
|
// using (SqlCommand cmd = new SqlCommand())
|
||||||
|
// {
|
||||||
|
// StringBuilder updateBuilder = new StringBuilder();
|
||||||
|
// updateBuilder.AppendFormat("update {0} set ", m_Realm);
|
||||||
|
// bool first = true;
|
||||||
|
// foreach (string field in fields)
|
||||||
|
// {
|
||||||
|
// if (!first)
|
||||||
|
// updateBuilder.Append(", ");
|
||||||
|
// updateBuilder.AppendFormat("{0} = @{0}", field);
|
||||||
|
|
||||||
|
// first = false;
|
||||||
|
// cmd.Parameters.Add(m_database.CreateParameter("@" + field, data.Data[field]));
|
||||||
|
// }
|
||||||
|
|
||||||
|
// updateBuilder.Append(" where UUID = @principalID");
|
||||||
|
|
||||||
|
// if (data.ScopeID != UUID.Zero)
|
||||||
|
// updateBuilder.Append(" and ScopeID = @scopeID");
|
||||||
|
|
||||||
|
// cmd.CommandText = updateBuilder.ToString();
|
||||||
|
// cmd.Connection = conn;
|
||||||
|
// cmd.Parameters.Add(m_database.CreateParameter("@principalID", data.PrincipalID));
|
||||||
|
// cmd.Parameters.Add(m_database.CreateParameter("@scopeID", data.ScopeID));
|
||||||
|
// conn.Open();
|
||||||
|
|
||||||
|
// if (cmd.ExecuteNonQuery() < 1)
|
||||||
|
// {
|
||||||
|
// StringBuilder insertBuilder = new StringBuilder();
|
||||||
|
// insertBuilder.AppendFormat("insert into {0} (UUID, ScopeID, ", m_Realm);
|
||||||
|
// insertBuilder.Append(String.Join(", ", fields));
|
||||||
|
// insertBuilder.Append(") values (@principalID, @scopeID, @");
|
||||||
|
// insertBuilder.Append(String.Join(", @", fields));
|
||||||
|
// insertBuilder.Append(")");
|
||||||
|
|
||||||
|
// cmd.CommandText = insertBuilder.ToString();
|
||||||
|
|
||||||
|
// if (cmd.ExecuteNonQuery() < 1)
|
||||||
|
// {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return true;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//public bool Store(UserAccountData data, UUID principalID, string token)
|
||||||
|
//{
|
||||||
|
// return false;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//public bool SetDataItem(UUID principalID, string item, string value)
|
||||||
|
//{
|
||||||
|
// string sql = string.Format("update {0} set {1} = @{1} where UUID = @UUID", m_Realm, item);
|
||||||
|
// using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
|
// using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||||
|
// {
|
||||||
|
// cmd.Parameters.Add(m_database.CreateParameter("@" + item, value));
|
||||||
|
// cmd.Parameters.Add(m_database.CreateParameter("@UUID", principalID));
|
||||||
|
|
||||||
|
// conn.Open();
|
||||||
|
|
||||||
|
// if (cmd.ExecuteNonQuery() > 0)
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
// return false;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//public UserAccountData[] Get(string[] keys, string[] vals)
|
||||||
|
//{
|
||||||
|
// return null;
|
||||||
|
//}
|
||||||
|
|
||||||
|
public UserAccountData[] GetUsers(UUID scopeID, string query)
|
||||||
{
|
{
|
||||||
return null;
|
string[] words = query.Split(new char[] { ' ' });
|
||||||
}
|
|
||||||
|
|
||||||
public UserAccountData Get(UUID principalID, UUID scopeID)
|
for (int i = 0; i < words.Length; i++)
|
||||||
{
|
|
||||||
UserAccountData ret = new UserAccountData();
|
|
||||||
ret.Data = new Dictionary<string, string>();
|
|
||||||
|
|
||||||
string sql = string.Format("select * from {0} where UUID = @principalID", m_Realm);
|
|
||||||
if (scopeID != UUID.Zero)
|
|
||||||
sql += " and ScopeID = @scopeID";
|
|
||||||
|
|
||||||
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
|
||||||
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(m_database.CreateParameter("@principalID", principalID));
|
if (words[i].Length < 3)
|
||||||
cmd.Parameters.Add(m_database.CreateParameter("@scopeID", scopeID));
|
|
||||||
|
|
||||||
conn.Open();
|
|
||||||
using (SqlDataReader result = cmd.ExecuteReader())
|
|
||||||
{
|
{
|
||||||
if (result.Read())
|
if (i != words.Length - 1)
|
||||||
{
|
Array.Copy(words, i + 1, words, i, words.Length - i - 1);
|
||||||
ret.PrincipalID = principalID;
|
Array.Resize(ref words, words.Length - 1);
|
||||||
UUID scope;
|
|
||||||
UUID.TryParse(result["ScopeID"].ToString(), out scope);
|
|
||||||
ret.ScopeID = scope;
|
|
||||||
|
|
||||||
if (m_ColumnNames == null)
|
|
||||||
{
|
|
||||||
m_ColumnNames = new List<string>();
|
|
||||||
|
|
||||||
DataTable schemaTable = result.GetSchemaTable();
|
|
||||||
foreach (DataRow row in schemaTable.Rows)
|
|
||||||
m_ColumnNames.Add(row["ColumnName"].ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (string s in m_ColumnNames)
|
|
||||||
{
|
|
||||||
if (s == "UUID")
|
|
||||||
continue;
|
|
||||||
if (s == "ScopeID")
|
|
||||||
continue;
|
|
||||||
|
|
||||||
ret.Data[s] = result[s].ToString();
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Store(UserAccountData data)
|
if (words.Length == 0)
|
||||||
{
|
return new UserAccountData[0];
|
||||||
if (data.Data.ContainsKey("UUID"))
|
|
||||||
data.Data.Remove("UUID");
|
|
||||||
if (data.Data.ContainsKey("ScopeID"))
|
|
||||||
data.Data.Remove("ScopeID");
|
|
||||||
|
|
||||||
string[] fields = new List<string>(data.Data.Keys).ToArray();
|
if (words.Length > 2)
|
||||||
|
return new UserAccountData[0];
|
||||||
|
|
||||||
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
using (SqlCommand cmd = new SqlCommand())
|
using (SqlCommand cmd = new SqlCommand())
|
||||||
{
|
{
|
||||||
StringBuilder updateBuilder = new StringBuilder();
|
if (words.Length == 1)
|
||||||
updateBuilder.AppendFormat("update {0} set ", m_Realm);
|
|
||||||
bool first = true;
|
|
||||||
foreach (string field in fields)
|
|
||||||
{
|
{
|
||||||
if (!first)
|
cmd.CommandText = String.Format("select * from {0} where ([ScopeID]=@ScopeID or [ScopeID]='00000000-0000-0000-0000-000000000000') and ([FirstName] like @search or [LastName] like @search)", m_Realm);
|
||||||
updateBuilder.Append(", ");
|
cmd.Parameters.Add(m_database.CreateParameter("@scopeID", scopeID));
|
||||||
updateBuilder.AppendFormat("{0} = @{0}", field);
|
cmd.Parameters.Add(m_database.CreateParameter("@search", "%" + words[0] + "%"));
|
||||||
|
}
|
||||||
first = false;
|
else
|
||||||
cmd.Parameters.Add(m_database.CreateParameter("@" + field, data.Data[field]));
|
{
|
||||||
|
cmd.CommandText = String.Format("select * from {0} where ([ScopeID]=@ScopeID or [ScopeID]='00000000-0000-0000-0000-000000000000') and ([FirstName] like @searchFirst or [LastName] like @searchLast)", m_Realm);
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@searchFirst", "%" + words[0] + "%"));
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@searchLast", "%" + words[1] + "%"));
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@ScopeID", scopeID.ToString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
updateBuilder.Append(" where UUID = @principalID");
|
return DoQuery(cmd);
|
||||||
|
|
||||||
if (data.ScopeID != UUID.Zero)
|
|
||||||
updateBuilder.Append(" and ScopeID = @scopeID");
|
|
||||||
|
|
||||||
cmd.CommandText = updateBuilder.ToString();
|
|
||||||
cmd.Connection = conn;
|
|
||||||
cmd.Parameters.Add(m_database.CreateParameter("@principalID", data.PrincipalID));
|
|
||||||
cmd.Parameters.Add(m_database.CreateParameter("@scopeID", data.ScopeID));
|
|
||||||
conn.Open();
|
|
||||||
|
|
||||||
if (cmd.ExecuteNonQuery() < 1)
|
|
||||||
{
|
|
||||||
StringBuilder insertBuilder = new StringBuilder();
|
|
||||||
insertBuilder.AppendFormat("insert into {0} (UUID, ScopeID, ", m_Realm);
|
|
||||||
insertBuilder.Append(String.Join(", ", fields));
|
|
||||||
insertBuilder.Append(") values (@principalID, @scopeID, @");
|
|
||||||
insertBuilder.Append(String.Join(", @", fields));
|
|
||||||
insertBuilder.Append(")");
|
|
||||||
|
|
||||||
cmd.CommandText = insertBuilder.ToString();
|
|
||||||
|
|
||||||
if (cmd.ExecuteNonQuery() < 1)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Store(UserAccountData data, UUID principalID, string token)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool SetDataItem(UUID principalID, string item, string value)
|
|
||||||
{
|
|
||||||
string sql = string.Format("update {0} set {1} = @{1} where UUID = @UUID", m_Realm, item);
|
|
||||||
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
|
||||||
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
|
||||||
{
|
|
||||||
cmd.Parameters.Add(m_database.CreateParameter("@" + item, value));
|
|
||||||
cmd.Parameters.Add(m_database.CreateParameter("@UUID", principalID));
|
|
||||||
|
|
||||||
conn.Open();
|
|
||||||
|
|
||||||
if (cmd.ExecuteNonQuery() > 0)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserAccountData[] Get(string[] keys, string[] vals)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserAccountData[] GetUsers(UUID scopeID, string query)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,166 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) Contributors, http://opensimulator.org/
|
||||||
|
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* * Neither the name of the OpenSimulator Project nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ''AS IS'' AND ANY
|
||||||
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||||
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using OpenMetaverse;
|
||||||
|
using OpenSim.Framework;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using log4net;
|
||||||
|
|
||||||
|
namespace OpenSim.Data.MSSQL
|
||||||
|
{
|
||||||
|
public class MSSQLXInventoryData : IXInventoryData
|
||||||
|
{
|
||||||
|
private static readonly ILog m_log = LogManager.GetLogger(
|
||||||
|
MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
|
private MSSQLGenericTableHandler<XInventoryFolder> m_Folders;
|
||||||
|
private MSSQLItemHandler m_Items;
|
||||||
|
|
||||||
|
public MSSQLXInventoryData(string conn, string realm)
|
||||||
|
{
|
||||||
|
m_Folders = new MSSQLGenericTableHandler<XInventoryFolder>(
|
||||||
|
conn, "inventoryfolders", "InventoryStore");
|
||||||
|
m_Items = new MSSQLItemHandler(
|
||||||
|
conn, "inventoryitems", String.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
public XInventoryFolder[] GetFolders(string[] fields, string[] vals)
|
||||||
|
{
|
||||||
|
return m_Folders.Get(fields, vals);
|
||||||
|
}
|
||||||
|
|
||||||
|
public XInventoryItem[] GetItems(string[] fields, string[] vals)
|
||||||
|
{
|
||||||
|
return m_Items.Get(fields, vals);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool StoreFolder(XInventoryFolder folder)
|
||||||
|
{
|
||||||
|
return m_Folders.Store(folder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool StoreItem(XInventoryItem item)
|
||||||
|
{
|
||||||
|
return m_Items.Store(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool DeleteFolders(string field, string val)
|
||||||
|
{
|
||||||
|
return m_Folders.Delete(field, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool DeleteItems(string field, string val)
|
||||||
|
{
|
||||||
|
return m_Items.Delete(field, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool MoveItem(string id, string newParent)
|
||||||
|
{
|
||||||
|
return m_Items.MoveItem(id, newParent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public XInventoryItem[] GetActiveGestures(UUID principalID)
|
||||||
|
{
|
||||||
|
return m_Items.GetActiveGestures(principalID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetAssetPermissions(UUID principalID, UUID assetID)
|
||||||
|
{
|
||||||
|
return m_Items.GetAssetPermissions(principalID, assetID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MSSQLItemHandler : MSSQLGenericTableHandler<XInventoryItem>
|
||||||
|
{
|
||||||
|
public MSSQLItemHandler(string c, string t, string m) :
|
||||||
|
base(c, t, m)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool MoveItem(string id, string newParent)
|
||||||
|
{
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand())
|
||||||
|
{
|
||||||
|
|
||||||
|
cmd.CommandText = String.Format("update {0} set parentFolderID = @ParentFolderID where inventoryID = @InventoryID", m_Realm);
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@ParentFolderID", newParent));
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@InventoryID", id));
|
||||||
|
cmd.Connection = conn;
|
||||||
|
conn.Open();
|
||||||
|
return cmd.ExecuteNonQuery() == 0 ? false : true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public XInventoryItem[] GetActiveGestures(UUID principalID)
|
||||||
|
{
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand())
|
||||||
|
{
|
||||||
|
cmd.CommandText = String.Format("select * from inventoryitems where avatarId = @uuid and assetType = @type and flags = 1", m_Realm);
|
||||||
|
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@uuid", principalID.ToString()));
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@type", (int)AssetType.Gesture));
|
||||||
|
cmd.Connection = conn;
|
||||||
|
conn.Open();
|
||||||
|
return DoQuery(cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetAssetPermissions(UUID principalID, UUID assetID)
|
||||||
|
{
|
||||||
|
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||||
|
using (SqlCommand cmd = new SqlCommand())
|
||||||
|
{
|
||||||
|
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.Add(m_database.CreateParameter("@PrincipalID", principalID.ToString()));
|
||||||
|
cmd.Parameters.Add(m_database.CreateParameter("@AssetID", assetID.ToString()));
|
||||||
|
cmd.Connection = conn;
|
||||||
|
conn.Open();
|
||||||
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||||
|
{
|
||||||
|
|
||||||
|
int perms = 0;
|
||||||
|
|
||||||
|
if (reader.Read())
|
||||||
|
{
|
||||||
|
perms = Convert.ToInt32(reader["inventoryCurrentPermissions"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return perms;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
BEGIN TRANSACTION
|
||||||
|
|
||||||
|
CREATE TABLE [auth] (
|
||||||
|
[uuid] [uniqueidentifier] NOT NULL default '00000000-0000-0000-0000-000000000000',
|
||||||
|
[passwordHash] [varchar](32) NOT NULL,
|
||||||
|
[passwordSalt] [varchar](32) NOT NULL,
|
||||||
|
[webLoginKey] [varchar](255) NOT NULL,
|
||||||
|
[accountType] VARCHAR(32) NOT NULL DEFAULT 'UserAccount',
|
||||||
|
) ON [PRIMARY]
|
||||||
|
|
||||||
|
CREATE TABLE [tokens] (
|
||||||
|
[uuid] [uniqueidentifier] NOT NULL default '00000000-0000-0000-0000-000000000000',
|
||||||
|
[token] [varchar](255) NOT NULL,
|
||||||
|
[validity] [datetime] NOT NULL )
|
||||||
|
ON [PRIMARY]
|
||||||
|
|
||||||
|
COMMIT
|
|
@ -0,0 +1,15 @@
|
||||||
|
BEGIN TRANSACTION
|
||||||
|
|
||||||
|
CREATE TABLE [Avatars] (
|
||||||
|
[PrincipalID] uniqueidentifier NOT NULL,
|
||||||
|
[Name] varchar(32) NOT NULL,
|
||||||
|
[Value] varchar(255) NOT NULL DEFAULT '',
|
||||||
|
PRIMARY KEY CLUSTERED
|
||||||
|
(
|
||||||
|
[PrincipalID] ASC, [Name] ASC
|
||||||
|
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
|
||||||
|
) ON [PRIMARY]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
COMMIT
|
|
@ -0,0 +1,11 @@
|
||||||
|
BEGIN TRANSACTION
|
||||||
|
|
||||||
|
CREATE TABLE [Friends] (
|
||||||
|
[PrincipalID] uniqueidentifier NOT NULL,
|
||||||
|
[FriendID] varchar(255) NOT NULL,
|
||||||
|
[Flags] char(16) NOT NULL DEFAULT '0',
|
||||||
|
[Offered] varchar(32) NOT NULL DEFAULT 0)
|
||||||
|
ON [PRIMARY]
|
||||||
|
|
||||||
|
|
||||||
|
COMMIT
|
|
@ -0,0 +1,19 @@
|
||||||
|
BEGIN TRANSACTION
|
||||||
|
|
||||||
|
CREATE TABLE [Presence] (
|
||||||
|
[UserID] varchar(255) NOT NULL,
|
||||||
|
[RegionID] uniqueidentifier NOT NULL,
|
||||||
|
[SessionID] uniqueidentifier NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000',
|
||||||
|
[SecureSessionID] uniqueidentifier NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000',
|
||||||
|
[Online] char(5) NOT NULL DEFAULT 'false',
|
||||||
|
[Login] char(16) NOT NULL DEFAULT '0',
|
||||||
|
[Logout] char(16) NOT NULL DEFAULT '0',
|
||||||
|
[Position] char(64) NOT NULL DEFAULT '<0,0,0>',
|
||||||
|
[LookAt] char(64) NOT NULL DEFAULT '<0,0,0>',
|
||||||
|
[HomeRegionID] uniqueidentifier NOT NULL,
|
||||||
|
[HomePosition] CHAR(64) NOT NULL DEFAULT '<0,0,0>',
|
||||||
|
[HomeLookAt] CHAR(64) NOT NULL DEFAULT '<0,0,0>',
|
||||||
|
)
|
||||||
|
ON [PRIMARY]
|
||||||
|
|
||||||
|
COMMIT
|
|
@ -0,0 +1,6 @@
|
||||||
|
BEGIN TRANSACTION
|
||||||
|
|
||||||
|
INSERT INTO auth (UUID, passwordHash, passwordSalt, webLoginKey, accountType) SELECT [UUID] AS UUID, [passwordHash] AS passwordHash, [passwordSalt] AS passwordSalt, [webLoginKey] AS webLoginKey, 'UserAccount' as [accountType] FROM users;
|
||||||
|
|
||||||
|
|
||||||
|
COMMIT
|
|
@ -0,0 +1,6 @@
|
||||||
|
BEGIN TRANSACTION
|
||||||
|
|
||||||
|
INSERT INTO Friends (PrincipalID, FriendID, Flags, Offered) SELECT [ownerID], [friendID], [friendPerms], 0 FROM userfriends;
|
||||||
|
|
||||||
|
|
||||||
|
COMMIT
|
|
@ -0,0 +1,6 @@
|
||||||
|
BEGIN TRANSACTION
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX SessionID ON Presence(SessionID);
|
||||||
|
CREATE INDEX UserID ON Presence(UserID);
|
||||||
|
|
||||||
|
COMMIT
|
|
@ -0,0 +1,12 @@
|
||||||
|
BEGIN TRANSACTION
|
||||||
|
|
||||||
|
INSERT INTO UserAccounts (PrincipalID, ScopeID, FirstName, LastName, Email, ServiceURLs, Created) SELECT [UUID] AS PrincipalID, '00000000-0000-0000-0000-000000000000' AS ScopeID,
|
||||||
|
username AS FirstName,
|
||||||
|
lastname AS LastName,
|
||||||
|
email as Email, (
|
||||||
|
'AssetServerURI=' +
|
||||||
|
userAssetURI + ' InventoryServerURI=' + userInventoryURI + ' GatewayURI= HomeURI=') AS ServiceURLs,
|
||||||
|
created as Created FROM users;
|
||||||
|
|
||||||
|
|
||||||
|
COMMIT
|
|
@ -0,0 +1,9 @@
|
||||||
|
BEGIN TRANSACTION
|
||||||
|
|
||||||
|
ALTER TABLE regions ADD [flags] integer NOT NULL DEFAULT 0;
|
||||||
|
CREATE INDEX [flags] ON regions(flags);
|
||||||
|
ALTER TABLE [regions] ADD [last_seen] integer NOT NULL DEFAULT 0;
|
||||||
|
ALTER TABLE [regions] ADD [PrincipalID] uniqueidentifier NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000';
|
||||||
|
ALTER TABLE [regions] ADD [Token] varchar(255) NOT NULL DEFAULT 0;
|
||||||
|
|
||||||
|
COMMIT
|
Loading…
Reference in New Issue