* Moved insertRegionRow into MSSQLGridData
* Split table test and creation into table by table * Debugged table creation Sql * Added missing CreateUserFriendsTable.sqlThreadPoolClientBranch
parent
d9e01bf453
commit
15c6788dc7
|
@ -38,7 +38,7 @@ namespace OpenSim.Framework.Data.MSSQL
|
|||
/// <summary>
|
||||
/// A grid data interface for Microsoft SQL Server
|
||||
/// </summary>
|
||||
public class SqlGridData : IGridData
|
||||
public class MSSQLGridData : IGridData
|
||||
{
|
||||
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
|
@ -77,7 +77,7 @@ namespace OpenSim.Framework.Data.MSSQL
|
|||
|
||||
private void TestTables()
|
||||
{
|
||||
IDbCommand cmd = database.Query("SELECT * FROM "+m_regionsTableName, new Dictionary<string, string>());
|
||||
IDbCommand cmd = database.Query("SELECT TOP 1 * FROM "+m_regionsTableName, new Dictionary<string, string>());
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -200,7 +200,7 @@ namespace OpenSim.Framework.Data.MSSQL
|
|||
System.Console.WriteLine("No regions found. Create new one.");
|
||||
}
|
||||
|
||||
if (database.insertRegionRow(profile))
|
||||
if ( insertRegionRow(profile))
|
||||
{
|
||||
return DataResponse.RESPONSE_OK;
|
||||
}
|
||||
|
@ -210,6 +210,77 @@ namespace OpenSim.Framework.Data.MSSQL
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new region in the database
|
||||
/// </summary>
|
||||
/// <param name="profile">The region profile to insert</param>
|
||||
/// <returns>Successful?</returns>
|
||||
public bool insertRegionRow(RegionProfileData profile)
|
||||
{
|
||||
//Insert new region
|
||||
string sql =
|
||||
"INSERT INTO " + m_regionsTableName + " ([regionHandle], [regionName], [uuid], [regionRecvKey], [regionSecret], [regionSendKey], [regionDataURI], ";
|
||||
sql +=
|
||||
"[serverIP], [serverPort], [serverURI], [locX], [locY], [locZ], [eastOverrideHandle], [westOverrideHandle], [southOverrideHandle], [northOverrideHandle], [regionAssetURI], [regionAssetRecvKey], ";
|
||||
sql +=
|
||||
"[regionAssetSendKey], [regionUserURI], [regionUserRecvKey], [regionUserSendKey], [regionMapTexture], [serverHttpPort], [serverRemotingPort]) VALUES ";
|
||||
|
||||
sql += "(@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI, ";
|
||||
sql +=
|
||||
"@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle, @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, ";
|
||||
sql +=
|
||||
"@regionAssetSendKey, @regionUserURI, @regionUserRecvKey, @regionUserSendKey, @regionMapTexture, @serverHttpPort, @serverRemotingPort);";
|
||||
|
||||
Dictionary<string, string> parameters = new Dictionary<string, string>();
|
||||
|
||||
parameters["regionHandle"] = profile.regionHandle.ToString();
|
||||
parameters["regionName"] = profile.regionName;
|
||||
parameters["uuid"] = profile.UUID.ToString();
|
||||
parameters["regionRecvKey"] = profile.regionRecvKey;
|
||||
parameters["regionSecret"] = profile.regionSecret;
|
||||
parameters["regionSendKey"] = profile.regionSendKey;
|
||||
parameters["regionDataURI"] = profile.regionDataURI;
|
||||
parameters["serverIP"] = profile.serverIP;
|
||||
parameters["serverPort"] = profile.serverPort.ToString();
|
||||
parameters["serverURI"] = profile.serverURI;
|
||||
parameters["locX"] = profile.regionLocX.ToString();
|
||||
parameters["locY"] = profile.regionLocY.ToString();
|
||||
parameters["locZ"] = profile.regionLocZ.ToString();
|
||||
parameters["eastOverrideHandle"] = profile.regionEastOverrideHandle.ToString();
|
||||
parameters["westOverrideHandle"] = profile.regionWestOverrideHandle.ToString();
|
||||
parameters["northOverrideHandle"] = profile.regionNorthOverrideHandle.ToString();
|
||||
parameters["southOverrideHandle"] = profile.regionSouthOverrideHandle.ToString();
|
||||
parameters["regionAssetURI"] = profile.regionAssetURI;
|
||||
parameters["regionAssetRecvKey"] = profile.regionAssetRecvKey;
|
||||
parameters["regionAssetSendKey"] = profile.regionAssetSendKey;
|
||||
parameters["regionUserURI"] = profile.regionUserURI;
|
||||
parameters["regionUserRecvKey"] = profile.regionUserRecvKey;
|
||||
parameters["regionUserSendKey"] = profile.regionUserSendKey;
|
||||
parameters["regionMapTexture"] = profile.regionMapTextureID.ToString();
|
||||
parameters["serverHttpPort"] = profile.httpPort.ToString();
|
||||
parameters["serverRemotingPort"] = profile.remotingPort.ToString();
|
||||
|
||||
|
||||
bool returnval = false;
|
||||
|
||||
try
|
||||
{
|
||||
IDbCommand result = database.Query(sql, parameters);
|
||||
|
||||
if (result.ExecuteNonQuery() == 1)
|
||||
returnval = true;
|
||||
|
||||
result.Dispose();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error("MSSQLManager : " + e.ToString());
|
||||
}
|
||||
|
||||
return returnval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DEPRECIATED. Attempts to authenticate a region by comparing a shared secret.
|
||||
/// </summary>
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace OpenSim.Framework.Data.MSSQL
|
|||
/// <summary>
|
||||
/// A management class for the MS SQL Storage Engine
|
||||
/// </summary>
|
||||
internal class MSSQLManager
|
||||
public class MSSQLManager
|
||||
{
|
||||
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
|
@ -56,8 +56,6 @@ namespace OpenSim.Framework.Data.MSSQL
|
|||
|
||||
public MSSQLManager(string dataSource, string initialCatalog, string persistSecurityInfo, string userId,
|
||||
string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
connectionString = "Data Source=" + dataSource + ";Initial Catalog=" + initialCatalog +
|
||||
";Persist Security Info=" + persistSecurityInfo + ";User ID=" + userId + ";Password=" +
|
||||
|
@ -65,55 +63,50 @@ namespace OpenSim.Framework.Data.MSSQL
|
|||
dbcon = new SqlConnection(connectionString);
|
||||
dbcon.Open();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception("Error initialising Sql Database: " + e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private DataTable createRegionsTable()
|
||||
{
|
||||
DataTable regions = new DataTable("regions");
|
||||
//private DataTable createRegionsTable()
|
||||
//{
|
||||
// DataTable regions = new DataTable("regions");
|
||||
|
||||
createCol(regions, "regionHandle", typeof (ulong));
|
||||
createCol(regions, "regionName", typeof (String));
|
||||
createCol(regions, "uuid", typeof (String));
|
||||
// createCol(regions, "regionHandle", typeof (ulong));
|
||||
// createCol(regions, "regionName", typeof (String));
|
||||
// createCol(regions, "uuid", typeof (String));
|
||||
|
||||
createCol(regions, "regionRecvKey", typeof (String));
|
||||
createCol(regions, "regionSecret", typeof (String));
|
||||
createCol(regions, "regionSendKey", typeof (String));
|
||||
// createCol(regions, "regionRecvKey", typeof (String));
|
||||
// createCol(regions, "regionSecret", typeof (String));
|
||||
// createCol(regions, "regionSendKey", typeof (String));
|
||||
|
||||
createCol(regions, "regionDataURI", typeof (String));
|
||||
createCol(regions, "serverIP", typeof (String));
|
||||
createCol(regions, "serverPort", typeof (String));
|
||||
createCol(regions, "serverURI", typeof (String));
|
||||
// createCol(regions, "regionDataURI", typeof (String));
|
||||
// createCol(regions, "serverIP", typeof (String));
|
||||
// createCol(regions, "serverPort", typeof (String));
|
||||
// createCol(regions, "serverURI", typeof (String));
|
||||
|
||||
|
||||
createCol(regions, "locX", typeof (uint));
|
||||
createCol(regions, "locY", typeof (uint));
|
||||
createCol(regions, "locZ", typeof (uint));
|
||||
// createCol(regions, "locX", typeof (uint));
|
||||
// createCol(regions, "locY", typeof (uint));
|
||||
// createCol(regions, "locZ", typeof (uint));
|
||||
|
||||
createCol(regions, "eastOverrideHandle", typeof (ulong));
|
||||
createCol(regions, "westOverrideHandle", typeof (ulong));
|
||||
createCol(regions, "southOverrideHandle", typeof (ulong));
|
||||
createCol(regions, "northOverrideHandle", typeof (ulong));
|
||||
// createCol(regions, "eastOverrideHandle", typeof (ulong));
|
||||
// createCol(regions, "westOverrideHandle", typeof (ulong));
|
||||
// createCol(regions, "southOverrideHandle", typeof (ulong));
|
||||
// createCol(regions, "northOverrideHandle", typeof (ulong));
|
||||
|
||||
createCol(regions, "regionAssetURI", typeof (String));
|
||||
createCol(regions, "regionAssetRecvKey", typeof (String));
|
||||
createCol(regions, "regionAssetSendKey", typeof (String));
|
||||
// createCol(regions, "regionAssetURI", typeof (String));
|
||||
// createCol(regions, "regionAssetRecvKey", typeof (String));
|
||||
// createCol(regions, "regionAssetSendKey", typeof (String));
|
||||
|
||||
createCol(regions, "regionUserURI", typeof (String));
|
||||
createCol(regions, "regionUserRecvKey", typeof (String));
|
||||
createCol(regions, "regionUserSendKey", typeof (String));
|
||||
// createCol(regions, "regionUserURI", typeof (String));
|
||||
// createCol(regions, "regionUserRecvKey", typeof (String));
|
||||
// createCol(regions, "regionUserSendKey", typeof (String));
|
||||
|
||||
createCol(regions, "regionMapTexture", typeof (String));
|
||||
createCol(regions, "serverHttpPort", typeof (String));
|
||||
createCol(regions, "serverRemotingPort", typeof (uint));
|
||||
// createCol(regions, "regionMapTexture", typeof (String));
|
||||
// createCol(regions, "serverHttpPort", typeof (String));
|
||||
// createCol(regions, "serverRemotingPort", typeof (uint));
|
||||
|
||||
// Add in contraints
|
||||
regions.PrimaryKey = new DataColumn[] {regions.Columns["UUID"]};
|
||||
return regions;
|
||||
}
|
||||
// // Add in contraints
|
||||
// regions.PrimaryKey = new DataColumn[] {regions.Columns["UUID"]};
|
||||
// return regions;
|
||||
//}
|
||||
|
||||
protected static void createCol(DataTable dt, string name, Type type)
|
||||
{
|
||||
|
@ -402,76 +395,6 @@ namespace OpenSim.Framework.Data.MSSQL
|
|||
return asset;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new region in the database
|
||||
/// </summary>
|
||||
/// <param name="profile">The region profile to insert</param>
|
||||
/// <returns>Successful?</returns>
|
||||
public bool insertRegionRow(RegionProfileData profile)
|
||||
{
|
||||
//Insert new region
|
||||
string sql =
|
||||
"INSERT INTO regions ([regionHandle], [regionName], [uuid], [regionRecvKey], [regionSecret], [regionSendKey], [regionDataURI], ";
|
||||
sql +=
|
||||
"[serverIP], [serverPort], [serverURI], [locX], [locY], [locZ], [eastOverrideHandle], [westOverrideHandle], [southOverrideHandle], [northOverrideHandle], [regionAssetURI], [regionAssetRecvKey], ";
|
||||
sql +=
|
||||
"[regionAssetSendKey], [regionUserURI], [regionUserRecvKey], [regionUserSendKey], [regionMapTexture], [serverHttpPort], [serverRemotingPort]) VALUES ";
|
||||
|
||||
sql += "(@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI, ";
|
||||
sql +=
|
||||
"@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle, @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, ";
|
||||
sql +=
|
||||
"@regionAssetSendKey, @regionUserURI, @regionUserRecvKey, @regionUserSendKey, @regionMapTexture, @serverHttpPort, @serverRemotingPort);";
|
||||
|
||||
Dictionary<string, string> parameters = new Dictionary<string, string>();
|
||||
|
||||
parameters["regionHandle"] = profile.regionHandle.ToString();
|
||||
parameters["regionName"] = profile.regionName;
|
||||
parameters["uuid"] = profile.UUID.ToString();
|
||||
parameters["regionRecvKey"] = profile.regionRecvKey;
|
||||
parameters["regionSecret"] = profile.regionSecret;
|
||||
parameters["regionSendKey"] = profile.regionSendKey;
|
||||
parameters["regionDataURI"] = profile.regionDataURI;
|
||||
parameters["serverIP"] = profile.serverIP;
|
||||
parameters["serverPort"] = profile.serverPort.ToString();
|
||||
parameters["serverURI"] = profile.serverURI;
|
||||
parameters["locX"] = profile.regionLocX.ToString();
|
||||
parameters["locY"] = profile.regionLocY.ToString();
|
||||
parameters["locZ"] = profile.regionLocZ.ToString();
|
||||
parameters["eastOverrideHandle"] = profile.regionEastOverrideHandle.ToString();
|
||||
parameters["westOverrideHandle"] = profile.regionWestOverrideHandle.ToString();
|
||||
parameters["northOverrideHandle"] = profile.regionNorthOverrideHandle.ToString();
|
||||
parameters["southOverrideHandle"] = profile.regionSouthOverrideHandle.ToString();
|
||||
parameters["regionAssetURI"] = profile.regionAssetURI;
|
||||
parameters["regionAssetRecvKey"] = profile.regionAssetRecvKey;
|
||||
parameters["regionAssetSendKey"] = profile.regionAssetSendKey;
|
||||
parameters["regionUserURI"] = profile.regionUserURI;
|
||||
parameters["regionUserRecvKey"] = profile.regionUserRecvKey;
|
||||
parameters["regionUserSendKey"] = profile.regionUserSendKey;
|
||||
parameters["regionMapTexture"] = profile.regionMapTextureID.ToString();
|
||||
parameters["serverHttpPort"] = profile.httpPort.ToString();
|
||||
parameters["serverRemotingPort"] = profile.remotingPort.ToString();
|
||||
|
||||
|
||||
bool returnval = false;
|
||||
|
||||
try
|
||||
{
|
||||
IDbCommand result = Query(sql, parameters);
|
||||
|
||||
if (result.ExecuteNonQuery() == 1)
|
||||
returnval = true;
|
||||
|
||||
result.Dispose();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error("MSSQLManager : " + e.ToString());
|
||||
}
|
||||
|
||||
return returnval;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Inserts a new row into the log database
|
||||
|
@ -616,18 +539,11 @@ namespace OpenSim.Framework.Data.MSSQL
|
|||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
public void ExecuteResourceSql(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
SqlCommand cmd = new SqlCommand(getResourceString(name), (SqlConnection)dbcon);
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Dispose();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error("Unable to execute query " + e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public SqlConnection getConnection()
|
||||
{
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace OpenSim.Framework.Data.MSSQL
|
|||
/// <summary>
|
||||
/// A database interface class to a user profile storage system
|
||||
/// </summary>
|
||||
internal class MSSQLUserData : IUserData
|
||||
public class MSSQLUserData : IUserData
|
||||
{
|
||||
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
|
@ -86,28 +86,12 @@ namespace OpenSim.Framework.Data.MSSQL
|
|||
new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId,
|
||||
settingPassword);
|
||||
|
||||
if (!TestTables())
|
||||
{
|
||||
database.ExecuteResourceSql("Mssql-agents.sql");
|
||||
database.ExecuteResourceSql("Mssql-users.sql");
|
||||
database.ExecuteResourceSql("Mssql-userfriends.sql");
|
||||
}
|
||||
TestTables();
|
||||
}
|
||||
|
||||
private bool TestTables()
|
||||
{
|
||||
IDbCommand cmd = database.Query("select top 1 webLoginKey from "+m_usersTableName, new Dictionary<string, string>());
|
||||
try
|
||||
{
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Dispose();
|
||||
}
|
||||
catch
|
||||
{
|
||||
database.Query("alter table "+m_usersTableName+" add column [webLoginKey] varchar(36) default NULL", new Dictionary<string, string>());
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Dispose();
|
||||
}
|
||||
IDbCommand cmd;
|
||||
|
||||
cmd = database.Query("select top 1 * from " + m_usersTableName, new Dictionary<string, string>());
|
||||
try
|
||||
|
@ -116,7 +100,27 @@ namespace OpenSim.Framework.Data.MSSQL
|
|||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
database.ExecuteResourceSql("Mssql-users.sql");
|
||||
}
|
||||
|
||||
cmd = database.Query("select top 1 * from " + m_agentsTableName, new Dictionary<string, string>());
|
||||
try
|
||||
{
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
catch
|
||||
{
|
||||
database.ExecuteResourceSql("Mssql-agents.sql");
|
||||
}
|
||||
|
||||
cmd = database.Query("select top 1 * from " + m_userFriendsTableName, new Dictionary<string, string>());
|
||||
try
|
||||
{
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
catch
|
||||
{
|
||||
database.ExecuteResourceSql("CreateUserFriendsTable.sql");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -180,6 +184,7 @@ namespace OpenSim.Framework.Data.MSSQL
|
|||
"VALUES " +
|
||||
"(@ownerID,@friendID,@friendPerms,@datetimestamp)",
|
||||
param);
|
||||
|
||||
adder.ExecuteNonQuery();
|
||||
|
||||
adder =
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
SET ANSI_NULLS ON
|
||||
|
||||
SET QUOTED_IDENTIFIER ON
|
||||
|
||||
SET ANSI_PADDING ON
|
||||
|
||||
CREATE TABLE [dbo].[userfriends](
|
||||
[ownerID] [varchar](50) COLLATE Latin1_General_CI_AS NOT NULL,
|
||||
[friendID] [varchar](50) COLLATE Latin1_General_CI_AS NOT NULL,
|
||||
[friendPerms] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
|
||||
[datetimestamp] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
|
||||
) ON [PRIMARY]
|
||||
|
||||
SET ANSI_PADDING OFF
|
|
@ -1,10 +1,10 @@
|
|||
SET ANSI_NULLS ON
|
||||
GO
|
||||
|
||||
SET QUOTED_IDENTIFIER ON
|
||||
GO
|
||||
|
||||
SET ANSI_PADDING ON
|
||||
GO
|
||||
CREATE TABLE [db_owner].[regions](
|
||||
|
||||
CREATE TABLE [dbo].[regions](
|
||||
[regionHandle] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
|
||||
[regionName] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
|
||||
[uuid] [varchar](255) COLLATE Latin1_General_CI_AS NOT NULL,
|
||||
|
@ -37,5 +37,4 @@ PRIMARY KEY CLUSTERED
|
|||
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
|
||||
) ON [PRIMARY]
|
||||
|
||||
GO
|
||||
SET ANSI_PADDING OFF
|
||||
|
|
Loading…
Reference in New Issue