From d4043c084a86da5f462356ec5c65eab2b861564d Mon Sep 17 00:00:00 2001 From: Chris Hart Date: Tue, 13 Sep 2011 16:55:30 -0400 Subject: [PATCH] MSSQL Bug fix in user account retrieval, plus migrations for FriendsStore and InventoryStore --- OpenSim/Data/MSSQL/MSSQLUserAccountData.cs | 18 +++++++---- .../MSSQL/Resources/FriendsStore.migrations | 28 ++++++++++++++++ .../MSSQL/Resources/InventoryStore.migrations | 32 +++++++++++++++++++ 3 files changed, 71 insertions(+), 7 deletions(-) diff --git a/OpenSim/Data/MSSQL/MSSQLUserAccountData.cs b/OpenSim/Data/MSSQL/MSSQLUserAccountData.cs index e7c8dc5a7e..7feec91eb9 100644 --- a/OpenSim/Data/MSSQL/MSSQLUserAccountData.cs +++ b/OpenSim/Data/MSSQL/MSSQLUserAccountData.cs @@ -218,23 +218,27 @@ namespace OpenSim.Data.MSSQL if (words.Length > 2) return new UserAccountData[0]; + string sql = ""; + using (SqlConnection conn = new SqlConnection(m_ConnectionString)) using (SqlCommand cmd = new SqlCommand()) { if (words.Length == 1) { - 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); + sql = 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); cmd.Parameters.Add(m_database.CreateParameter("@scopeID", scopeID)); - cmd.Parameters.Add(m_database.CreateParameter("@search", "%" + words[0] + "%")); + cmd.Parameters.Add(m_database.CreateParameter("@search", "%" + words[0] + "%")); } else { - 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())); + sql = 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())); } - + cmd.Connection = conn; + cmd.CommandText = sql; + conn.Open(); return DoQuery(cmd); } } diff --git a/OpenSim/Data/MSSQL/Resources/FriendsStore.migrations b/OpenSim/Data/MSSQL/Resources/FriendsStore.migrations index 4d8ab0f622..cc94c4e8cf 100644 --- a/OpenSim/Data/MSSQL/Resources/FriendsStore.migrations +++ b/OpenSim/Data/MSSQL/Resources/FriendsStore.migrations @@ -19,4 +19,32 @@ IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[userf INSERT INTO Friends (PrincipalID, Friend, Flags, Offered) SELECT [ownerID], [friendID], [friendPerms], 0 FROM userfriends; +COMMIT + +:VERSION 3 + +BEGIN TRANSACTION + +CREATE TABLE [Tmp_Friends] + ([PrincipalID] varchar(255) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', +[Friend] varchar(255) NOT NULL, +[Flags] char(16) NOT NULL DEFAULT '0', +[Offered] varchar(32) NOT NULL DEFAULT 0) +ON [PRIMARY] + + +IF EXISTS(SELECT * FROM dbo.Friends) + EXEC('INSERT INTO dbo.Tmp_Friends (PrincipalID, Friend, Flags, Offered) + SELECT CONVERT(varchar(255),PrincipalID), Friend, Flags, Offered FROM dbo.Friends WITH (HOLDLOCK TABLOCKX)') + +DROP TABLE dbo.Friends + +EXECUTE sp_rename N'dbo.Tmp_Friends', N'Friends', 'OBJECT' + +ALTER TABLE dbo.Friends ADD + PRIMARY KEY CLUSTERED +( + [PrincipalID] ASC, [Friend] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] + COMMIT \ No newline at end of file diff --git a/OpenSim/Data/MSSQL/Resources/InventoryStore.migrations b/OpenSim/Data/MSSQL/Resources/InventoryStore.migrations index 4a3cb27312..4e436534fd 100644 --- a/OpenSim/Data/MSSQL/Resources/InventoryStore.migrations +++ b/OpenSim/Data/MSSQL/Resources/InventoryStore.migrations @@ -244,4 +244,36 @@ ALTER TABLE inventoryitems ADD CONSTRAINT DF_inventoryitems_creatorID DEFAULT '00000000-0000-0000-0000-000000000000' FOR creatorID +:GO + +:VERSION 9 + +BEGIN TRANSACTION + +# CreatorID goes up to VARCHAR(255) + +exec sp_rename 'inventoryitems.CreatorID', 'cr_old', 'COLUMN' + +:GO + +alter table inventoryitems + add creatorID varchar(255) NULL + +:GO + +update inventoryitems set creatorID = cr_old + +alter table inventoryitems +drop CONSTRAINT DF_inventoryitems_creatorID +:GO + +alter table inventoryitems + drop column cr_old + :GO +COMMIT + +ALTER TABLE inventoryitems +ADD CONSTRAINT DF_inventoryitems_creatorID +DEFAULT '00000000-0000-0000-0000-000000000000' FOR creatorID + :GO \ No newline at end of file