* Moved insertRegionRow into MSSQLGridData

* Split table test and creation into table by table
* Debugged table creation Sql
* Added missing CreateUserFriendsTable.sql
ThreadPoolClientBranch
lbsa71 2008-02-13 20:08:46 +00:00
parent d9e01bf453
commit 15c6788dc7
5 changed files with 193 additions and 188 deletions

View File

@ -38,7 +38,7 @@ namespace OpenSim.Framework.Data.MSSQL
/// <summary> /// <summary>
/// A grid data interface for Microsoft SQL Server /// A grid data interface for Microsoft SQL Server
/// </summary> /// </summary>
public class SqlGridData : IGridData public class MSSQLGridData : IGridData
{ {
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 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() 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 try
{ {
@ -200,7 +200,7 @@ namespace OpenSim.Framework.Data.MSSQL
System.Console.WriteLine("No regions found. Create new one."); System.Console.WriteLine("No regions found. Create new one.");
} }
if (database.insertRegionRow(profile)) if ( insertRegionRow(profile))
{ {
return DataResponse.RESPONSE_OK; 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> /// <summary>
/// DEPRECIATED. Attempts to authenticate a region by comparing a shared secret. /// DEPRECIATED. Attempts to authenticate a region by comparing a shared secret.
/// </summary> /// </summary>

View File

@ -40,7 +40,7 @@ namespace OpenSim.Framework.Data.MSSQL
/// <summary> /// <summary>
/// A management class for the MS SQL Storage Engine /// A management class for the MS SQL Storage Engine
/// </summary> /// </summary>
internal class MSSQLManager public class MSSQLManager
{ {
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
@ -57,63 +57,56 @@ namespace OpenSim.Framework.Data.MSSQL
public MSSQLManager(string dataSource, string initialCatalog, string persistSecurityInfo, string userId, public MSSQLManager(string dataSource, string initialCatalog, string persistSecurityInfo, string userId,
string password) string password)
{ {
try connectionString = "Data Source=" + dataSource + ";Initial Catalog=" + initialCatalog +
{
connectionString = "Data Source=" + dataSource + ";Initial Catalog=" + initialCatalog +
";Persist Security Info=" + persistSecurityInfo + ";User ID=" + userId + ";Password=" + ";Persist Security Info=" + persistSecurityInfo + ";User ID=" + userId + ";Password=" +
password + ";"; password + ";";
dbcon = new SqlConnection(connectionString); dbcon = new SqlConnection(connectionString);
dbcon.Open(); dbcon.Open();
}
catch (Exception e)
{
throw new Exception("Error initialising Sql Database: " + e.ToString());
}
} }
private DataTable createRegionsTable() //private DataTable createRegionsTable()
{ //{
DataTable regions = new DataTable("regions"); // DataTable regions = new DataTable("regions");
createCol(regions, "regionHandle", typeof (ulong)); // createCol(regions, "regionHandle", typeof (ulong));
createCol(regions, "regionName", typeof (String)); // createCol(regions, "regionName", typeof (String));
createCol(regions, "uuid", typeof (String)); // createCol(regions, "uuid", typeof (String));
createCol(regions, "regionRecvKey", typeof (String)); // createCol(regions, "regionRecvKey", typeof (String));
createCol(regions, "regionSecret", typeof (String)); // createCol(regions, "regionSecret", typeof (String));
createCol(regions, "regionSendKey", typeof (String)); // createCol(regions, "regionSendKey", typeof (String));
createCol(regions, "regionDataURI", typeof (String)); // createCol(regions, "regionDataURI", typeof (String));
createCol(regions, "serverIP", typeof (String)); // createCol(regions, "serverIP", typeof (String));
createCol(regions, "serverPort", typeof (String)); // createCol(regions, "serverPort", typeof (String));
createCol(regions, "serverURI", typeof (String)); // createCol(regions, "serverURI", typeof (String));
createCol(regions, "locX", typeof (uint)); // createCol(regions, "locX", typeof (uint));
createCol(regions, "locY", typeof (uint)); // createCol(regions, "locY", typeof (uint));
createCol(regions, "locZ", typeof (uint)); // createCol(regions, "locZ", typeof (uint));
createCol(regions, "eastOverrideHandle", typeof (ulong)); // createCol(regions, "eastOverrideHandle", typeof (ulong));
createCol(regions, "westOverrideHandle", typeof (ulong)); // createCol(regions, "westOverrideHandle", typeof (ulong));
createCol(regions, "southOverrideHandle", typeof (ulong)); // createCol(regions, "southOverrideHandle", typeof (ulong));
createCol(regions, "northOverrideHandle", typeof (ulong)); // createCol(regions, "northOverrideHandle", typeof (ulong));
createCol(regions, "regionAssetURI", typeof (String)); // createCol(regions, "regionAssetURI", typeof (String));
createCol(regions, "regionAssetRecvKey", typeof (String)); // createCol(regions, "regionAssetRecvKey", typeof (String));
createCol(regions, "regionAssetSendKey", typeof (String)); // createCol(regions, "regionAssetSendKey", typeof (String));
createCol(regions, "regionUserURI", typeof (String)); // createCol(regions, "regionUserURI", typeof (String));
createCol(regions, "regionUserRecvKey", typeof (String)); // createCol(regions, "regionUserRecvKey", typeof (String));
createCol(regions, "regionUserSendKey", typeof (String)); // createCol(regions, "regionUserSendKey", typeof (String));
createCol(regions, "regionMapTexture", typeof (String)); // createCol(regions, "regionMapTexture", typeof (String));
createCol(regions, "serverHttpPort", typeof (String)); // createCol(regions, "serverHttpPort", typeof (String));
createCol(regions, "serverRemotingPort", typeof (uint)); // createCol(regions, "serverRemotingPort", typeof (uint));
// Add in contraints // // Add in contraints
regions.PrimaryKey = new DataColumn[] {regions.Columns["UUID"]}; // regions.PrimaryKey = new DataColumn[] {regions.Columns["UUID"]};
return regions; // return regions;
} //}
protected static void createCol(DataTable dt, string name, Type type) protected static void createCol(DataTable dt, string name, Type type)
{ {
@ -149,19 +142,19 @@ namespace OpenSim.Framework.Data.MSSQL
// slightly differently. // slightly differently.
private static string SqlType(Type type) private static string SqlType(Type type)
{ {
if (type == typeof (String)) if (type == typeof(String))
{ {
return "varchar(255)"; return "varchar(255)";
} }
else if (type == typeof (Int32)) else if (type == typeof(Int32))
{ {
return "integer"; return "integer";
} }
else if (type == typeof (Double)) else if (type == typeof(Double))
{ {
return "float"; return "float";
} }
else if (type == typeof (Byte[])) else if (type == typeof(Byte[]))
{ {
return "image"; return "image";
} }
@ -210,14 +203,14 @@ namespace OpenSim.Framework.Data.MSSQL
/// <returns>A Sql DB Command</returns> /// <returns>A Sql DB Command</returns>
public IDbCommand Query(string sql, Dictionary<string, string> parameters) public IDbCommand Query(string sql, Dictionary<string, string> parameters)
{ {
SqlCommand dbcommand = (SqlCommand) dbcon.CreateCommand(); SqlCommand dbcommand = (SqlCommand)dbcon.CreateCommand();
dbcommand.CommandText = sql; dbcommand.CommandText = sql;
foreach (KeyValuePair<string, string> param in parameters) foreach (KeyValuePair<string, string> param in parameters)
{ {
dbcommand.Parameters.AddWithValue(param.Key, param.Value); dbcommand.Parameters.AddWithValue(param.Key, param.Value);
} }
return (IDbCommand) dbcommand; return (IDbCommand)dbcommand;
} }
/// <summary> /// <summary>
@ -233,20 +226,20 @@ namespace OpenSim.Framework.Data.MSSQL
{ {
// Region Main // Region Main
regionprofile.regionHandle = Convert.ToUInt64(reader["regionHandle"]); regionprofile.regionHandle = Convert.ToUInt64(reader["regionHandle"]);
regionprofile.regionName = (string) reader["regionName"]; regionprofile.regionName = (string)reader["regionName"];
regionprofile.UUID = new LLUUID((string) reader["uuid"]); regionprofile.UUID = new LLUUID((string)reader["uuid"]);
// Secrets // Secrets
regionprofile.regionRecvKey = (string) reader["regionRecvKey"]; regionprofile.regionRecvKey = (string)reader["regionRecvKey"];
regionprofile.regionSecret = (string) reader["regionSecret"]; regionprofile.regionSecret = (string)reader["regionSecret"];
regionprofile.regionSendKey = (string) reader["regionSendKey"]; regionprofile.regionSendKey = (string)reader["regionSendKey"];
// Region Server // Region Server
regionprofile.regionDataURI = (string) reader["regionDataURI"]; regionprofile.regionDataURI = (string)reader["regionDataURI"];
regionprofile.regionOnline = false; // Needs to be pinged before this can be set. regionprofile.regionOnline = false; // Needs to be pinged before this can be set.
regionprofile.serverIP = (string) reader["serverIP"]; regionprofile.serverIP = (string)reader["serverIP"];
regionprofile.serverPort = Convert.ToUInt32(reader["serverPort"]); regionprofile.serverPort = Convert.ToUInt32(reader["serverPort"]);
regionprofile.serverURI = (string) reader["serverURI"]; regionprofile.serverURI = (string)reader["serverURI"];
regionprofile.httpPort = Convert.ToUInt32(reader["serverHttpPort"]); regionprofile.httpPort = Convert.ToUInt32(reader["serverHttpPort"]);
regionprofile.remotingPort = Convert.ToUInt32(reader["serverRemotingPort"]); regionprofile.remotingPort = Convert.ToUInt32(reader["serverRemotingPort"]);
@ -263,14 +256,14 @@ namespace OpenSim.Framework.Data.MSSQL
regionprofile.regionNorthOverrideHandle = Convert.ToUInt64(reader["northOverrideHandle"]); regionprofile.regionNorthOverrideHandle = Convert.ToUInt64(reader["northOverrideHandle"]);
// Assets // Assets
regionprofile.regionAssetURI = (string) reader["regionAssetURI"]; regionprofile.regionAssetURI = (string)reader["regionAssetURI"];
regionprofile.regionAssetRecvKey = (string) reader["regionAssetRecvKey"]; regionprofile.regionAssetRecvKey = (string)reader["regionAssetRecvKey"];
regionprofile.regionAssetSendKey = (string) reader["regionAssetSendKey"]; regionprofile.regionAssetSendKey = (string)reader["regionAssetSendKey"];
// Userserver // Userserver
regionprofile.regionUserURI = (string) reader["regionUserURI"]; regionprofile.regionUserURI = (string)reader["regionUserURI"];
regionprofile.regionUserRecvKey = (string) reader["regionUserRecvKey"]; regionprofile.regionUserRecvKey = (string)reader["regionUserRecvKey"];
regionprofile.regionUserSendKey = (string) reader["regionUserSendKey"]; regionprofile.regionUserSendKey = (string)reader["regionUserSendKey"];
// World Map Addition // World Map Addition
string tempRegionMap = reader["regionMapTexture"].ToString(); string tempRegionMap = reader["regionMapTexture"].ToString();
@ -302,12 +295,12 @@ namespace OpenSim.Framework.Data.MSSQL
if (reader.Read()) if (reader.Read())
{ {
retval.UUID = new LLUUID((string) reader["UUID"]); retval.UUID = new LLUUID((string)reader["UUID"]);
retval.username = (string) reader["username"]; retval.username = (string)reader["username"];
retval.surname = (string) reader["lastname"]; retval.surname = (string)reader["lastname"];
retval.passwordHash = (string) reader["passwordHash"]; retval.passwordHash = (string)reader["passwordHash"];
retval.passwordSalt = (string) reader["passwordSalt"]; retval.passwordSalt = (string)reader["passwordSalt"];
retval.homeRegion = Convert.ToUInt64(reader["homeRegion"].ToString()); retval.homeRegion = Convert.ToUInt64(reader["homeRegion"].ToString());
retval.homeLocation = new LLVector3( retval.homeLocation = new LLVector3(
@ -322,17 +315,17 @@ namespace OpenSim.Framework.Data.MSSQL
retval.created = Convert.ToInt32(reader["created"].ToString()); retval.created = Convert.ToInt32(reader["created"].ToString());
retval.lastLogin = Convert.ToInt32(reader["lastLogin"].ToString()); retval.lastLogin = Convert.ToInt32(reader["lastLogin"].ToString());
retval.userInventoryURI = (string) reader["userInventoryURI"]; retval.userInventoryURI = (string)reader["userInventoryURI"];
retval.userAssetURI = (string) reader["userAssetURI"]; retval.userAssetURI = (string)reader["userAssetURI"];
retval.profileCanDoMask = Convert.ToUInt32(reader["profileCanDoMask"].ToString()); retval.profileCanDoMask = Convert.ToUInt32(reader["profileCanDoMask"].ToString());
retval.profileWantDoMask = Convert.ToUInt32(reader["profileWantDoMask"].ToString()); retval.profileWantDoMask = Convert.ToUInt32(reader["profileWantDoMask"].ToString());
retval.profileAboutText = (string) reader["profileAboutText"]; retval.profileAboutText = (string)reader["profileAboutText"];
retval.profileFirstText = (string) reader["profileFirstText"]; retval.profileFirstText = (string)reader["profileFirstText"];
retval.profileImage = new LLUUID((string) reader["profileImage"]); retval.profileImage = new LLUUID((string)reader["profileImage"]);
retval.profileFirstImage = new LLUUID((string) reader["profileFirstImage"]); retval.profileFirstImage = new LLUUID((string)reader["profileFirstImage"]);
retval.webLoginKey = new LLUUID((string)reader["webLoginKey"]); retval.webLoginKey = new LLUUID((string)reader["webLoginKey"]);
} }
else else
@ -354,12 +347,12 @@ namespace OpenSim.Framework.Data.MSSQL
if (reader.Read()) if (reader.Read())
{ {
// Agent IDs // Agent IDs
retval.UUID = new LLUUID((string) reader["UUID"]); retval.UUID = new LLUUID((string)reader["UUID"]);
retval.sessionID = new LLUUID((string) reader["sessionID"]); retval.sessionID = new LLUUID((string)reader["sessionID"]);
retval.secureSessionID = new LLUUID((string) reader["secureSessionID"]); retval.secureSessionID = new LLUUID((string)reader["secureSessionID"]);
// Agent Who? // Agent Who?
retval.agentIP = (string) reader["agentIP"]; retval.agentIP = (string)reader["agentIP"];
retval.agentPort = Convert.ToUInt32(reader["agentPort"].ToString()); retval.agentPort = Convert.ToUInt32(reader["agentPort"].ToString());
retval.agentOnline = Convert.ToBoolean(reader["agentOnline"].ToString()); retval.agentOnline = Convert.ToBoolean(reader["agentOnline"].ToString());
@ -368,9 +361,9 @@ namespace OpenSim.Framework.Data.MSSQL
retval.logoutTime = Convert.ToInt32(reader["logoutTime"].ToString()); retval.logoutTime = Convert.ToInt32(reader["logoutTime"].ToString());
// Current position // Current position
retval.currentRegion = (string) reader["currentRegion"]; retval.currentRegion = (string)reader["currentRegion"];
retval.currentHandle = Convert.ToUInt64(reader["currentHandle"].ToString()); retval.currentHandle = Convert.ToUInt64(reader["currentHandle"].ToString());
LLVector3.TryParse((string) reader["currentPos"], out retval.currentPos); LLVector3.TryParse((string)reader["currentPos"], out retval.currentPos);
} }
else else
{ {
@ -387,12 +380,12 @@ namespace OpenSim.Framework.Data.MSSQL
// Region Main // Region Main
asset = new AssetBase(); asset = new AssetBase();
asset.Data = (byte[]) reader["data"]; asset.Data = (byte[])reader["data"];
asset.Description = (string) reader["description"]; asset.Description = (string)reader["description"];
asset.FullID = new LLUUID((string) reader["id"]); asset.FullID = new LLUUID((string)reader["id"]);
asset.InvType = Convert.ToSByte(reader["invType"]); asset.InvType = Convert.ToSByte(reader["invType"]);
asset.Local = Convert.ToBoolean(reader["local"]); // ((sbyte)reader["local"]) != 0 ? true : false; asset.Local = Convert.ToBoolean(reader["local"]); // ((sbyte)reader["local"]) != 0 ? true : false;
asset.Name = (string) reader["name"]; asset.Name = (string)reader["name"];
asset.Type = Convert.ToSByte(reader["assetType"]); asset.Type = Convert.ToSByte(reader["assetType"]);
} }
else else
@ -402,76 +395,6 @@ namespace OpenSim.Framework.Data.MSSQL
return asset; 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> /// <summary>
/// Inserts a new row into the log database /// Inserts a new row into the log database
@ -617,21 +540,14 @@ namespace OpenSim.Framework.Data.MSSQL
/// <param name="name"></param> /// <param name="name"></param>
public void ExecuteResourceSql(string name) public void ExecuteResourceSql(string name)
{ {
try SqlCommand cmd = new SqlCommand(getResourceString(name), (SqlConnection)dbcon);
{ cmd.ExecuteNonQuery();
SqlCommand cmd = new SqlCommand(getResourceString(name), (SqlConnection) dbcon); cmd.Dispose();
cmd.ExecuteNonQuery();
cmd.Dispose();
}
catch (Exception e)
{
m_log.Error("Unable to execute query " + e.ToString());
}
} }
public SqlConnection getConnection() public SqlConnection getConnection()
{ {
return (SqlConnection) dbcon; return (SqlConnection)dbcon;
} }
/// <summary> /// <summary>
@ -652,7 +568,7 @@ namespace OpenSim.Framework.Data.MSSQL
{ {
try try
{ {
string tableName = (string) tables["TABLE_NAME"]; string tableName = (string)tables["TABLE_NAME"];
if (tableList.ContainsKey(tableName)) if (tableList.ContainsKey(tableName))
tableList[tableName] = tableName; tableList[tableName] = tableName;
} }

View File

@ -37,7 +37,7 @@ namespace OpenSim.Framework.Data.MSSQL
/// <summary> /// <summary>
/// A database interface class to a user profile storage system /// A database interface class to a user profile storage system
/// </summary> /// </summary>
internal class MSSQLUserData : IUserData public class MSSQLUserData : IUserData
{ {
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
@ -86,37 +86,41 @@ namespace OpenSim.Framework.Data.MSSQL
new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId,
settingPassword); settingPassword);
if (!TestTables()) TestTables();
{
database.ExecuteResourceSql("Mssql-agents.sql");
database.ExecuteResourceSql("Mssql-users.sql");
database.ExecuteResourceSql("Mssql-userfriends.sql");
}
} }
private bool TestTables() private bool TestTables()
{ {
IDbCommand cmd = database.Query("select top 1 webLoginKey from "+m_usersTableName, new Dictionary<string, string>()); IDbCommand cmd;
cmd = database.Query("select top 1 * from " + m_usersTableName, new Dictionary<string, string>());
try try
{ {
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
cmd.Dispose();
} }
catch catch
{ {
database.Query("alter table "+m_usersTableName+" add column [webLoginKey] varchar(36) default NULL", new Dictionary<string, string>()); database.ExecuteResourceSql("Mssql-users.sql");
cmd.ExecuteNonQuery();
cmd.Dispose();
} }
cmd = database.Query("select top 1 * from "+m_usersTableName, new Dictionary<string, string>()); cmd = database.Query("select top 1 * from " + m_agentsTableName, new Dictionary<string, string>());
try try
{ {
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
} }
catch catch
{ {
return false; 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; return true;
@ -180,6 +184,7 @@ namespace OpenSim.Framework.Data.MSSQL
"VALUES " + "VALUES " +
"(@ownerID,@friendID,@friendPerms,@datetimestamp)", "(@ownerID,@friendID,@friendPerms,@datetimestamp)",
param); param);
adder.ExecuteNonQuery(); adder.ExecuteNonQuery();
adder = adder =

View File

@ -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

View File

@ -1,10 +1,10 @@
SET ANSI_NULLS ON SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON SET ANSI_PADDING ON
GO
CREATE TABLE [db_owner].[regions]( CREATE TABLE [dbo].[regions](
[regionHandle] [varchar](255) COLLATE Latin1_General_CI_AS NULL, [regionHandle] [varchar](255) COLLATE Latin1_General_CI_AS NULL,
[regionName] [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, [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] )WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] ) ON [PRIMARY]
GO
SET ANSI_PADDING OFF SET ANSI_PADDING OFF