From 15c6788dc79e7f6d802f0217198e3af21dff4e57 Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Wed, 13 Feb 2008 20:08:46 +0000 Subject: [PATCH] * Moved insertRegionRow into MSSQLGridData * Split table test and creation into table by table * Debugged table creation Sql * Added missing CreateUserFriendsTable.sql --- OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs | 77 +++++- OpenSim/Framework/Data.MSSQL/MSSQLManager.cs | 250 ++++++------------ OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs | 31 ++- .../Resources/CreateUserFriendsTable.sql | 14 + .../Data.MSSQL/Resources/Mssql-regions.sql | 9 +- 5 files changed, 193 insertions(+), 188 deletions(-) create mode 100644 OpenSim/Framework/Data.MSSQL/Resources/CreateUserFriendsTable.sql diff --git a/OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs b/OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs index 0df88b63e1..36484373c1 100644 --- a/OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs +++ b/OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs @@ -38,7 +38,7 @@ namespace OpenSim.Framework.Data.MSSQL /// /// A grid data interface for Microsoft SQL Server /// - 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()); + IDbCommand cmd = database.Query("SELECT TOP 1 * FROM "+m_regionsTableName, new Dictionary()); 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 } } + + /// + /// Creates a new region in the database + /// + /// The region profile to insert + /// Successful? + 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 parameters = new Dictionary(); + + 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; + } + /// /// DEPRECIATED. Attempts to authenticate a region by comparing a shared secret. /// diff --git a/OpenSim/Framework/Data.MSSQL/MSSQLManager.cs b/OpenSim/Framework/Data.MSSQL/MSSQLManager.cs index 5c3e94fad1..26e8eb934f 100644 --- a/OpenSim/Framework/Data.MSSQL/MSSQLManager.cs +++ b/OpenSim/Framework/Data.MSSQL/MSSQLManager.cs @@ -40,7 +40,7 @@ namespace OpenSim.Framework.Data.MSSQL /// /// A management class for the MS SQL Storage Engine /// - internal class MSSQLManager + public class MSSQLManager { 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, 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=" + password + ";"; - dbcon = new SqlConnection(connectionString); - dbcon.Open(); - } - catch (Exception e) - { - throw new Exception("Error initialising Sql Database: " + e.ToString()); - } + dbcon = new SqlConnection(connectionString); + dbcon.Open(); } - 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) { @@ -149,19 +142,19 @@ namespace OpenSim.Framework.Data.MSSQL // slightly differently. private static string SqlType(Type type) { - if (type == typeof (String)) + if (type == typeof(String)) { return "varchar(255)"; } - else if (type == typeof (Int32)) + else if (type == typeof(Int32)) { return "integer"; } - else if (type == typeof (Double)) + else if (type == typeof(Double)) { return "float"; } - else if (type == typeof (Byte[])) + else if (type == typeof(Byte[])) { return "image"; } @@ -210,14 +203,14 @@ namespace OpenSim.Framework.Data.MSSQL /// A Sql DB Command public IDbCommand Query(string sql, Dictionary parameters) { - SqlCommand dbcommand = (SqlCommand) dbcon.CreateCommand(); + SqlCommand dbcommand = (SqlCommand)dbcon.CreateCommand(); dbcommand.CommandText = sql; foreach (KeyValuePair param in parameters) { dbcommand.Parameters.AddWithValue(param.Key, param.Value); } - return (IDbCommand) dbcommand; + return (IDbCommand)dbcommand; } /// @@ -233,20 +226,20 @@ namespace OpenSim.Framework.Data.MSSQL { // Region Main regionprofile.regionHandle = Convert.ToUInt64(reader["regionHandle"]); - regionprofile.regionName = (string) reader["regionName"]; - regionprofile.UUID = new LLUUID((string) reader["uuid"]); + regionprofile.regionName = (string)reader["regionName"]; + regionprofile.UUID = new LLUUID((string)reader["uuid"]); // Secrets - regionprofile.regionRecvKey = (string) reader["regionRecvKey"]; - regionprofile.regionSecret = (string) reader["regionSecret"]; - regionprofile.regionSendKey = (string) reader["regionSendKey"]; + regionprofile.regionRecvKey = (string)reader["regionRecvKey"]; + regionprofile.regionSecret = (string)reader["regionSecret"]; + regionprofile.regionSendKey = (string)reader["regionSendKey"]; // 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.serverIP = (string) reader["serverIP"]; + regionprofile.serverIP = (string)reader["serverIP"]; regionprofile.serverPort = Convert.ToUInt32(reader["serverPort"]); - regionprofile.serverURI = (string) reader["serverURI"]; + regionprofile.serverURI = (string)reader["serverURI"]; regionprofile.httpPort = Convert.ToUInt32(reader["serverHttpPort"]); regionprofile.remotingPort = Convert.ToUInt32(reader["serverRemotingPort"]); @@ -263,14 +256,14 @@ namespace OpenSim.Framework.Data.MSSQL regionprofile.regionNorthOverrideHandle = Convert.ToUInt64(reader["northOverrideHandle"]); // Assets - regionprofile.regionAssetURI = (string) reader["regionAssetURI"]; - regionprofile.regionAssetRecvKey = (string) reader["regionAssetRecvKey"]; - regionprofile.regionAssetSendKey = (string) reader["regionAssetSendKey"]; + regionprofile.regionAssetURI = (string)reader["regionAssetURI"]; + regionprofile.regionAssetRecvKey = (string)reader["regionAssetRecvKey"]; + regionprofile.regionAssetSendKey = (string)reader["regionAssetSendKey"]; // Userserver - regionprofile.regionUserURI = (string) reader["regionUserURI"]; - regionprofile.regionUserRecvKey = (string) reader["regionUserRecvKey"]; - regionprofile.regionUserSendKey = (string) reader["regionUserSendKey"]; + regionprofile.regionUserURI = (string)reader["regionUserURI"]; + regionprofile.regionUserRecvKey = (string)reader["regionUserRecvKey"]; + regionprofile.regionUserSendKey = (string)reader["regionUserSendKey"]; // World Map Addition string tempRegionMap = reader["regionMapTexture"].ToString(); @@ -302,12 +295,12 @@ namespace OpenSim.Framework.Data.MSSQL if (reader.Read()) { - retval.UUID = new LLUUID((string) reader["UUID"]); - retval.username = (string) reader["username"]; - retval.surname = (string) reader["lastname"]; + retval.UUID = new LLUUID((string)reader["UUID"]); + retval.username = (string)reader["username"]; + retval.surname = (string)reader["lastname"]; - retval.passwordHash = (string) reader["passwordHash"]; - retval.passwordSalt = (string) reader["passwordSalt"]; + retval.passwordHash = (string)reader["passwordHash"]; + retval.passwordSalt = (string)reader["passwordSalt"]; retval.homeRegion = Convert.ToUInt64(reader["homeRegion"].ToString()); retval.homeLocation = new LLVector3( @@ -322,17 +315,17 @@ namespace OpenSim.Framework.Data.MSSQL retval.created = Convert.ToInt32(reader["created"].ToString()); retval.lastLogin = Convert.ToInt32(reader["lastLogin"].ToString()); - retval.userInventoryURI = (string) reader["userInventoryURI"]; - retval.userAssetURI = (string) reader["userAssetURI"]; + retval.userInventoryURI = (string)reader["userInventoryURI"]; + retval.userAssetURI = (string)reader["userAssetURI"]; retval.profileCanDoMask = Convert.ToUInt32(reader["profileCanDoMask"].ToString()); retval.profileWantDoMask = Convert.ToUInt32(reader["profileWantDoMask"].ToString()); - retval.profileAboutText = (string) reader["profileAboutText"]; - retval.profileFirstText = (string) reader["profileFirstText"]; + retval.profileAboutText = (string)reader["profileAboutText"]; + retval.profileFirstText = (string)reader["profileFirstText"]; - retval.profileImage = new LLUUID((string) reader["profileImage"]); - retval.profileFirstImage = new LLUUID((string) reader["profileFirstImage"]); + retval.profileImage = new LLUUID((string)reader["profileImage"]); + retval.profileFirstImage = new LLUUID((string)reader["profileFirstImage"]); retval.webLoginKey = new LLUUID((string)reader["webLoginKey"]); } else @@ -354,12 +347,12 @@ namespace OpenSim.Framework.Data.MSSQL if (reader.Read()) { // Agent IDs - retval.UUID = new LLUUID((string) reader["UUID"]); - retval.sessionID = new LLUUID((string) reader["sessionID"]); - retval.secureSessionID = new LLUUID((string) reader["secureSessionID"]); + retval.UUID = new LLUUID((string)reader["UUID"]); + retval.sessionID = new LLUUID((string)reader["sessionID"]); + retval.secureSessionID = new LLUUID((string)reader["secureSessionID"]); // Agent Who? - retval.agentIP = (string) reader["agentIP"]; + retval.agentIP = (string)reader["agentIP"]; retval.agentPort = Convert.ToUInt32(reader["agentPort"].ToString()); retval.agentOnline = Convert.ToBoolean(reader["agentOnline"].ToString()); @@ -368,9 +361,9 @@ namespace OpenSim.Framework.Data.MSSQL retval.logoutTime = Convert.ToInt32(reader["logoutTime"].ToString()); // Current position - retval.currentRegion = (string) reader["currentRegion"]; + retval.currentRegion = (string)reader["currentRegion"]; retval.currentHandle = Convert.ToUInt64(reader["currentHandle"].ToString()); - LLVector3.TryParse((string) reader["currentPos"], out retval.currentPos); + LLVector3.TryParse((string)reader["currentPos"], out retval.currentPos); } else { @@ -387,12 +380,12 @@ namespace OpenSim.Framework.Data.MSSQL // Region Main asset = new AssetBase(); - asset.Data = (byte[]) reader["data"]; - asset.Description = (string) reader["description"]; - asset.FullID = new LLUUID((string) reader["id"]); + asset.Data = (byte[])reader["data"]; + asset.Description = (string)reader["description"]; + asset.FullID = new LLUUID((string)reader["id"]); asset.InvType = Convert.ToSByte(reader["invType"]); 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"]); } else @@ -402,76 +395,6 @@ namespace OpenSim.Framework.Data.MSSQL return asset; } - /// - /// Creates a new region in the database - /// - /// The region profile to insert - /// Successful? - 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 parameters = new Dictionary(); - - 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; - } - /// /// Inserts a new row into the log database @@ -617,21 +540,14 @@ namespace OpenSim.Framework.Data.MSSQL /// 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()); - } + SqlCommand cmd = new SqlCommand(getResourceString(name), (SqlConnection)dbcon); + cmd.ExecuteNonQuery(); + cmd.Dispose(); } public SqlConnection getConnection() { - return (SqlConnection) dbcon; + return (SqlConnection)dbcon; } /// @@ -652,7 +568,7 @@ namespace OpenSim.Framework.Data.MSSQL { try { - string tableName = (string) tables["TABLE_NAME"]; + string tableName = (string)tables["TABLE_NAME"]; if (tableList.ContainsKey(tableName)) tableList[tableName] = tableName; } diff --git a/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs b/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs index 95a0c08a11..56ad3fa91f 100644 --- a/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs +++ b/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs @@ -37,7 +37,7 @@ namespace OpenSim.Framework.Data.MSSQL /// /// A database interface class to a user profile storage system /// - internal class MSSQLUserData : IUserData + public class MSSQLUserData : IUserData { 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, 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()); + IDbCommand cmd; + + cmd = database.Query("select top 1 * from " + m_usersTableName, new Dictionary()); try { cmd.ExecuteNonQuery(); - cmd.Dispose(); } catch { - database.Query("alter table "+m_usersTableName+" add column [webLoginKey] varchar(36) default NULL", new Dictionary()); + database.ExecuteResourceSql("Mssql-users.sql"); + } + + cmd = database.Query("select top 1 * from " + m_agentsTableName, new Dictionary()); + try + { cmd.ExecuteNonQuery(); - cmd.Dispose(); + } + catch + { + database.ExecuteResourceSql("Mssql-agents.sql"); } - cmd = database.Query("select top 1 * from "+m_usersTableName, new Dictionary()); + cmd = database.Query("select top 1 * from " + m_userFriendsTableName, new Dictionary()); try { cmd.ExecuteNonQuery(); } catch { - return false; + database.ExecuteResourceSql("CreateUserFriendsTable.sql"); } return true; @@ -180,6 +184,7 @@ namespace OpenSim.Framework.Data.MSSQL "VALUES " + "(@ownerID,@friendID,@friendPerms,@datetimestamp)", param); + adder.ExecuteNonQuery(); adder = diff --git a/OpenSim/Framework/Data.MSSQL/Resources/CreateUserFriendsTable.sql b/OpenSim/Framework/Data.MSSQL/Resources/CreateUserFriendsTable.sql new file mode 100644 index 0000000000..9aebfa3efb --- /dev/null +++ b/OpenSim/Framework/Data.MSSQL/Resources/CreateUserFriendsTable.sql @@ -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 diff --git a/OpenSim/Framework/Data.MSSQL/Resources/Mssql-regions.sql b/OpenSim/Framework/Data.MSSQL/Resources/Mssql-regions.sql index b46da16caf..7875c5040f 100644 --- a/OpenSim/Framework/Data.MSSQL/Resources/Mssql-regions.sql +++ b/OpenSim/Framework/Data.MSSQL/Resources/Mssql-regions.sql @@ -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