diff --git a/PROMS/DataLoader/PROMSFixes.Sql b/PROMS/DataLoader/PROMSFixes.Sql index 77084393..e6d6af1a 100644 --- a/PROMS/DataLoader/PROMSFixes.Sql +++ b/PROMS/DataLoader/PROMSFixes.Sql @@ -1,6 +1,6 @@ - if db_name() in('master','model','msdn','tempdb') +If (db_name() in('master','model','msdn','tempdb')) begin DECLARE @ErrorMsg varchar(255) SET @ErrorMsg = 'Don''t add these procedures and functions to ' + db_name() @@ -16,6 +16,8 @@ begin end print 'Adding procedures and functions to ' + db_name() + + IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[PasteItemReplace]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) DROP PROCEDURE [PasteItemReplace]; GO @@ -17387,16 +17389,6 @@ ELSE PRINT 'Index Creation:[IX_tblTransitionsDeleteStatusTransitionID] Error on GO - - --- Rebuild / Reorganize All Indexes -exec [dbo].[vesp_UtilityCheckIndexes]; - - -IF (@@Error = 0) PRINT 'Running vesp_UtilityCheckIndexes Succeeded' -ELSE PRINT 'Running vesp_UtilityCheckIndexes Failed to Execute' -GO - IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getGridIds]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) DROP PROCEDURE [getGridIds]; GO @@ -17419,6 +17411,2646 @@ ELSE PRINT 'Procedure Creation: [getGridIds] Error on Creation' GO + +/* +========================================================================================================== + Begin: B2022-026 RO Memory reduction coding (Jakes Merge) [Version 2.0] + Notes** If you need to rollback to the previous version for some reason and undo the changes + for v2.0 then run the corresponding "PROMSRollback (v2.0).sql" file +========================================================================================================== +*/ + /* + ---------------------------------------------------------------------------------- + Tables: + ---------------------------------------------------------------------------------- + [RofstHeader] + [RofstDatabase] + [RofstChild] + [RofstDefaultValue] + + ---------------------------------------------------------------------------------- + Indexes: + ---------------------------------------------------------------------------------- + [IX_RofstID_Roid] on [dbo].[RofstChild] + [IX_RofstID_DbiID_ParentID] on [dbo].[RofstChild] + + */ + + -- If RofstHeader and other tables already exist then don't drop and recreate them + IF Not Exists(SELECT * FROM sys.objects Where name = 'RofstHeader' AND type in (N'U')) + Begin -- Rofst Tables + + SET ANSI_NULLS ON + SET QUOTED_IDENTIFIER ON + + /****** Object: Table [dbo].[RofstChild] Script Date: 6/6/2022 11:18:32 AM ******/ + CREATE TABLE [dbo].[RofstChild]( + [RofstChildID] [int] IDENTITY(1,1) NOT NULL, + [RofstID] [int] NOT NULL, + [dbiID] [int] NOT NULL, + [ID] [int] NOT NULL, + [ParentID] [int] NOT NULL, + [type] [int] NOT NULL, + [title] [varchar](max) NOT NULL, + [roid] [varchar](50) NOT NULL, + [appid] [varchar](max) NULL, + [value] [varchar](max) NULL, + CONSTRAINT [PK_RofstChild] PRIMARY KEY CLUSTERED + ( + [RofstChildID] ASC + )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] + ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] + + IF (@@Error = 0) PRINT 'Table Creation: [RofstChild] Succeeded' + ELSE PRINT 'Table Creation: [RofstChild] Error on Creation' + + + /****** Object: Table [dbo].[RofstDatabase] Script Date: 6/6/2022 11:18:32 AM ******/ + CREATE TABLE [dbo].[RofstDatabase]( + [RofstID] [int] NOT NULL, + [dbiID] [int] NOT NULL, + [dbiType] [int] NOT NULL, + [dbiAW] [int] NOT NULL, + [dbiTitle] [varchar](max) NOT NULL, + [dbiAP] [varchar](max) NOT NULL, + [ID] [int] NOT NULL, + [ParentID] [int] NOT NULL, + CONSTRAINT [PK_RofstDatabase_1] PRIMARY KEY CLUSTERED + ( + [RofstID] ASC, + [dbiID] ASC + )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] + ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] + + IF (@@Error = 0) PRINT 'Table Creation: [RofstDatabase] Succeeded' + ELSE PRINT 'Table Creation: [RofstDatabase] Error on Creation' + + + /****** Object: Table [dbo].[RofstDefaultValue] Script Date: 6/6/2022 11:18:32 AM ******/ + CREATE TABLE [dbo].[RofstDefaultValue]( + [RofstID] [int] NOT NULL, + [roid] [varchar](50) NOT NULL, + [value] [varchar](max) NOT NULL, + [AccPageID] [varchar](max) NULL, + CONSTRAINT [PK_RofstDefaultValue] PRIMARY KEY CLUSTERED + ( + [RofstID] ASC, + [roid] ASC + )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] + ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] + + IF (@@Error = 0) PRINT 'Table Creation: [RofstDefaultValue] Succeeded' + ELSE PRINT 'Table Creation: [RofstDefaultValue] Error on Creation' + + + /****** Object: Table [dbo].[RofstHeader] Script Date: 6/6/2022 11:18:32 AM ******/ + CREATE TABLE [dbo].[RofstHeader]( + [RofstID] [int] NOT NULL, + [hSize] [int] NOT NULL, + [hMonth] [int] NOT NULL, + [hDay] [int] NOT NULL, + [hcYear] [int] NOT NULL, + [hcMonth] [int] NOT NULL, + [hcDay] [int] NOT NULL, + [hcHour] [int] NOT NULL, + [hcMin] [int] NOT NULL, + [hcSec] [int] NOT NULL, + [hcHund] [int] NOT NULL, + [CreateUserID] [varchar](50) NOT NULL, + [CreateDate] [datetime] NOT NULL, + [LoadedDate] [datetime] NULL, + CONSTRAINT [PK_RofstHeader] PRIMARY KEY CLUSTERED + ( + [RofstID] ASC + )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] + ) ON [PRIMARY] + + IF (@@Error = 0) PRINT 'Table Creation: [RofstHeader] Succeeded' + ELSE PRINT 'Table Creation: [RofstHeader] Error on Creation' + + + /****** Object: Index [IX_RofstID_DbiID_ParentID] Script Date: 6/6/2022 11:18:32 AM ******/ + CREATE NONCLUSTERED INDEX [IX_RofstID_DbiID_ParentID] ON [dbo].[RofstChild] + ( + [RofstID] ASC, + [dbiID] ASC, + [ParentID] ASC + ) + INCLUDE([ID],[type],[title],[roid],[appid],[value]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] + + IF (@@Error = 0) PRINT 'Index Creation: [IX_RofstID_DbiID_ParentID] Succeeded' + ELSE PRINT 'Index Creation: [IX_RofstID_DbiID_ParentID] Error on Creation' + + + /****** Object: Index [IX_RofstID_Roid] Script Date: 6/6/2022 11:18:32 AM ******/ + CREATE NONCLUSTERED INDEX [IX_RofstID_Roid] ON [dbo].[RofstChild] + ( + [RofstID] ASC, + [roid] ASC + )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] + + IF (@@Error = 0) PRINT 'Index Creation: [IX_RofstID_Roid] Succeeded' + ELSE PRINT 'Index Creation: [IX_RofstID_Roid] Error on Creation' + + + ALTER TABLE [dbo].[RofstDatabase] ADD CONSTRAINT [DF_RofstDatabase_ParentID] DEFAULT ((0)) FOR [ParentID] + + ALTER TABLE [dbo].[RofstHeader] ADD CONSTRAINT [DF_RofstHeader_CreateUserID] DEFAULT ('SYSTEM') FOR [CreateUserID] + + ALTER TABLE [dbo].[RofstHeader] ADD CONSTRAINT [DF_RofstHeader_CreateDate] DEFAULT (getdate()) FOR [CreateDate] + + ALTER TABLE [dbo].[RofstChild] WITH CHECK ADD CONSTRAINT [FK_RofstChild_RofstDatabase] FOREIGN KEY([RofstID], [dbiID]) + REFERENCES [dbo].[RofstDatabase] ([RofstID], [dbiID]) + ON DELETE CASCADE + + ALTER TABLE [dbo].[RofstChild] CHECK CONSTRAINT [FK_RofstChild_RofstDatabase] + + ALTER TABLE [dbo].[RofstDatabase] WITH CHECK ADD CONSTRAINT [FK_RofstDatabase_RofstHeader] FOREIGN KEY([RofstID]) + REFERENCES [dbo].[RofstHeader] ([RofstID]) + ON DELETE CASCADE + + ALTER TABLE [dbo].[RofstDatabase] CHECK CONSTRAINT [FK_RofstDatabase_RofstHeader] + + ALTER TABLE [dbo].[RofstDefaultValue] WITH CHECK ADD CONSTRAINT [FK_RofstDefaultValue_RofstHeader] FOREIGN KEY([RofstID]) + REFERENCES [dbo].[RofstHeader] ([RofstID]) + ON DELETE CASCADE + + ALTER TABLE [dbo].[RofstDefaultValue] CHECK CONSTRAINT [FK_RofstDefaultValue_RofstHeader] + + ALTER TABLE [dbo].[RofstHeader] WITH CHECK ADD CONSTRAINT [FK_RofstHeader_ROFsts] FOREIGN KEY([RofstID]) + REFERENCES [dbo].[ROFsts] ([ROFstID]) + ON DELETE CASCADE + + ALTER TABLE [dbo].[RofstHeader] CHECK CONSTRAINT [FK_RofstHeader_ROFsts] + + IF (@@Error = 0) PRINT 'Table/FK Constraints: Succeeded' + ELSE PRINT 'Table/FK Constraints: Error on Creation' + + End -- Rofst Tables + Go + + + /* + ---------------------------------------------------------------------------------- + Functions: + ---------------------------------------------------------------------------------- + [dbo].[vefn_Clean] + [dbo].[vefn_ParseStringListToTable] + [dbo].[vefn_NumOfOccurrences] + [dbo].[vefn_RofstDataReplaceVars] + [dbo].[vefn_RofstDataReplaceApplTagsWithDefaults] + [dbo].[vefn_RofstDataGetLoadStatus] + */ + + /****** Object: UserDefinedFunction [dbo].[vefn_Clean] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vefn_Clean' AND type in (N'FN')) + DROP FUNCTION [dbo].[vefn_Clean] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + -- ========================================================================================== + -- Author: Jake Ropar + -- Create Date: 4/21/2022 + -- Description: Cleans (Trim) the string value passed + -- Optional: Truncate is string is passed a specified max length + -- Optional: Convert any null values to an empty string or leave as null + -- ========================================================================================== + + Create Function [dbo].[vefn_Clean] ( @Value VarChar(Max), @ConvertNulls bit = 0, @MaxLength Int = null ) + Returns VarChar(Max) + As + Begin + + Declare @RetVal VarChar(Max); + + If (Len(IsNull(@Value,'')) > 0) + Begin + + Set @RetVal = LTrim(RTrim(@Value)); + If (Not @MaxLength is null And Len(@RetVal) > @MaxLength) Set @RetVal = Left(@RetVal, @MaxLength); + + End + + If (@ConvertNulls = 1) + Set @RetVal = IsNull(@RetVal, ''); + + Return @RetVal; + + End + GO + + IF (@@Error = 0) PRINT 'Function Creation: [vefn_Clean] Succeeded' + ELSE PRINT 'Function Creation: [vefn_Clean] Error on Creation' + GO + + + + /****** Object: UserDefinedFunction [dbo].[vefn_ParseStringListToTable] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vefn_ParseStringListToTable' AND type in (N'TF')) + DROP FUNCTION [dbo].[vefn_ParseStringListToTable] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + -- ========================================================================================== + -- Author: Jake Ropar + -- Create Date: 3/26/2018 + -- Description: Splits a delimited list of strings into a table of string values + -- ========================================================================================== + + Create Function [dbo].[vefn_ParseStringListToTable] ( @List VarChar(Max), @Delimeter VarChar(1) = null ) + Returns @RetVal Table (ListPosition Int Identity(1,1) Not Null, ListValue VarChar(Max) Not Null) + With Execute As Owner + As + Begin + + Declare @Position Int; + Declare @TextPosition Int; + Declare @Length smallint; + Declare @String VarChar(Max); + Declare @TempString VarChar(Max); + Declare @LeftOver VarChar(Max); + + Set @TextPosition = 1; + Set @LeftOver = ''; + Set @Delimeter = IsNull(@Delimeter, ','); + + If (DataLength(@List) = 1) + Insert @RetVal (ListValue) Values (Cast(@List as VarChar(Max))); + Else + Begin + While (@TextPosition <= DataLength(@List) / 2) + Begin + + Set @Length = (4000 - DataLength(@LeftOver) / 2); + Set @TempString = LTrim(@LeftOver + Substring(@List, @TextPosition, @Length)); + Set @TextPosition = @TextPosition + @Length; + Set @Position = CharIndex(@Delimeter, @TempString); + + While (@Position > 0) + Begin + + Set @String = Substring(@TempString, 1, @Position - 1); + + Insert @RetVal (ListValue) Values (Cast(@String as VarChar(Max))); + + Set @TempString = LTrim(Substring(@TempString, @Position + 1, Len(@TempString))); + Set @Position = CharIndex(@Delimeter, @TempString); + + End + + Set @LeftOver = @TempString; + End + End + + If (LTrim(RTrim(@LeftOver)) <> '') + Insert @RetVal (ListValue) Values (Cast(@LeftOver as VarChar(Max))); + + Return; + End + GO + + IF (@@Error = 0) PRINT 'Function Creation: [vefn_ParseStringListToTable] Succeeded' + ELSE PRINT 'Function Creation: [vefn_ParseStringListToTable] Error on Creation' + GO + + + + /****** Object: UserDefinedFunction [dbo].[vefn_NumOfOccurrences] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vefn_NumOfOccurrences' AND type in (N'FN')) + DROP FUNCTION [dbo].[vefn_NumOfOccurrences] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + -- ========================================================================================== + -- Author: Jake Ropar + -- Create Date: 3/1/2022 + -- Description: Returns the number of occurences of a specific value in a specified string + -- ========================================================================================== + + CREATE FUNCTION [dbo].[vefn_NumOfOccurrences](@Text VarChar(Max), @Value VarChar(Max)) Returns Int + WITH EXECUTE AS OWNER + AS + BEGIN + + Declare @ValueCount Int; + + If (Len(@Value) = 0) + Set @ValueCount = 0; + Else + Set @ValueCount = (Len(@Text) - Len(Replace(@Text, @Value, ''))) / Len(@Value); + + Return @ValueCount; + + END + GO + + IF (@@Error = 0) PRINT 'Function Creation: [vefn_NumOfOccurrences] Succeeded' + ELSE PRINT 'Function Creation: [vefn_NumOfOccurrences] Error on Creation' + GO + + + + /****** Object: UserDefinedFunction [dbo].[vefn_RofstDataReplaceVars] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vefn_RofstDataReplaceVars' AND type in (N'FN')) + DROP FUNCTION [dbo].[vefn_RofstDataReplaceVars] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + -- ========================================================================================== + -- Author: Jake Ropar + -- Create Date: 3/25/2022 + -- Description: Replaces Any Variables and returns the rest of the value string + -- ========================================================================================== + + CREATE FUNCTION [dbo].[vefn_RofstDataReplaceVars](@Values VarChar(Max)) Returns VarChar(Max) + WITH EXECUTE AS OWNER + AS + BEGIN + + Declare @RetVal VarChar(Max) = ''; + Declare @EqualsIndex Int; + Declare @EndIndex Int; + Declare @NameValPairStartIndex Int; + Declare @NameValPairEndIndex Int; + + Declare @VarPair VarChar(Max); + Declare @VarName VarChar(Max); + Declare @VarValue VarChar(Max); + + -- Replace Any "" Tags with the Default Value first + Select @RetVal = dbo.vefn_RofstDataReplaceApplTagsWithDefaults(@Values); + + If (PatIndex('%{{A%', @RetVal) > 0) + Set @EndIndex = PatIndex('%{{A%', @RetVal); + Else + Set @EndIndex = Len(@RetVal) -1; + + Set @NameValPairStartIndex = PatIndex('%{%', @RetVal); + Set @NameValPairEndIndex = PatIndex('%}%', @RetVal); + + While(@NameValPairStartIndex > 0 And @NameValPairStartIndex < @EndIndex) + Begin + + -- Get Name Value Pair [ex. {EGS=1214}] + Set @VarPair = SubString(@RetVal, @NameValPairStartIndex, (@NameValPairEndIndex - @NameValPairStartIndex) + 1); + + -- Remove Name Value Pair From Return Val + Set @RetVal = Replace(@RetVal, @VarPair, ''); + + -- Get Variable Name and Value + Set @EqualsIndex = PatIndex('%=%', @VarPair); + + If (@EqualsIndex > 0) + Begin + Set @VarName = SubString(@VarPair, 2, @EqualsIndex - 2); + Set @VarValue = SubString(@VarPair, @EqualsIndex + 1, Len(@VarPair) - @EqualsIndex - 1); + Set @VarName = Concat('{', @VarName, '}'); + + -- Replace All Occurences + Set @RetVal = Replace(@RetVal, @VarName, @VarValue); + End + + -- Get Updated Index Values + If (PatIndex('%{{A%', @RetVal) > 0) + Set @EndIndex = PatIndex('%{{A%', @RetVal); + Else + Set @EndIndex = Len(@RetVal) -1; + + Set @NameValPairStartIndex = PatIndex('%{%', @RetVal); + Set @NameValPairEndIndex = PatIndex('%}%', @RetVal); + + End -- End While(@ReplaceVarEndTagIndex > 0) + + Return @RetVal; + + END + GO + + IF (@@Error = 0) PRINT 'Function Creation: [vefn_RofstDataReplaceVars] Succeeded' + ELSE PRINT 'Function Creation: [vefn_RofstDataReplaceVars] Error on Creation' + GO + + + + /****** Object: UserDefinedFunction [dbo].[vefn_RofstDataReplaceApplTagsWithDefaults] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vefn_RofstDataReplaceApplTagsWithDefaults' AND type in (N'FN')) + DROP FUNCTION [dbo].[vefn_RofstDataReplaceApplTagsWithDefaults] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + -- ========================================================================================== + -- Author: Jake Ropar + -- Create Date: 3/25/2022 + -- Description: Replaces any "" tags with the default value + -- ========================================================================================== + + CREATE FUNCTION [dbo].[vefn_RofstDataReplaceApplTagsWithDefaults](@Values VarChar(Max)) Returns VarChar(Max) + WITH EXECUTE AS OWNER + AS + BEGIN + + Declare @RetVal VarChar(Max) = ''; + Declare @DefaultValue VarChar(Max) = ''; + + Declare @StartTagIndex Int; + Declare @EndTagIndex Int; + Declare @StartTagValue VarChar(Max); + + Set @RetVal = @Values; + Set @StartTagIndex = PatIndex('%%', @RetVal); + + While (@StartTagIndex > 0) + Begin + + Set @StartTagValue = SubString(@RetVal, @StartTagIndex, (@EndTagIndex - @StartTagIndex) + 5); + Set @DefaultValue = Replace(@StartTagValue, '%', @DefaultValue); + + Set @DefaultValue = RTrim(SubString(@DefaultValue, 0, @EndTagIndex)); + Set @RetVal = Replace(@RetVal, @StartTagValue, @DefaultValue); + + Set @StartTagIndex = PatIndex('%%', @RetVal); + + End -- While (@StartTagIndex > 0) + + Return @RetVal; + + END + GO + + IF (@@Error = 0) PRINT 'Function Creation: [vefn_RofstDataReplaceApplTagsWithDefaults] Succeeded' + ELSE PRINT 'Function Creation: [vefn_RofstDataReplaceApplTagsWithDefaults] Error on Creation' + GO + + + + + /****** Object: UserDefinedFunction [dbo].[vefn_RofstDataGetLoadStatus] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vefn_RofstDataGetLoadStatus' AND type in (N'FN')) + DROP FUNCTION [dbo].[vefn_RofstDataGetLoadStatus] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + -- ========================================================================================== + -- Author: Jake Ropar + -- Create Date: 05/20/2022 + -- Description: Gets the current load status for a Rofst Binary + -- ========================================================================================== + + CREATE FUNCTION [dbo].[vefn_RofstDataGetLoadStatus](@RofstID Int) Returns Int + WITH EXECUTE AS OWNER + AS + BEGIN + + Declare @RofstHeaderStatusID Int; + Declare @NumOfRecordsStart Int; + Declare @NumOfRecordsEnd Int; + Declare @CreateDate DateTime; + Declare @LoadedDate DateTime; + + -- Set Default Values + Set @RofstHeaderStatusID = 0; -- [Unknown] + Set @NumOfRecordsStart = -1; + Set @NumOfRecordsEnd = -1; + + -- Get RofstHeader Data + Select @CreateDate = CreateDate, @LoadedDate = LoadedDate + From RofstHeader with (NoLock) + Where RofstID = @RofstID; + + -- Check Current Status of RofstHeader/Data + If (@CreateDate is null) + Begin + Set @RofstHeaderStatusID = 1; -- [Not Loaded] + End + Else If (Not @LoadedDate is null) + Begin + Set @RofstHeaderStatusID = 3; -- [Load Complete] + End + Else If (@LoadedDate is null) + Begin + + -- Check if the record count for Rofst Default Values is still increasing + --Declare @cnt Int = 4000000; + Declare @cnt Int = 2000000; + + Select @NumOfRecordsStart = Count(1) From vwRofstData_RofstDefaultValues Where RofstID = @RofstID; + + While (@cnt > 0) + Set @cnt = @Cnt -1; + + Select @NumOfRecordsEnd = Count(1) From vwRofstData_RofstDefaultValues Where RofstID = @RofstID; + + If (@NumOfRecordsStart < @NumOfRecordsEnd) + Set @RofstHeaderStatusID = 2; -- [In Progress] + Else + Set @RofstHeaderStatusID = 4; -- [Load Failed] + End + Else + Begin + Set @RofstHeaderStatusID = 0; -- [Unknown] + End + + + Return @RofstHeaderStatusID; + + END + GO + + IF (@@Error = 0) PRINT 'Function Creation: [vefn_RofstDataGetLoadStatus] Succeeded' + ELSE PRINT 'Function Creation: [vefn_RofstDataGetLoadStatus] Error on Creation' + GO + + + /* + ---------------------------------------------------------------------------------- + Views: + ---------------------------------------------------------------------------------- + [dbo].[vwRofstData_RofstChildren] + [dbo].[vwRofstData_RofstDatabases] + [dbo].[vwRofstData_RofstDefaultValues] + [dbo].[vwRofstData_RofstHeaders] + [dbo].[vwRofstData_RofstHeaderStatuses] + */ + + /****** Object: View [dbo].[vwRofstData_RofstChildren] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vwRofstData_RofstChildren' AND type in (N'V')) + DROP VIEW [dbo].[vwRofstData_RofstChildren] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 03/24/2024 + Description: (RofstData) Master View for RofstChildren (RoChild & Groups) + ========================================================================================================== + */ + Create View [dbo].[vwRofstData_RofstChildren] + As + + Select rc.RofstChildID as 'RofstChildID', + rd.RofstID as 'RofstID', + -- RoDatabase Info + rd.dbiID as 'dbiID', + rd.dbiType as 'dbiType', + rd.dbiAW as 'dbiAW', + rd.dbiTitle as 'dbiTitle', + rd.dbiAP as 'dbiAP', + -- RoChild Info + rc.ID as 'ID', + rc.ParentID as 'ParentID', + rc.[type] as 'type', + Case When (rc.[type] = 1) Then 'Single Line Text' -- Fixed Length Text + When (rc.[type] = 2) Then 'Table' + When (rc.[type] = 3) Then 'Multiple Line Text' + When (rc.[type] = 4) Then 'X/Y Plot' + When (rc.[type] = 8) Then 'Image' + Else 'Unknown' End as 'TypeDescription', + rc.title as 'title', + rc.roid as 'roid', + rc.appid as 'appid', + rc.[value] as 'value', + Case When (Not rc.[value] is null) Then rd.dbiAP + '-' + rc.appid Else null End as 'AccPageID' + From RofstChild rc With (NoLock) + inner join RofstDatabase rd With (NoLock) on rc.RofstID = rd.RofstID and rc.dbiID = rd.dbiID; + + GO + + IF (@@Error = 0) PRINT 'View Creation: [vwRofstData_RofstChildren] Succeeded' + ELSE PRINT 'View Creation: [vwRofstData_RofstChildren] Error on Creation' + GO + + + /****** Object: View [dbo].[vwRofstData_RofstDatabases] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vwRofstData_RofstDatabases' AND type in (N'V')) + DROP VIEW [dbo].[vwRofstData_RofstDatabases] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 03/24/2024 + Description: (RofstData) Master View for RofstDatabases + ========================================================================================================== + */ + Create View [dbo].[vwRofstData_RofstDatabases] + As + + Select rd.RofstID as 'RofstID', + rd.dbiID as 'dbiID', + rd.dbiType as 'dbiType', + rd.dbiAW as 'dbiAW', + rd.dbiTitle as 'dbiTitle', + rd.dbiAP as 'dbiAP', + rd.ID as 'ID', + rd.ParentID as 'ParentID' + From RofstDatabase rd With (NoLock) + + + GO + + IF (@@Error = 0) PRINT 'View Creation: [vwRofstData_RofstDatabases] Succeeded' + ELSE PRINT 'View Creation: [vwRofstData_RofstDatabases] Error on Creation' + GO + + + /****** Object: View [dbo].[vwRofstData_RofstDefaultValues] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vwRofstData_RofstDefaultValues' AND type in (N'V')) + DROP VIEW [dbo].[vwRofstData_RofstDefaultValues] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 03/24/2024 + Description: (RofstData) Master View for Rofst Roid Default Values + ========================================================================================================== + */ + Create View [dbo].[vwRofstData_RofstDefaultValues] + As + + Select rdv.RofstID as 'RofstID', + rdv.roid as 'roid', + rdv.[value] as 'value', + rdv.AccPageID as 'AccPageID' + From RofstDefaultValue rdv With (NoLock) + + GO + + IF (@@Error = 0) PRINT 'View Creation: [vwRofstData_RofstDefaultValues] Succeeded' + ELSE PRINT 'View Creation: [vwRofstData_RofstDefaultValues] Error on Creation' + GO + + + /****** Object: View [dbo].[vwRofstData_RofstHeaders] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vwRofstData_RofstHeaders' AND type in (N'V')) + DROP VIEW [dbo].[vwRofstData_RofstHeaders] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 03/24/2024 + Description: (RofstData) Master View for RofstHeaders + ========================================================================================================== + */ + Create View [dbo].[vwRofstData_RofstHeaders] + As + + Select rh.RofstID as 'RofstID', + hs.RofstHeaderStatusID as 'RofstHeaderStatusID', + hs.RofstHeaderStatus as 'RofstHeaderStatus', + rh.hSize as 'hSize', + rh.hMonth as 'hMonth', + rh.hDay as 'hDay', + rh.hcYear as 'hcYear', + rh.hcMonth as 'hcMonth', + rh.hcDay as 'hcDay', + rh.hcHour as 'hcHour', + rh.hcMin as 'hcMin', + rh.hcSec as 'hcSec', + rh.hcHund as 'hcHund', + rh.LoadedDate as 'LoadedDate', + rh.CreateUserID as 'CreateUserID', + rh.CreateDate as 'CreateDate' + From RofstHeader rh With (NoLock) + inner join vwRofstData_RofstHeaderStatuses hs on hs.RofstHeaderStatusID = dbo.vefn_RofstDataGetLoadStatus(rh.RofstID) + + GO + + IF (@@Error = 0) PRINT 'View Creation: [vwRofstData_RofstHeaders] Succeeded' + ELSE PRINT 'View Creation: [vwRofstData_RofstHeaders] Error on Creation' + GO + + + /****** Object: View [dbo].[vwRofstData_RofstHeaderStatuses] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vwRofstData_RofstHeaderStatuses' AND type in (N'V')) + DROP VIEW [dbo].[vwRofstData_RofstHeaderStatuses] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 05/20/2022 + Description: (RofstData) Master View for RofstHeader Statuses + (0) Unknown (1) Not Loaded (2) In Progress (3) Load Complete (4) Load Failed + ========================================================================================================== + */ + Create View [dbo].[vwRofstData_RofstHeaderStatuses] + As + + Select '0' as 'RofstHeaderStatusID', 'Unknown' as 'RofstHeaderStatus' + Union All + Select '1' as 'RofstHeaderStatusID', 'Not Loaded' as 'RofstHeaderStatus' + Union All + Select '2' as 'RofstHeaderStatusID', 'In Progress' as 'RofstHeaderStatus' + Union All + Select '3' as 'RofstHeaderStatusID', 'Load Complete' as 'RofstHeaderStatus' + Union All + Select '4' as 'RofstHeaderStatusID', 'Load Failed' as 'RofstHeaderStatus' + + GO + + IF (@@Error = 0) PRINT 'View Creation: [vwRofstData_RofstHeaderStatuses] Succeeded' + ELSE PRINT 'View Creation: [vwRofstData_RofstHeaderStatuses] Error on Creation' + GO + + + + + /* + ---------------------------------------------------------------------------------- + Stored Procs: (Update Existing) + ---------------------------------------------------------------------------------- + [dbo].[updateROFst] + [dbo].[getROImage] + [dbo].[getROFstsByRODbID] + [dbo].[getROFsts] + [dbo].[getRoFstBySize] + [dbo].[getROFstByRODbID_DTS] + [dbo].[getROFst] + [dbo].[getRODb] + [dbo].[getJustROFst] + [dbo].[getFiguresByImageID] + [dbo].[getDocVersion] + */ + + + /****** Object: StoredProcedure [dbo].[updateROFst] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'updateROFst' AND type in (N'P')) + DROP PROCEDURE [dbo].[updateROFst] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: + Create Date: + Description: + ========================================================================================================== + */ + CREATE PROCEDURE [dbo].[updateROFst] + ( + @ROFstID int, + @RODbID int, + @ROLookup varbinary(MAX), + @Config nvarchar(MAX)=null, + @DTS datetime, + @UserID nvarchar(100), + @LastChanged timestamp, + @newLastChanged timestamp output + ) + WITH EXECUTE AS OWNER + AS + BEGIN TRY -- Try Block + BEGIN TRANSACTION + UPDATE [ROFsts] + SET + [RODbID]=@RODbID, + --[ROLookup]=@ROLookup, + [Config]=@Config, + [DTS]=@DTS, + [UserID]=@UserID + WHERE [ROFstID]=@ROFstID AND [LastChanged]=@LastChanged + IF @@ROWCOUNT = 0 + BEGIN + IF NOT exists(select * from [ROFsts] WHERE [ROFstID]=@ROFstID) + RAISERROR('ROFst record has been deleted by another user', 16, 1) + ELSE + RAISERROR('ROFst has been edited by another user', 16, 1) + END + + SELECT @newLastChanged=[LastChanged] + FROM [ROFsts] WHERE [ROFstID]=@ROFstID + + IF( @@TRANCOUNT > 0 ) COMMIT + END TRY + BEGIN CATCH -- Catch Block + IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level + ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback + EXEC vlnErrorHandler + END CATCH + + GO + + IF (@@Error = 0) PRINT 'Procedure Creation: [updateROFst] Succeeded' + ELSE PRINT 'Procedure Creation: [updateROFst] Error on Creation' + GO + + + + + /****** Object: StoredProcedure [dbo].[getROImage] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'getROImage' AND type in (N'P')) + DROP PROCEDURE [dbo].[getROImage] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: + Create Date: + Description: + ========================================================================================================== + */ + CREATE PROCEDURE [dbo].[getROImage] + ( + @ImageID int + ) + WITH EXECUTE AS OWNER + AS + SELECT + [ImageID], + [RODbID], + [FileName], + [Content], + [Config], + [DTS], + [UserID], + [LastChanged], + (SELECT COUNT(1) FROM [Figures] WHERE [Figures].[ImageID]=[ROImages].[ImageID]) [FigureCount] + FROM [ROImages] + WHERE [ImageID]=@ImageID + + SELECT + [Figures].[FigureID], + [Figures].[ROFstID], + [Figures].[ImageID], + [Figures].[Config], + [Figures].[DTS], + [Figures].[UserID], + [Figures].[LastChanged], + [ROFsts].[RODbID] [ROFst_RODbID], + --[ROFsts].[ROLookup] [ROFst_ROLookup], + null as [ROFst_ROLookup], + [ROFsts].[Config] [ROFst_Config], + [ROFsts].[DTS] [ROFst_DTS], + [ROFsts].[UserID] [ROFst_UserID] + FROM [Figures] + JOIN [ROFsts] ON + [ROFsts].[ROFstID]=[Figures].[ROFstID] + WHERE + [Figures].[ImageID]=@ImageID + + RETURN + GO + + IF (@@Error = 0) PRINT 'Procedure Creation: [getROImage] Succeeded' + ELSE PRINT 'Procedure Creation: [getROImage] Error on Creation' + GO + + + + + /****** Object: StoredProcedure [dbo].[getROFstsByRODbID] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'getROFstsByRODbID' AND type in (N'P')) + DROP PROCEDURE [dbo].[getROFstsByRODbID] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: + Create Date: + Description: + ========================================================================================================== + */ + CREATE PROCEDURE [dbo].[getROFstsByRODbID] + ( + @RODbID int + ) + WITH EXECUTE AS OWNER + AS + + SELECT + [ROFsts].[ROFstID], + [ROFsts].[RODbID], + --[ROFsts].[ROLookup], + null as [ROLookup], + [ROFsts].[Config], + [ROFsts].[DTS], + [ROFsts].[UserID], + [ROFsts].[LastChanged], + (SELECT COUNT(1) FROM [Associations] WHERE [Associations].[ROFstID]=[ROFsts].[ROFstID]) [AssociationCount], + (SELECT COUNT(1) FROM [Figures] WHERE [Figures].[ROFstID]=[ROFsts].[ROFstID]) [FigureCount] + FROM [ROFsts] + WHERE + [ROFsts].[RODbID]=@RODbID + + RETURN + GO + + IF (@@Error = 0) PRINT 'Procedure Creation: [getROFstsByRODbID] Succeeded' + ELSE PRINT 'Procedure Creation: [getROFstsByRODbID] Error on Creation' + GO + + + + + /****** Object: StoredProcedure [dbo].[getROFsts] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'getROFsts' AND type in (N'P')) + DROP PROCEDURE [dbo].[getROFsts] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: + Create Date: + Description: + ========================================================================================================== + */ + CREATE PROCEDURE [dbo].[getROFsts] + + WITH EXECUTE AS OWNER + AS + SELECT + [ROFstID], + [RODbID], + --[ROLookup], + null as [ROLookup], + [Config], + [DTS], + [UserID], + [LastChanged], + (SELECT Count(1) FROM [Associations] WHERE [Associations].[ROFstID]=[ROFsts].[ROFstID]) [AssociationCount], + (SELECT Count(1) FROM [Figures] WHERE [Figures].[ROFstID]=[ROFsts].[ROFstID]) [FigureCount] + FROM [ROFsts] + + RETURN + + GO + + IF (@@Error = 0) PRINT 'Procedure Creation: [getROFsts] Succeeded' + ELSE PRINT 'Procedure Creation: [getROFsts] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[getRoFstBySize] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'getRoFstBySize' AND type in (N'P')) + DROP PROCEDURE [dbo].[getRoFstBySize] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + Create PROCEDURE [dbo].[getRoFstBySize] + ( + @RODbID int, + @Len int + ) + WITH EXECUTE AS OWNER + AS + + select [ROFstID], + [RODbID], + --[ROLookup], + null as [ROLookup], + [Config], + [DTS], + [UserID], + [LastChanged], + (SELECT Count(1) FROM [Associations] WHERE [Associations].[ROFstID]=[ROFsts].[ROFstID]) [AssociationCount], + (SELECT Count(1) FROM [Figures] WHERE [Figures].[ROFstID]=[ROFsts].[ROFstID]) [FigureCount] + from [ROFsts] + where len(rolookup) = @len and [RODbID] = @RODbID + + RETURN + + GO + + IF (@@Error = 0) PRINT 'Procedure Creation: [getRoFstBySize] Succeeded' + ELSE PRINT 'Procedure Creation: [getRoFstBySize] Error on Creation' + GO + + + + + /****** Object: StoredProcedure [dbo].[getROFstByRODbID_DTS] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'getROFstByRODbID_DTS' AND type in (N'P')) + DROP PROCEDURE [dbo].[getROFstByRODbID_DTS] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: + Create Date: + Description: + ========================================================================================================== + */ + CREATE PROCEDURE [dbo].[getROFstByRODbID_DTS] + ( + @RODbID int, + @DTS datetime + ) + WITH EXECUTE AS OWNER + AS + SELECT + [ROFstID], + [RODbID], + --[ROLookup], + null as [ROLookup], + [Config], + [DTS], + [UserID], + [LastChanged], + (SELECT Count(1) FROM [Associations] WHERE [Associations].[ROFstID]=[ROFsts].[ROFstID]) [AssociationCount], + (SELECT Count(1) FROM [Figures] WHERE [Figures].[ROFstID]=[ROFsts].[ROFstID]) [FigureCount] + FROM [ROFsts] + WHERE [RODbID]=@RODbID AND [DTS]=@DTS + + RETURN + + GO + + IF (@@Error = 0) PRINT 'Procedure Creation: [getROFstByRODbID_DTS] Succeeded' + ELSE PRINT 'Procedure Creation: [getROFstByRODbID_DTS] Error on Creation' + GO + + + + + /****** Object: StoredProcedure [dbo].[getROFst] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'getROFst' AND type in (N'P')) + DROP PROCEDURE [dbo].[getROFst] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: + Create Date: + Description: + ========================================================================================================== + */ + CREATE PROCEDURE [dbo].[getROFst] + + ( + @ROFstID int + ) + WITH EXECUTE AS OWNER + AS + SELECT + [ROFstID], + [RODbID], + -- [ROLookup], + null as [ROLookup], + [Config], + [DTS], + [UserID], + [LastChanged], + (SELECT Count(1) FROM [Associations] WHERE [Associations].[ROFstID]=[ROFsts].[ROFstID]) [AssociationCount], + (SELECT Count(1) FROM [Figures] WHERE [Figures].[ROFstID]=[ROFsts].[ROFstID]) [FigureCount] + FROM [ROFsts] + WHERE [ROFstID]=@ROFstID + + SELECT + [Associations].[AssociationID], + [Associations].[VersionID], + [Associations].[ROFstID], + [Associations].[Config], + [Associations].[DTS], + [Associations].[UserID], + [Associations].[LastChanged], + [DocVersions].[FolderID] [DocVersion_FolderID], + [DocVersions].[VersionType] [DocVersion_VersionType], + [DocVersions].[Name] [DocVersion_Name], + [DocVersions].[Title] [DocVersion_Title], + [DocVersions].[ItemID] [DocVersion_ItemID], + [DocVersions].[FormatID] [DocVersion_FormatID], + [DocVersions].[Config] [DocVersion_Config], + [DocVersions].[DTS] [DocVersion_DTS], + [DocVersions].[UserID] [DocVersion_UserID] + FROM [Associations] + JOIN [DocVersions] ON + [DocVersions].[VersionID]=[Associations].[VersionID] + WHERE + [Associations].[ROFstID]=@ROFstID + + + SELECT + [Figures].[FigureID], + [Figures].[ROFstID], + [Figures].[ImageID], + [Figures].[Config], + [Figures].[DTS], + [Figures].[UserID], + [Figures].[LastChanged], + [ROImages].[RODbID] [ROImage_RODbID], + [ROImages].[FileName] [ROImage_FileName], + [ROImages].[Content] [ROImage_Content], + [ROImages].[Config] [ROImage_Config], + [ROImages].[DTS] [ROImage_DTS], + [ROImages].[UserID] [ROImage_UserID] + FROM [Figures] + JOIN [ROImages] ON + [ROImages].[ImageID]=[Figures].[ImageID] + WHERE + [Figures].[ROFstID]=@ROFstID + + RETURN + GO + + IF (@@Error = 0) PRINT 'Procedure Creation: [getROFst] Succeeded' + ELSE PRINT 'Procedure Creation: [getROFst] Error on Creation' + GO + + + + + /****** Object: StoredProcedure [dbo].[getRODb] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'getRODb' AND type in (N'P')) + DROP PROCEDURE [dbo].[getRODb] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: + Create Date: + Description: + ========================================================================================================== + */ + CREATE PROCEDURE [dbo].[getRODb] + ( + @RODbID int + ) + WITH EXECUTE AS OWNER + AS + SELECT + [RODbID], + [ROName], + [FolderPath], + [DBConnectionString], + [Config], + [DTS], + [UserID], + [LastChanged], + (SELECT Count(1) FROM [DROUsages] WHERE [DROUsages].[RODbID]=[RODbs].[RODbID]) [DROUsageCount], + (SELECT Count(1) FROM [ROFsts] WHERE [ROFsts].[RODbID]=[RODbs].[RODbID]) [ROFstCount], + (SELECT Count(1) FROM [ROImages] WHERE [ROImages].[RODbID]=[RODbs].[RODbID]) [ROImageCount], + (SELECT Count(1) FROM [RoUsages] WHERE [RoUsages].[RODbID]=[RODbs].[RODbID]) [RoUsageCount] + FROM [RODbs] + WHERE [RODbID]=@RODbID + + SELECT + [DROUsages].[DROUsageID], + [DROUsages].[DocID], + [DROUsages].[ROID], + [DROUsages].[Config], + [DROUsages].[DTS], + [DROUsages].[UserID], + [DROUsages].[LastChanged], + [DROUsages].[RODbID], + [Documents].[LibTitle] [Document_LibTitle], + [Documents].[DocContent] [Document_DocContent], + [Documents].[DocAscii] [Document_DocAscii], + [Documents].[Config] [Document_Config], + [Documents].[DTS] [Document_DTS], + [Documents].[UserID] [Document_UserID], + [Documents].[FileExtension] [Document_FileExtension] + FROM [DROUsages] + JOIN [Documents] ON + [Documents].[DocID]=[DROUsages].[DocID] + WHERE + [DROUsages].[RODbID]=@RODbID + + + SELECT + [ROFsts].[ROFstID], + [ROFsts].[RODbID], + --[ROFsts].[ROLookup], + null as [ROLookup], + [ROFsts].[Config], + [ROFsts].[DTS], + [ROFsts].[UserID], + [ROFsts].[LastChanged] + FROM [ROFsts] + WHERE + [ROFsts].[RODbID]=@RODbID + + + SELECT + [ROImages].[ImageID], + [ROImages].[RODbID], + [ROImages].[FileName], + [ROImages].[Content], + [ROImages].[Config], + [ROImages].[DTS], + [ROImages].[UserID], + [ROImages].[LastChanged] + FROM [ROImages] + WHERE + [ROImages].[RODbID]=@RODbID + + + SELECT + [RoUsages].[ROUsageID], + [RoUsages].[ContentID], + [RoUsages].[ROID], + [RoUsages].[Config], + [RoUsages].[DTS], + [RoUsages].[UserID], + [RoUsages].[LastChanged], + [RoUsages].[RODbID], + [Contents].[Number] [Content_Number], + [Contents].[Text] [Content_Text], + [Contents].[Type] [Content_Type], + [Contents].[FormatID] [Content_FormatID], + [Contents].[Config] [Content_Config], + [Contents].[DTS] [Content_DTS], + [Contents].[UserID] [Content_UserID] + FROM [RoUsages] + JOIN [Contents] ON + [Contents].[ContentID]=[RoUsages].[ContentID] + WHERE + [RoUsages].[RODbID]=@RODbID + + RETURN + + GO + + IF (@@Error = 0) PRINT 'Procedure Creation: [getRODb] Succeeded' + ELSE PRINT 'Procedure Creation: [getRODb] Error on Creation' + GO + + + + + /****** Object: StoredProcedure [dbo].[getJustROFst] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'getJustROFst' AND type in (N'P')) + DROP PROCEDURE [dbo].[getJustROFst] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: + Create Date: + Description: + ========================================================================================================== + */ + CREATE PROCEDURE [dbo].[getJustROFst] + ( + @ROFstID int + ) + WITH EXECUTE AS OWNER + AS + SELECT + [ROFstID], + [RODbID], + --[ROLookup], + null as [ROLookup], + [Config], + [DTS], + [UserID], + [LastChanged], + (SELECT Count(1) FROM [Associations] WHERE [Associations].[ROFstID]=[ROFsts].[ROFstID]) [AssociationCount], + (SELECT Count(1) FROM [Figures] WHERE [Figures].[ROFstID]=[ROFsts].[ROFstID]) [FigureCount] + FROM [ROFsts] + WHERE [ROFstID]=@ROFstID + + RETURN + + GO + + IF (@@Error = 0) PRINT 'Procedure Creation: [getJustROFst] Succeeded' + ELSE PRINT 'Procedure Creation: [getJustROFst] Error on Creation' + GO + + + + + /****** Object: StoredProcedure [dbo].[getFiguresByImageID] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'getFiguresByImageID' AND type in (N'P')) + DROP PROCEDURE [dbo].[getFiguresByImageID] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: + Create Date: + Description: + ========================================================================================================== + */ + CREATE PROCEDURE [dbo].[getFiguresByImageID] + ( + @ImageID int + ) + WITH EXECUTE AS OWNER + AS + + SELECT + [Figures].[FigureID], + [Figures].[ROFstID], + [Figures].[ImageID], + [Figures].[Config], + [Figures].[DTS], + [Figures].[UserID], + [Figures].[LastChanged], + [ROFsts].[RODbID] [ROFst_RODbID], + --[ROFsts].[ROLookup] [ROFst_ROLookup], + null as [ROFst_ROLookup], + [ROFsts].[Config] [ROFst_Config], + [ROFsts].[DTS] [ROFst_DTS], + [ROFsts].[UserID] [ROFst_UserID] + FROM [Figures] + JOIN [ROFsts] ON + [ROFsts].[ROFstID]=[Figures].[ROFstID] + WHERE + [Figures].[ImageID]=@ImageID + + RETURN + GO + + IF (@@Error = 0) PRINT 'Procedure Creation: [getFiguresByImageID] Succeeded' + ELSE PRINT 'Procedure Creation: [getFiguresByImageID] Error on Creation' + GO + + + + + /****** Object: StoredProcedure [dbo].[getDocVersion] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'getDocVersion' AND type in (N'P')) + DROP PROCEDURE [dbo].[getDocVersion] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: + Create Date: + Description: + ========================================================================================================== + */ + CREATE PROCEDURE [dbo].[getDocVersion] + ( + @VersionID int + ) + WITH EXECUTE AS OWNER + AS + SELECT + [VersionID], + [FolderID], + [VersionType], + [Name], + [Title], + [ItemID], + [FormatID], + [Config], + [DTS], + [UserID], + [LastChanged], + (SELECT COUNT(1) FROM [Associations] WHERE [Associations].[VersionID]=[DocVersions].[VersionID]) [AssociationCount] + FROM [DocVersions] + WHERE [VersionID]=@VersionID + + SELECT + [Associations].[AssociationID], + [Associations].[VersionID], + [Associations].[ROFstID], + [Associations].[Config], + [Associations].[DTS], + [Associations].[UserID], + [Associations].[LastChanged], + [ROFsts].[RODbID] [ROFst_RODbID], + --[ROFsts].[ROLookup] [ROFst_ROLookup], + null as [ROFst_ROLookup], + [ROFsts].[Config] [ROFst_Config], + [ROFsts].[DTS] [ROFst_DTS], + [ROFsts].[UserID] [ROFst_UserID] + FROM [Associations] + JOIN [ROFsts] ON + [ROFsts].[ROFstID]=[Associations].[ROFstID] + WHERE + [Associations].[VersionID]=@VersionID + + RETURN + GO + + IF (@@Error = 0) PRINT 'Procedure Creation: [getDocVersion] Succeeded' + ELSE PRINT 'Procedure Creation: [getDocVersion] Error on Creation' + GO + + + + /* + ---------------------------------------------------------------------------------- + Stored Procs: (Create New) + ---------------------------------------------------------------------------------- + [dbo].[vesp_RofstHeaderInsert] + [dbo].[vesp_RofstHeaderFinalizeLoad] + [dbo].[vesp_RofstDataSearch] + [dbo].[vesp_RofstDataGetValueDifferences] + [dbo].[vesp_RofstDataGetRofstByID] + [dbo].[vesp_RofstDataGetHeaderRofstByID] + [dbo].[vesp_RofstDataGetDatabases] + [dbo].[vesp_RofstDataGetDatabaseByID] + [dbo].[vesp_RofstDataGetChildrenByType] + [dbo].[vesp_RofstDataGetChildrenByRoid] + [dbo].[vesp_RofstDataGetChildrenByRofstID] + [dbo].[vesp_RofstDataGetChildrenByID] + [dbo].[vesp_RofstDataGetChildByRoid] + [dbo].[vesp_RofstDataGetChildByID] + [dbo].[vesp_RofstDataGetChildByAccPageID] + [dbo].[vesp_RofstDatabaseInsert] + [dbo].[vesp_RofstChildInsert] + */ + + + /****** Object: StoredProcedure [dbo].[vesp_RofstHeaderInsert] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstHeaderInsert' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstHeaderInsert] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Inserts New Rofst Header Record + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstHeaderInsert] + ( + @RofstID Int, + @hSize Int, + @hMonth Int, + @hDay Int, + @hcYear Int, + @hcMonth Int, + @hcDay Int, + @hcHour Int, + @hcMin Int, + @hcSec Int, + @hcHund Int, + @UserID VarChar(50) + ) + With Execute as Owner + As + Begin + + -- Clear Existing Values (If Any) + Delete From RofstHeader Where RofstID = @RofstID; + + -- Create RofstHeader records and Set LoadedDate to null + Insert Into RofstHeader (RofstID, hSize, hMonth, hDay, hcYear, hcMonth, hcDay, hcHour, hcMin, hcSec, hcHund, LoadedDate, CreateUserID, CreateDate) + Values (@RofstID, @hSize, @hMonth, @hDay, @hcYear, @hcMonth, @hcDay, @hcHour, @hcMin, @hcSec, @hcHund, null, @UserID, GetDate()); + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstHeaderInsert] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstHeaderInsert] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstHeaderFinalizeLoad] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstHeaderFinalizeLoad' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstHeaderFinalizeLoad] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Finalizes Rofst Header Record / Updates LoadedDate if Success + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstHeaderFinalizeLoad] + ( + @RofstID Int + ) + With Execute as Owner + As + Begin + + -- Set LoadedDate on RofstHeader + Update RofstHeader + Set LoadedDate = GetDate() + Where RofstID = @RofstID; + + -- Rebuild/Reorganize Indexes + Exec [dbo].[vesp_UtilityCheckIndexes] 20.0, 5.0, 0, 1; + + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstHeaderFinalizeLoad] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstHeaderFinalizeLoad] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataSearch] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataSearch' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDataSearch] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: RO Default Value Search + + @SearchTypeID => (1) Starts With (2) Ends With (3) Contains (4) Exact Match + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataSearch] + ( + @RofstID int, + @Value VarChar(Max) = null, + @SearchTypeID Int = 1, -- Starts With + @MaxNumOfRecords Int = null + ) + With Execute as Owner + As + Begin + + -- Remove any leading/trailing white spaces + Set @Value = dbo.vefn_Clean( @Value, 0, null ); + + -- Escape any % signs in the search value + Set @Value = Replace( @Value, '%', '[%]' ); + + -- Format search value + If (Len(@Value) = 0) Set @Value = null; + + -- Create Temp Results Table + Create Table #SearchResults + (roid VarChar(50) Not Null, [value] VarChar(Max), RowNum Int Not Null Primary Key); + + -- Select roids/values based on search criteria + Insert Into #SearchResults (roid, [value], RowNum) + Select rdv.roid, + rdv.[value], + Row_Number() Over (Order By rdv.[value] Asc, rdv.roid Asc) as 'RowNum' + From vwRofstData_RofstDefaultValues rdv + Where rdv.RofstID = @RofstID + And ((@Value is null) + Or (@SearchTypeID = 1 And rdv.[value] like @Value + '%') -- Starts With + Or (@SearchTypeID = 2 And rdv.[value] like '%' + @Value) -- Ends With + Or (@SearchTypeID = 3 And rdv.[value] like '%' + @Value + '%') -- Contains + Or (@SearchTypeID = 4 And rdv.[value] = @Value)) -- Exact Match + Order By rdv.[value] Asc, rdv.roid Asc + Option (Recompile); + + -- Return the specified number of results + Select sr.roid, sr.[value] + From #SearchResults sr + Where (@MaxNumOfRecords is null Or sr.RowNum <= @MaxNumOfRecords) + Order By sr.RowNum Asc; + + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataSearch] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataSearch] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataGetValueDifferences] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataGetValueDifferences' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDataGetValueDifferences] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Gets Value Differences between (2) Rofst (Ro.fst) Files + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataGetValueDifferences] + ( + @OriginalRofstID Int, + @CurrentRofstID Int + ) + With Execute as Owner + As + Begin + + Declare @Differences Table (OriginalRoid VarChar(25), OriginalValue VarChar(Max), + CurrentRoid VarChar(25), CurrentValue VarChar(Max)); + + + With OriginalRofst as + ( + Select rc.roid, rc.[value] + From vwRofstData_RofstChildren rc + Where rc.RofstID = @OriginalRofstID + And Not rc.[value] is null + + ), CurrentRofst as ( + + Select rc.roid, rc.[value] + From vwRofstData_RofstChildren rc + Where rc.RofstID = @CurrentRofstID + And Not rc.[value] is null + ) + Insert Into @Differences (OriginalRoid, OriginalValue, CurrentRoid, CurrentValue) + Select o.roid, o.[value], c.roid, c.[value] + From OriginalRofst o + left outer join CurrentRofst c on c.roid = o.roid + Where o.[value] <> c.[value]; + + + Select OriginalRoid as 'Roid', + Case When (CurrentValue is null) Then 1 Else 0 End as 'IsDeleted', + Case When (Not CurrentValue is null) Then 1 Else 0 End as 'IsModified' + From @Differences; + + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataGetValueDifferences] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataGetValueDifferences] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataGetRofstByID] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataGetRofstByID' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDataGetRofstByID] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Gets Rofsts Info by ID + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataGetRofstByID] + ( + @RofstID int, + @IncludeRoLookup Bit + ) + With Execute as Owner + As + Begin + + Select r.ROFstID, + r.RODbID, + Case (@IncludeRoLookup) When 1 Then r.ROLookup Else null End as 'ROLookup', + r.DTS, + r.UserID, + r.LastChanged + From ROFsts r with (NoLock) + Where r.RofstID = @RofstID; + + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataGetRofstByID] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataGetRofstByID] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataGetHeaderRofstByID] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataGetHeaderRofstByID' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDataGetHeaderRofstByID] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Gets Rofst Header Info by ID + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataGetHeaderRofstByID] + ( + @RofstID int + ) + With Execute as Owner + As + Begin + + Select rh.RofstID as 'RofstID', + rh.RofstHeaderStatusID as 'RofstHeaderStatusID', + rh.RofstHeaderStatus as 'RofstHeaderStatus', + rh.hSize as 'hSize', + rh.hMonth as 'hMonth', + rh.hDay as 'hDay', + rh.hcYear as 'hcYear', + rh.hcMonth as 'hcMonth', + rh.hcDay as 'hcDay', + rh.hcHour as 'hcHour', + rh.hcMin as 'hcMin', + rh.hcSec as 'hcSec', + rh.hcHund as 'hcHund', + rh.LoadedDate as 'LoadedDate', + rh.CreateUserID as 'CreateUserID', + rh.CreateDate as 'CreateDate' + From vwRofstData_RofstHeaders rh + Where rh.RofstID = @RofstID; + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataGetHeaderRofstByID] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataGetHeaderRofstByID] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataGetDatabases] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataGetDatabases' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDataGetDatabases] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Gets all Rofst Databases for a specified Rofst File + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataGetDatabases] + ( + @RofstID int + ) + With Execute as Owner + As + Begin + + Select rd.RofstID, + rd.dbiID, + rd.dbiType, + rd.dbiAW, + rd.dbiTitle, + rd.dbiAP, + rd.ID, + rd.ParentID + From vwRofstData_RofstDatabases rd + Where rd.RofstID = @RofstID + Order By rd.dbiID Asc; + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataGetDatabases] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataGetDatabases] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataGetDatabaseByID] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataGetDatabaseByID' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDataGetDatabaseByID] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Gets Rofst Database Info by ID + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataGetDatabaseByID] + ( + @RofstID int, + @dbiID int + ) + With Execute as Owner + As + Begin + + Select rd.RofstID, + rd.dbiID, + rd.dbiType, + rd.dbiAW, + rd.dbiTitle, + rd.dbiAP, + rd.ID, + rd.ParentID + From vwRofstData_RofstDatabases rd + Where rd.RofstID = @RofstID + And rd.dbiID = @dbiID; + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataGetDatabaseByID] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataGetDatabaseByID] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataGetChildrenByType] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataGetChildrenByType' AND type in (N'P')) + DROP PROCEDURE[dbo].[vesp_RofstDataGetChildrenByType] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Gets Rofst Children Info by Type + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataGetChildrenByType] + ( + @RofstID int, + @ValueTypes VarChar(Max) + ) + With Execute as Owner + As + Begin + + -- Remove any leading/trailing white spaces + Set @ValueTypes = dbo.vefn_Clean( @ValueTypes, 0, null ); + + -- Format search value + If (Len(@ValueTypes) = 0) Set @ValueTypes = null; + + With ValueTypes as + ( + Select Cast(x.ListValue as Int) as 'ListValue' + From dbo.vefn_ParseStringListToTable(@ValueTypes, ',') as x + ) + Select rc.ROFstID, + rc.dbiID, + rc.ID, + rc.ParentID, + rc.[type], + rc.title, + rc.roid, + rc.appid, + rc.[value], + rc.AccPageID + From vwRofstData_RofstChildren rc + Left outer join ValueTypes vt on vt.ListValue = rc.[type] + Where rc.RofstID = @RofstID + And Not rc.[value] is null + And (@ValueTypes is null Or Not vt.ListValue is null) + Option (Recompile); + + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataGetChildrenByType] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataGetChildrenByType] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataGetChildrenByRoid] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataGetChildrenByRoid' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDataGetChildrenByRoid] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Gets Rofst Children (RoChild) Info by Roid + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataGetChildrenByRoid] + ( + @RofstID int, + @Roid VarChar(50) + ) + With Execute as Owner + As + Begin + + With RoParent as + ( + Select RofstID, dbiID, ID, [type], title, roid + From vwRofstData_RofstChildren + Where RofstID = @RofstID And roid = @Roid + ) + Select rc.RofstID, + rc.dbiID, + -- Ro Parent Info + rp.[type] as 'ParentType', + rp.title as 'ParentTitle', + rp.roid as 'ParentRoid', + -- Ro Child Info + rc.ID, + rc.ParentID, + rc.[type], + rc.title, + rc.roid, + rc.appid, + rc.[value], + rc.AccPageID + From RoParent rp + inner join vwRofstData_RofstChildren rc on rc.RofstID = rp.RofstID and rc.dbiID = rp.dbiID and rc.ParentID = rp.ID + Order By rc.ID Asc; + + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataGetChildrenByRoid] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataGetChildrenByRoid] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataGetChildrenByRofstID] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataGetChildrenByRofstID' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDataGetChildrenByRofstID] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Gets All Rofst Children Info by Rofst ID + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataGetChildrenByRofstID] + ( + @RofstID int + ) + With Execute as Owner + As + Begin + + Select rc.RofstID, + rc.dbiID, + rc.ID, + rc.ParentID, + rc.[type], + rc.title, + rc.roid, + rc.appid, + rc.[value], + rc.AccPageID + From vwRofstData_RofstChildren rc + Where rc.RofstID = @RofstID + And Not rc.[value] is null + Order By rc.dbiID Asc, rc.[type] Asc, rc.roid Asc; + + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataGetChildrenByRofstID] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataGetChildrenByRofstID] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataGetChildrenByID] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataGetChildrenByID' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDataGetChildrenByID] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Gets Rofst Children Info by DbiID and Object ID + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataGetChildrenByID] + ( + @RofstID int, + @DbiID int, + @ID Int + ) + With Execute as Owner + As + Begin + + + Select rc.RofstID, + rc.dbiID, + rc.ID, + rc.ParentID, + rc.[type], + rc.title, + rc.roid, + rc.appid, + rc.[value], + rc.AccPageID + From vwRofstData_RofstChildren rc + Where rc.RofstID = @RofstID + And rc.dbiID = @DbiID + And rc.ParentID = @ID + Order By rc.ID Asc; + + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataGetChildrenByID] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataGetChildrenByID] Error on Creation' + GO + + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataGetChildByRoid] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataGetChildByRoid' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDataGetChildByRoid] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Gets Rofst Child Info by Roid + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataGetChildByRoid] + ( + @RofstID int, + @Roid VarChar(50) + ) + With Execute as Owner + As + Begin + + Select rc.ROFstID, + rc.dbiID, + rc.ID, + rc.ParentID, + rc.[type], + rc.title, + rc.roid, + rc.appid, + rc.[value], + rc.AccPageID + From vwRofstData_RofstChildren rc + Where rc.RofstID = @RofstID + And rc.roid = @Roid; + + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataGetChildByRoid] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataGetChildByRoid] Error on Creation' + GO + + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataGetChildByID] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataGetChildByID' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDataGetChildByID] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Gets Rofst Child Info by dbiID and Object ID + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataGetChildByID] + ( + @RofstID int, + @DbiID int, + @ID Int + ) + With Execute as Owner + As + Begin + + Select rc.RofstID, + rc.dbiID, + rc.ID, + rc.ParentID, + rc.[type], + rc.title, + rc.roid, + rc.appid, + rc.[value], + rc.AccPageID + From vwRofstData_RofstChildren rc + Where rc.RofstID = @RofstID + And rc.dbiID = @DbiID + And rc.ID = @ID; + + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataGetChildByID] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataGetChildByID] Error on Creation' + GO + + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataGetChildByAccPageID] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataGetChildByAccPageID' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDataGetChildByAccPageID] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Gets Rofst Child Info by AccPageID + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataGetChildByAccPageID] + ( + @RofstID int, + @AccPageID VarChar(50) + ) + With Execute as Owner + As + Begin + + Select rc.ROFstID, + rc.dbiID, + rc.ID, + rc.ParentID, + rc.[type], + rc.title, + rc.roid, + rc.appid, + rc.[value], + rc.AccPageID + From vwRofstData_RofstChildren rc + Where rc.RofstID = @RofstID + And rc.AccPageID = @AccPageID; + + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataGetChildByAccPageID] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataGetChildByAccPageID] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDatabaseInsert] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDatabaseInsert' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDatabaseInsert] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Inserts New Rofst Database Record + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDatabaseInsert] + ( + @RofstID Int, + @dbiID Int, + @dbiType Int, + @dbiAW Int, + @dbiTitle VarChar(Max), + @dbiAP VarChar(Max), + @ID Int, + @ParentID Int + ) + With Execute as Owner + As + Begin + + + Insert Into RofstDatabase (RofstID, dbiID, dbiType, dbiAW, dbiTitle, dbiAP, ID, ParentID) + Values (@RofstID, @dbiID, @dbiType, @dbiAW, @dbiTitle, @dbiAP, @ID, @ParentID ); + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDatabaseInsert] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDatabaseInsert] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstChildInsert] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstChildInsert' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstChildInsert] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Inserts New Rofst Child Record / Default Values + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstChildInsert] + ( + @RofstID Int, + @ID Int, + @ParentID Int, + @dbiID Int, + @type Int, + @title VarChar(Max), + @roid VarChar(50), + @appid VarChar(Max) = null, + @value VarChar(Max) = null + ) + With Execute as Owner + As + Begin + + Declare @AccPageID VarChar(Max) = null; + Declare @DefaultValues VarChar(Max); + + + -- Create Rofst Child/Group Record + Insert Into RofstChild (RofstID, ID, ParentID, dbiID, [type], title, roid, appid, [value]) + Values (@RofstID, @ID, @ParentID, @dbiID, @type, @title, @roid, @appid, @value); + + + -- Check for appid, if exists, then insert the default value for each return type if multi-value + If (Len(@appid) > 0) + Begin + + -- Get Accessory Page ID + Select @AccPageID = Concat(d.dbiAP, '-', @appid) + From RofstDatabase d with (NoLock) + Where d.RofstID = @RofstID And d.dbiID = @dbiID; + + -- Insert Rofst Default Value (Parent RoChild) [roid = 12] + Insert Into RofstDefaultValue (RofstID, roid, [value], AccPageID) + Values (@RofstID, @roid, Replace(@title, '\u160?', ' '), @AccPageID); + + -- Insert Rofst Default Value(s) (Children RoChild) [roid = 16] (Do Not Insert Duplicates) + Select @DefaultValues = Replace(dbo.vefn_RofstDataReplaceVars(@value), '{', ''); + + With ChildrenValues as + ( + Select (x.ListPosition + 40) as 'OffsetIndex', + Case When (PatIndex('%=%', x.ListValue) > 0) Then Right(x.ListValue, Len(x.ListValue)-PatIndex('%=%', x.ListValue)) Else x.ListValue End as 'DefaultValue' + From [dbo].[vefn_ParseStringListToTable](@DefaultValues, '}') x + Where Len(x.ListValue) > 0 + ) + Insert Into RofstDefaultValue (RofstID, roid, [value], AccPageID) + Select @RofstID as 'RofstID', + Concat(@roid, Cast(Format(Min(OffsetIndex), 'D4') as VarChar(4))) as 'roid', + DefaultValue as 'value', + null as 'AccPageID' + From ChildrenValues + Group By DefaultValue + Order By Min(OffsetIndex) Asc + + End -- (Len(@appid) > 0) + + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstChildInsert] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstChildInsert] Error on Creation' + GO + + + + + +/* +========================================================================================================== + End: B2022-026 RO Memory reduction coding (Jakes Merge) [Version 2.0] +========================================================================================================== +*/ + + ----------------------------------------------------------------------------- /* --------------------------------------------------------------------------- @@ -17427,6 +20059,14 @@ GO --------------------------------------------------------------------------- */ ----------------------------------------------------------------------------- +-- Rebuild / Reorganize All Indexes +exec [dbo].[vesp_UtilityCheckIndexes]; + +IF (@@Error = 0) PRINT 'Running vesp_UtilityCheckIndexes Succeeded' +ELSE PRINT 'Running vesp_UtilityCheckIndexes Failed to Execute' +GO + + IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vesp_GetSQLCodeRevision]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) DROP PROCEDURE [vesp_GetSQLCodeRevision]; GO @@ -17445,8 +20085,8 @@ BEGIN TRY -- Try Block DECLARE @RevDate varchar(255) DECLARE @RevDescription varchar(255) - set @RevDate = '06/02/2022 12:30 PM' - set @RevDescription = 'getGridIds fix for table searches' + set @RevDate = '06/22/2022 5:30 PM' + set @RevDescription = 'ROFST Lookup / Memory Fixes (v2.0) -> [B2022-026 RO Memory reduction coding (Jakes Merge)]' Select cast(@RevDate as datetime) RevDate, @RevDescription RevDescription PRINT 'SQL Code Revision ' + @RevDate + ' - ' + @RevDescription diff --git a/PROMS/VEPROMS User Interface/PROMSFixes.Sql b/PROMS/VEPROMS User Interface/PROMSFixes.Sql index 77084393..e6d6af1a 100644 --- a/PROMS/VEPROMS User Interface/PROMSFixes.Sql +++ b/PROMS/VEPROMS User Interface/PROMSFixes.Sql @@ -1,6 +1,6 @@ - if db_name() in('master','model','msdn','tempdb') +If (db_name() in('master','model','msdn','tempdb')) begin DECLARE @ErrorMsg varchar(255) SET @ErrorMsg = 'Don''t add these procedures and functions to ' + db_name() @@ -16,6 +16,8 @@ begin end print 'Adding procedures and functions to ' + db_name() + + IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[PasteItemReplace]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) DROP PROCEDURE [PasteItemReplace]; GO @@ -17387,16 +17389,6 @@ ELSE PRINT 'Index Creation:[IX_tblTransitionsDeleteStatusTransitionID] Error on GO - - --- Rebuild / Reorganize All Indexes -exec [dbo].[vesp_UtilityCheckIndexes]; - - -IF (@@Error = 0) PRINT 'Running vesp_UtilityCheckIndexes Succeeded' -ELSE PRINT 'Running vesp_UtilityCheckIndexes Failed to Execute' -GO - IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getGridIds]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) DROP PROCEDURE [getGridIds]; GO @@ -17419,6 +17411,2646 @@ ELSE PRINT 'Procedure Creation: [getGridIds] Error on Creation' GO + +/* +========================================================================================================== + Begin: B2022-026 RO Memory reduction coding (Jakes Merge) [Version 2.0] + Notes** If you need to rollback to the previous version for some reason and undo the changes + for v2.0 then run the corresponding "PROMSRollback (v2.0).sql" file +========================================================================================================== +*/ + /* + ---------------------------------------------------------------------------------- + Tables: + ---------------------------------------------------------------------------------- + [RofstHeader] + [RofstDatabase] + [RofstChild] + [RofstDefaultValue] + + ---------------------------------------------------------------------------------- + Indexes: + ---------------------------------------------------------------------------------- + [IX_RofstID_Roid] on [dbo].[RofstChild] + [IX_RofstID_DbiID_ParentID] on [dbo].[RofstChild] + + */ + + -- If RofstHeader and other tables already exist then don't drop and recreate them + IF Not Exists(SELECT * FROM sys.objects Where name = 'RofstHeader' AND type in (N'U')) + Begin -- Rofst Tables + + SET ANSI_NULLS ON + SET QUOTED_IDENTIFIER ON + + /****** Object: Table [dbo].[RofstChild] Script Date: 6/6/2022 11:18:32 AM ******/ + CREATE TABLE [dbo].[RofstChild]( + [RofstChildID] [int] IDENTITY(1,1) NOT NULL, + [RofstID] [int] NOT NULL, + [dbiID] [int] NOT NULL, + [ID] [int] NOT NULL, + [ParentID] [int] NOT NULL, + [type] [int] NOT NULL, + [title] [varchar](max) NOT NULL, + [roid] [varchar](50) NOT NULL, + [appid] [varchar](max) NULL, + [value] [varchar](max) NULL, + CONSTRAINT [PK_RofstChild] PRIMARY KEY CLUSTERED + ( + [RofstChildID] ASC + )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] + ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] + + IF (@@Error = 0) PRINT 'Table Creation: [RofstChild] Succeeded' + ELSE PRINT 'Table Creation: [RofstChild] Error on Creation' + + + /****** Object: Table [dbo].[RofstDatabase] Script Date: 6/6/2022 11:18:32 AM ******/ + CREATE TABLE [dbo].[RofstDatabase]( + [RofstID] [int] NOT NULL, + [dbiID] [int] NOT NULL, + [dbiType] [int] NOT NULL, + [dbiAW] [int] NOT NULL, + [dbiTitle] [varchar](max) NOT NULL, + [dbiAP] [varchar](max) NOT NULL, + [ID] [int] NOT NULL, + [ParentID] [int] NOT NULL, + CONSTRAINT [PK_RofstDatabase_1] PRIMARY KEY CLUSTERED + ( + [RofstID] ASC, + [dbiID] ASC + )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] + ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] + + IF (@@Error = 0) PRINT 'Table Creation: [RofstDatabase] Succeeded' + ELSE PRINT 'Table Creation: [RofstDatabase] Error on Creation' + + + /****** Object: Table [dbo].[RofstDefaultValue] Script Date: 6/6/2022 11:18:32 AM ******/ + CREATE TABLE [dbo].[RofstDefaultValue]( + [RofstID] [int] NOT NULL, + [roid] [varchar](50) NOT NULL, + [value] [varchar](max) NOT NULL, + [AccPageID] [varchar](max) NULL, + CONSTRAINT [PK_RofstDefaultValue] PRIMARY KEY CLUSTERED + ( + [RofstID] ASC, + [roid] ASC + )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] + ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] + + IF (@@Error = 0) PRINT 'Table Creation: [RofstDefaultValue] Succeeded' + ELSE PRINT 'Table Creation: [RofstDefaultValue] Error on Creation' + + + /****** Object: Table [dbo].[RofstHeader] Script Date: 6/6/2022 11:18:32 AM ******/ + CREATE TABLE [dbo].[RofstHeader]( + [RofstID] [int] NOT NULL, + [hSize] [int] NOT NULL, + [hMonth] [int] NOT NULL, + [hDay] [int] NOT NULL, + [hcYear] [int] NOT NULL, + [hcMonth] [int] NOT NULL, + [hcDay] [int] NOT NULL, + [hcHour] [int] NOT NULL, + [hcMin] [int] NOT NULL, + [hcSec] [int] NOT NULL, + [hcHund] [int] NOT NULL, + [CreateUserID] [varchar](50) NOT NULL, + [CreateDate] [datetime] NOT NULL, + [LoadedDate] [datetime] NULL, + CONSTRAINT [PK_RofstHeader] PRIMARY KEY CLUSTERED + ( + [RofstID] ASC + )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] + ) ON [PRIMARY] + + IF (@@Error = 0) PRINT 'Table Creation: [RofstHeader] Succeeded' + ELSE PRINT 'Table Creation: [RofstHeader] Error on Creation' + + + /****** Object: Index [IX_RofstID_DbiID_ParentID] Script Date: 6/6/2022 11:18:32 AM ******/ + CREATE NONCLUSTERED INDEX [IX_RofstID_DbiID_ParentID] ON [dbo].[RofstChild] + ( + [RofstID] ASC, + [dbiID] ASC, + [ParentID] ASC + ) + INCLUDE([ID],[type],[title],[roid],[appid],[value]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] + + IF (@@Error = 0) PRINT 'Index Creation: [IX_RofstID_DbiID_ParentID] Succeeded' + ELSE PRINT 'Index Creation: [IX_RofstID_DbiID_ParentID] Error on Creation' + + + /****** Object: Index [IX_RofstID_Roid] Script Date: 6/6/2022 11:18:32 AM ******/ + CREATE NONCLUSTERED INDEX [IX_RofstID_Roid] ON [dbo].[RofstChild] + ( + [RofstID] ASC, + [roid] ASC + )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] + + IF (@@Error = 0) PRINT 'Index Creation: [IX_RofstID_Roid] Succeeded' + ELSE PRINT 'Index Creation: [IX_RofstID_Roid] Error on Creation' + + + ALTER TABLE [dbo].[RofstDatabase] ADD CONSTRAINT [DF_RofstDatabase_ParentID] DEFAULT ((0)) FOR [ParentID] + + ALTER TABLE [dbo].[RofstHeader] ADD CONSTRAINT [DF_RofstHeader_CreateUserID] DEFAULT ('SYSTEM') FOR [CreateUserID] + + ALTER TABLE [dbo].[RofstHeader] ADD CONSTRAINT [DF_RofstHeader_CreateDate] DEFAULT (getdate()) FOR [CreateDate] + + ALTER TABLE [dbo].[RofstChild] WITH CHECK ADD CONSTRAINT [FK_RofstChild_RofstDatabase] FOREIGN KEY([RofstID], [dbiID]) + REFERENCES [dbo].[RofstDatabase] ([RofstID], [dbiID]) + ON DELETE CASCADE + + ALTER TABLE [dbo].[RofstChild] CHECK CONSTRAINT [FK_RofstChild_RofstDatabase] + + ALTER TABLE [dbo].[RofstDatabase] WITH CHECK ADD CONSTRAINT [FK_RofstDatabase_RofstHeader] FOREIGN KEY([RofstID]) + REFERENCES [dbo].[RofstHeader] ([RofstID]) + ON DELETE CASCADE + + ALTER TABLE [dbo].[RofstDatabase] CHECK CONSTRAINT [FK_RofstDatabase_RofstHeader] + + ALTER TABLE [dbo].[RofstDefaultValue] WITH CHECK ADD CONSTRAINT [FK_RofstDefaultValue_RofstHeader] FOREIGN KEY([RofstID]) + REFERENCES [dbo].[RofstHeader] ([RofstID]) + ON DELETE CASCADE + + ALTER TABLE [dbo].[RofstDefaultValue] CHECK CONSTRAINT [FK_RofstDefaultValue_RofstHeader] + + ALTER TABLE [dbo].[RofstHeader] WITH CHECK ADD CONSTRAINT [FK_RofstHeader_ROFsts] FOREIGN KEY([RofstID]) + REFERENCES [dbo].[ROFsts] ([ROFstID]) + ON DELETE CASCADE + + ALTER TABLE [dbo].[RofstHeader] CHECK CONSTRAINT [FK_RofstHeader_ROFsts] + + IF (@@Error = 0) PRINT 'Table/FK Constraints: Succeeded' + ELSE PRINT 'Table/FK Constraints: Error on Creation' + + End -- Rofst Tables + Go + + + /* + ---------------------------------------------------------------------------------- + Functions: + ---------------------------------------------------------------------------------- + [dbo].[vefn_Clean] + [dbo].[vefn_ParseStringListToTable] + [dbo].[vefn_NumOfOccurrences] + [dbo].[vefn_RofstDataReplaceVars] + [dbo].[vefn_RofstDataReplaceApplTagsWithDefaults] + [dbo].[vefn_RofstDataGetLoadStatus] + */ + + /****** Object: UserDefinedFunction [dbo].[vefn_Clean] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vefn_Clean' AND type in (N'FN')) + DROP FUNCTION [dbo].[vefn_Clean] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + -- ========================================================================================== + -- Author: Jake Ropar + -- Create Date: 4/21/2022 + -- Description: Cleans (Trim) the string value passed + -- Optional: Truncate is string is passed a specified max length + -- Optional: Convert any null values to an empty string or leave as null + -- ========================================================================================== + + Create Function [dbo].[vefn_Clean] ( @Value VarChar(Max), @ConvertNulls bit = 0, @MaxLength Int = null ) + Returns VarChar(Max) + As + Begin + + Declare @RetVal VarChar(Max); + + If (Len(IsNull(@Value,'')) > 0) + Begin + + Set @RetVal = LTrim(RTrim(@Value)); + If (Not @MaxLength is null And Len(@RetVal) > @MaxLength) Set @RetVal = Left(@RetVal, @MaxLength); + + End + + If (@ConvertNulls = 1) + Set @RetVal = IsNull(@RetVal, ''); + + Return @RetVal; + + End + GO + + IF (@@Error = 0) PRINT 'Function Creation: [vefn_Clean] Succeeded' + ELSE PRINT 'Function Creation: [vefn_Clean] Error on Creation' + GO + + + + /****** Object: UserDefinedFunction [dbo].[vefn_ParseStringListToTable] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vefn_ParseStringListToTable' AND type in (N'TF')) + DROP FUNCTION [dbo].[vefn_ParseStringListToTable] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + -- ========================================================================================== + -- Author: Jake Ropar + -- Create Date: 3/26/2018 + -- Description: Splits a delimited list of strings into a table of string values + -- ========================================================================================== + + Create Function [dbo].[vefn_ParseStringListToTable] ( @List VarChar(Max), @Delimeter VarChar(1) = null ) + Returns @RetVal Table (ListPosition Int Identity(1,1) Not Null, ListValue VarChar(Max) Not Null) + With Execute As Owner + As + Begin + + Declare @Position Int; + Declare @TextPosition Int; + Declare @Length smallint; + Declare @String VarChar(Max); + Declare @TempString VarChar(Max); + Declare @LeftOver VarChar(Max); + + Set @TextPosition = 1; + Set @LeftOver = ''; + Set @Delimeter = IsNull(@Delimeter, ','); + + If (DataLength(@List) = 1) + Insert @RetVal (ListValue) Values (Cast(@List as VarChar(Max))); + Else + Begin + While (@TextPosition <= DataLength(@List) / 2) + Begin + + Set @Length = (4000 - DataLength(@LeftOver) / 2); + Set @TempString = LTrim(@LeftOver + Substring(@List, @TextPosition, @Length)); + Set @TextPosition = @TextPosition + @Length; + Set @Position = CharIndex(@Delimeter, @TempString); + + While (@Position > 0) + Begin + + Set @String = Substring(@TempString, 1, @Position - 1); + + Insert @RetVal (ListValue) Values (Cast(@String as VarChar(Max))); + + Set @TempString = LTrim(Substring(@TempString, @Position + 1, Len(@TempString))); + Set @Position = CharIndex(@Delimeter, @TempString); + + End + + Set @LeftOver = @TempString; + End + End + + If (LTrim(RTrim(@LeftOver)) <> '') + Insert @RetVal (ListValue) Values (Cast(@LeftOver as VarChar(Max))); + + Return; + End + GO + + IF (@@Error = 0) PRINT 'Function Creation: [vefn_ParseStringListToTable] Succeeded' + ELSE PRINT 'Function Creation: [vefn_ParseStringListToTable] Error on Creation' + GO + + + + /****** Object: UserDefinedFunction [dbo].[vefn_NumOfOccurrences] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vefn_NumOfOccurrences' AND type in (N'FN')) + DROP FUNCTION [dbo].[vefn_NumOfOccurrences] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + -- ========================================================================================== + -- Author: Jake Ropar + -- Create Date: 3/1/2022 + -- Description: Returns the number of occurences of a specific value in a specified string + -- ========================================================================================== + + CREATE FUNCTION [dbo].[vefn_NumOfOccurrences](@Text VarChar(Max), @Value VarChar(Max)) Returns Int + WITH EXECUTE AS OWNER + AS + BEGIN + + Declare @ValueCount Int; + + If (Len(@Value) = 0) + Set @ValueCount = 0; + Else + Set @ValueCount = (Len(@Text) - Len(Replace(@Text, @Value, ''))) / Len(@Value); + + Return @ValueCount; + + END + GO + + IF (@@Error = 0) PRINT 'Function Creation: [vefn_NumOfOccurrences] Succeeded' + ELSE PRINT 'Function Creation: [vefn_NumOfOccurrences] Error on Creation' + GO + + + + /****** Object: UserDefinedFunction [dbo].[vefn_RofstDataReplaceVars] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vefn_RofstDataReplaceVars' AND type in (N'FN')) + DROP FUNCTION [dbo].[vefn_RofstDataReplaceVars] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + -- ========================================================================================== + -- Author: Jake Ropar + -- Create Date: 3/25/2022 + -- Description: Replaces Any Variables and returns the rest of the value string + -- ========================================================================================== + + CREATE FUNCTION [dbo].[vefn_RofstDataReplaceVars](@Values VarChar(Max)) Returns VarChar(Max) + WITH EXECUTE AS OWNER + AS + BEGIN + + Declare @RetVal VarChar(Max) = ''; + Declare @EqualsIndex Int; + Declare @EndIndex Int; + Declare @NameValPairStartIndex Int; + Declare @NameValPairEndIndex Int; + + Declare @VarPair VarChar(Max); + Declare @VarName VarChar(Max); + Declare @VarValue VarChar(Max); + + -- Replace Any "" Tags with the Default Value first + Select @RetVal = dbo.vefn_RofstDataReplaceApplTagsWithDefaults(@Values); + + If (PatIndex('%{{A%', @RetVal) > 0) + Set @EndIndex = PatIndex('%{{A%', @RetVal); + Else + Set @EndIndex = Len(@RetVal) -1; + + Set @NameValPairStartIndex = PatIndex('%{%', @RetVal); + Set @NameValPairEndIndex = PatIndex('%}%', @RetVal); + + While(@NameValPairStartIndex > 0 And @NameValPairStartIndex < @EndIndex) + Begin + + -- Get Name Value Pair [ex. {EGS=1214}] + Set @VarPair = SubString(@RetVal, @NameValPairStartIndex, (@NameValPairEndIndex - @NameValPairStartIndex) + 1); + + -- Remove Name Value Pair From Return Val + Set @RetVal = Replace(@RetVal, @VarPair, ''); + + -- Get Variable Name and Value + Set @EqualsIndex = PatIndex('%=%', @VarPair); + + If (@EqualsIndex > 0) + Begin + Set @VarName = SubString(@VarPair, 2, @EqualsIndex - 2); + Set @VarValue = SubString(@VarPair, @EqualsIndex + 1, Len(@VarPair) - @EqualsIndex - 1); + Set @VarName = Concat('{', @VarName, '}'); + + -- Replace All Occurences + Set @RetVal = Replace(@RetVal, @VarName, @VarValue); + End + + -- Get Updated Index Values + If (PatIndex('%{{A%', @RetVal) > 0) + Set @EndIndex = PatIndex('%{{A%', @RetVal); + Else + Set @EndIndex = Len(@RetVal) -1; + + Set @NameValPairStartIndex = PatIndex('%{%', @RetVal); + Set @NameValPairEndIndex = PatIndex('%}%', @RetVal); + + End -- End While(@ReplaceVarEndTagIndex > 0) + + Return @RetVal; + + END + GO + + IF (@@Error = 0) PRINT 'Function Creation: [vefn_RofstDataReplaceVars] Succeeded' + ELSE PRINT 'Function Creation: [vefn_RofstDataReplaceVars] Error on Creation' + GO + + + + /****** Object: UserDefinedFunction [dbo].[vefn_RofstDataReplaceApplTagsWithDefaults] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vefn_RofstDataReplaceApplTagsWithDefaults' AND type in (N'FN')) + DROP FUNCTION [dbo].[vefn_RofstDataReplaceApplTagsWithDefaults] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + -- ========================================================================================== + -- Author: Jake Ropar + -- Create Date: 3/25/2022 + -- Description: Replaces any "" tags with the default value + -- ========================================================================================== + + CREATE FUNCTION [dbo].[vefn_RofstDataReplaceApplTagsWithDefaults](@Values VarChar(Max)) Returns VarChar(Max) + WITH EXECUTE AS OWNER + AS + BEGIN + + Declare @RetVal VarChar(Max) = ''; + Declare @DefaultValue VarChar(Max) = ''; + + Declare @StartTagIndex Int; + Declare @EndTagIndex Int; + Declare @StartTagValue VarChar(Max); + + Set @RetVal = @Values; + Set @StartTagIndex = PatIndex('%%', @RetVal); + + While (@StartTagIndex > 0) + Begin + + Set @StartTagValue = SubString(@RetVal, @StartTagIndex, (@EndTagIndex - @StartTagIndex) + 5); + Set @DefaultValue = Replace(@StartTagValue, '%', @DefaultValue); + + Set @DefaultValue = RTrim(SubString(@DefaultValue, 0, @EndTagIndex)); + Set @RetVal = Replace(@RetVal, @StartTagValue, @DefaultValue); + + Set @StartTagIndex = PatIndex('%%', @RetVal); + + End -- While (@StartTagIndex > 0) + + Return @RetVal; + + END + GO + + IF (@@Error = 0) PRINT 'Function Creation: [vefn_RofstDataReplaceApplTagsWithDefaults] Succeeded' + ELSE PRINT 'Function Creation: [vefn_RofstDataReplaceApplTagsWithDefaults] Error on Creation' + GO + + + + + /****** Object: UserDefinedFunction [dbo].[vefn_RofstDataGetLoadStatus] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vefn_RofstDataGetLoadStatus' AND type in (N'FN')) + DROP FUNCTION [dbo].[vefn_RofstDataGetLoadStatus] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + -- ========================================================================================== + -- Author: Jake Ropar + -- Create Date: 05/20/2022 + -- Description: Gets the current load status for a Rofst Binary + -- ========================================================================================== + + CREATE FUNCTION [dbo].[vefn_RofstDataGetLoadStatus](@RofstID Int) Returns Int + WITH EXECUTE AS OWNER + AS + BEGIN + + Declare @RofstHeaderStatusID Int; + Declare @NumOfRecordsStart Int; + Declare @NumOfRecordsEnd Int; + Declare @CreateDate DateTime; + Declare @LoadedDate DateTime; + + -- Set Default Values + Set @RofstHeaderStatusID = 0; -- [Unknown] + Set @NumOfRecordsStart = -1; + Set @NumOfRecordsEnd = -1; + + -- Get RofstHeader Data + Select @CreateDate = CreateDate, @LoadedDate = LoadedDate + From RofstHeader with (NoLock) + Where RofstID = @RofstID; + + -- Check Current Status of RofstHeader/Data + If (@CreateDate is null) + Begin + Set @RofstHeaderStatusID = 1; -- [Not Loaded] + End + Else If (Not @LoadedDate is null) + Begin + Set @RofstHeaderStatusID = 3; -- [Load Complete] + End + Else If (@LoadedDate is null) + Begin + + -- Check if the record count for Rofst Default Values is still increasing + --Declare @cnt Int = 4000000; + Declare @cnt Int = 2000000; + + Select @NumOfRecordsStart = Count(1) From vwRofstData_RofstDefaultValues Where RofstID = @RofstID; + + While (@cnt > 0) + Set @cnt = @Cnt -1; + + Select @NumOfRecordsEnd = Count(1) From vwRofstData_RofstDefaultValues Where RofstID = @RofstID; + + If (@NumOfRecordsStart < @NumOfRecordsEnd) + Set @RofstHeaderStatusID = 2; -- [In Progress] + Else + Set @RofstHeaderStatusID = 4; -- [Load Failed] + End + Else + Begin + Set @RofstHeaderStatusID = 0; -- [Unknown] + End + + + Return @RofstHeaderStatusID; + + END + GO + + IF (@@Error = 0) PRINT 'Function Creation: [vefn_RofstDataGetLoadStatus] Succeeded' + ELSE PRINT 'Function Creation: [vefn_RofstDataGetLoadStatus] Error on Creation' + GO + + + /* + ---------------------------------------------------------------------------------- + Views: + ---------------------------------------------------------------------------------- + [dbo].[vwRofstData_RofstChildren] + [dbo].[vwRofstData_RofstDatabases] + [dbo].[vwRofstData_RofstDefaultValues] + [dbo].[vwRofstData_RofstHeaders] + [dbo].[vwRofstData_RofstHeaderStatuses] + */ + + /****** Object: View [dbo].[vwRofstData_RofstChildren] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vwRofstData_RofstChildren' AND type in (N'V')) + DROP VIEW [dbo].[vwRofstData_RofstChildren] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 03/24/2024 + Description: (RofstData) Master View for RofstChildren (RoChild & Groups) + ========================================================================================================== + */ + Create View [dbo].[vwRofstData_RofstChildren] + As + + Select rc.RofstChildID as 'RofstChildID', + rd.RofstID as 'RofstID', + -- RoDatabase Info + rd.dbiID as 'dbiID', + rd.dbiType as 'dbiType', + rd.dbiAW as 'dbiAW', + rd.dbiTitle as 'dbiTitle', + rd.dbiAP as 'dbiAP', + -- RoChild Info + rc.ID as 'ID', + rc.ParentID as 'ParentID', + rc.[type] as 'type', + Case When (rc.[type] = 1) Then 'Single Line Text' -- Fixed Length Text + When (rc.[type] = 2) Then 'Table' + When (rc.[type] = 3) Then 'Multiple Line Text' + When (rc.[type] = 4) Then 'X/Y Plot' + When (rc.[type] = 8) Then 'Image' + Else 'Unknown' End as 'TypeDescription', + rc.title as 'title', + rc.roid as 'roid', + rc.appid as 'appid', + rc.[value] as 'value', + Case When (Not rc.[value] is null) Then rd.dbiAP + '-' + rc.appid Else null End as 'AccPageID' + From RofstChild rc With (NoLock) + inner join RofstDatabase rd With (NoLock) on rc.RofstID = rd.RofstID and rc.dbiID = rd.dbiID; + + GO + + IF (@@Error = 0) PRINT 'View Creation: [vwRofstData_RofstChildren] Succeeded' + ELSE PRINT 'View Creation: [vwRofstData_RofstChildren] Error on Creation' + GO + + + /****** Object: View [dbo].[vwRofstData_RofstDatabases] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vwRofstData_RofstDatabases' AND type in (N'V')) + DROP VIEW [dbo].[vwRofstData_RofstDatabases] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 03/24/2024 + Description: (RofstData) Master View for RofstDatabases + ========================================================================================================== + */ + Create View [dbo].[vwRofstData_RofstDatabases] + As + + Select rd.RofstID as 'RofstID', + rd.dbiID as 'dbiID', + rd.dbiType as 'dbiType', + rd.dbiAW as 'dbiAW', + rd.dbiTitle as 'dbiTitle', + rd.dbiAP as 'dbiAP', + rd.ID as 'ID', + rd.ParentID as 'ParentID' + From RofstDatabase rd With (NoLock) + + + GO + + IF (@@Error = 0) PRINT 'View Creation: [vwRofstData_RofstDatabases] Succeeded' + ELSE PRINT 'View Creation: [vwRofstData_RofstDatabases] Error on Creation' + GO + + + /****** Object: View [dbo].[vwRofstData_RofstDefaultValues] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vwRofstData_RofstDefaultValues' AND type in (N'V')) + DROP VIEW [dbo].[vwRofstData_RofstDefaultValues] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 03/24/2024 + Description: (RofstData) Master View for Rofst Roid Default Values + ========================================================================================================== + */ + Create View [dbo].[vwRofstData_RofstDefaultValues] + As + + Select rdv.RofstID as 'RofstID', + rdv.roid as 'roid', + rdv.[value] as 'value', + rdv.AccPageID as 'AccPageID' + From RofstDefaultValue rdv With (NoLock) + + GO + + IF (@@Error = 0) PRINT 'View Creation: [vwRofstData_RofstDefaultValues] Succeeded' + ELSE PRINT 'View Creation: [vwRofstData_RofstDefaultValues] Error on Creation' + GO + + + /****** Object: View [dbo].[vwRofstData_RofstHeaders] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vwRofstData_RofstHeaders' AND type in (N'V')) + DROP VIEW [dbo].[vwRofstData_RofstHeaders] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 03/24/2024 + Description: (RofstData) Master View for RofstHeaders + ========================================================================================================== + */ + Create View [dbo].[vwRofstData_RofstHeaders] + As + + Select rh.RofstID as 'RofstID', + hs.RofstHeaderStatusID as 'RofstHeaderStatusID', + hs.RofstHeaderStatus as 'RofstHeaderStatus', + rh.hSize as 'hSize', + rh.hMonth as 'hMonth', + rh.hDay as 'hDay', + rh.hcYear as 'hcYear', + rh.hcMonth as 'hcMonth', + rh.hcDay as 'hcDay', + rh.hcHour as 'hcHour', + rh.hcMin as 'hcMin', + rh.hcSec as 'hcSec', + rh.hcHund as 'hcHund', + rh.LoadedDate as 'LoadedDate', + rh.CreateUserID as 'CreateUserID', + rh.CreateDate as 'CreateDate' + From RofstHeader rh With (NoLock) + inner join vwRofstData_RofstHeaderStatuses hs on hs.RofstHeaderStatusID = dbo.vefn_RofstDataGetLoadStatus(rh.RofstID) + + GO + + IF (@@Error = 0) PRINT 'View Creation: [vwRofstData_RofstHeaders] Succeeded' + ELSE PRINT 'View Creation: [vwRofstData_RofstHeaders] Error on Creation' + GO + + + /****** Object: View [dbo].[vwRofstData_RofstHeaderStatuses] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vwRofstData_RofstHeaderStatuses' AND type in (N'V')) + DROP VIEW [dbo].[vwRofstData_RofstHeaderStatuses] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 05/20/2022 + Description: (RofstData) Master View for RofstHeader Statuses + (0) Unknown (1) Not Loaded (2) In Progress (3) Load Complete (4) Load Failed + ========================================================================================================== + */ + Create View [dbo].[vwRofstData_RofstHeaderStatuses] + As + + Select '0' as 'RofstHeaderStatusID', 'Unknown' as 'RofstHeaderStatus' + Union All + Select '1' as 'RofstHeaderStatusID', 'Not Loaded' as 'RofstHeaderStatus' + Union All + Select '2' as 'RofstHeaderStatusID', 'In Progress' as 'RofstHeaderStatus' + Union All + Select '3' as 'RofstHeaderStatusID', 'Load Complete' as 'RofstHeaderStatus' + Union All + Select '4' as 'RofstHeaderStatusID', 'Load Failed' as 'RofstHeaderStatus' + + GO + + IF (@@Error = 0) PRINT 'View Creation: [vwRofstData_RofstHeaderStatuses] Succeeded' + ELSE PRINT 'View Creation: [vwRofstData_RofstHeaderStatuses] Error on Creation' + GO + + + + + /* + ---------------------------------------------------------------------------------- + Stored Procs: (Update Existing) + ---------------------------------------------------------------------------------- + [dbo].[updateROFst] + [dbo].[getROImage] + [dbo].[getROFstsByRODbID] + [dbo].[getROFsts] + [dbo].[getRoFstBySize] + [dbo].[getROFstByRODbID_DTS] + [dbo].[getROFst] + [dbo].[getRODb] + [dbo].[getJustROFst] + [dbo].[getFiguresByImageID] + [dbo].[getDocVersion] + */ + + + /****** Object: StoredProcedure [dbo].[updateROFst] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'updateROFst' AND type in (N'P')) + DROP PROCEDURE [dbo].[updateROFst] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: + Create Date: + Description: + ========================================================================================================== + */ + CREATE PROCEDURE [dbo].[updateROFst] + ( + @ROFstID int, + @RODbID int, + @ROLookup varbinary(MAX), + @Config nvarchar(MAX)=null, + @DTS datetime, + @UserID nvarchar(100), + @LastChanged timestamp, + @newLastChanged timestamp output + ) + WITH EXECUTE AS OWNER + AS + BEGIN TRY -- Try Block + BEGIN TRANSACTION + UPDATE [ROFsts] + SET + [RODbID]=@RODbID, + --[ROLookup]=@ROLookup, + [Config]=@Config, + [DTS]=@DTS, + [UserID]=@UserID + WHERE [ROFstID]=@ROFstID AND [LastChanged]=@LastChanged + IF @@ROWCOUNT = 0 + BEGIN + IF NOT exists(select * from [ROFsts] WHERE [ROFstID]=@ROFstID) + RAISERROR('ROFst record has been deleted by another user', 16, 1) + ELSE + RAISERROR('ROFst has been edited by another user', 16, 1) + END + + SELECT @newLastChanged=[LastChanged] + FROM [ROFsts] WHERE [ROFstID]=@ROFstID + + IF( @@TRANCOUNT > 0 ) COMMIT + END TRY + BEGIN CATCH -- Catch Block + IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level + ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback + EXEC vlnErrorHandler + END CATCH + + GO + + IF (@@Error = 0) PRINT 'Procedure Creation: [updateROFst] Succeeded' + ELSE PRINT 'Procedure Creation: [updateROFst] Error on Creation' + GO + + + + + /****** Object: StoredProcedure [dbo].[getROImage] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'getROImage' AND type in (N'P')) + DROP PROCEDURE [dbo].[getROImage] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: + Create Date: + Description: + ========================================================================================================== + */ + CREATE PROCEDURE [dbo].[getROImage] + ( + @ImageID int + ) + WITH EXECUTE AS OWNER + AS + SELECT + [ImageID], + [RODbID], + [FileName], + [Content], + [Config], + [DTS], + [UserID], + [LastChanged], + (SELECT COUNT(1) FROM [Figures] WHERE [Figures].[ImageID]=[ROImages].[ImageID]) [FigureCount] + FROM [ROImages] + WHERE [ImageID]=@ImageID + + SELECT + [Figures].[FigureID], + [Figures].[ROFstID], + [Figures].[ImageID], + [Figures].[Config], + [Figures].[DTS], + [Figures].[UserID], + [Figures].[LastChanged], + [ROFsts].[RODbID] [ROFst_RODbID], + --[ROFsts].[ROLookup] [ROFst_ROLookup], + null as [ROFst_ROLookup], + [ROFsts].[Config] [ROFst_Config], + [ROFsts].[DTS] [ROFst_DTS], + [ROFsts].[UserID] [ROFst_UserID] + FROM [Figures] + JOIN [ROFsts] ON + [ROFsts].[ROFstID]=[Figures].[ROFstID] + WHERE + [Figures].[ImageID]=@ImageID + + RETURN + GO + + IF (@@Error = 0) PRINT 'Procedure Creation: [getROImage] Succeeded' + ELSE PRINT 'Procedure Creation: [getROImage] Error on Creation' + GO + + + + + /****** Object: StoredProcedure [dbo].[getROFstsByRODbID] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'getROFstsByRODbID' AND type in (N'P')) + DROP PROCEDURE [dbo].[getROFstsByRODbID] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: + Create Date: + Description: + ========================================================================================================== + */ + CREATE PROCEDURE [dbo].[getROFstsByRODbID] + ( + @RODbID int + ) + WITH EXECUTE AS OWNER + AS + + SELECT + [ROFsts].[ROFstID], + [ROFsts].[RODbID], + --[ROFsts].[ROLookup], + null as [ROLookup], + [ROFsts].[Config], + [ROFsts].[DTS], + [ROFsts].[UserID], + [ROFsts].[LastChanged], + (SELECT COUNT(1) FROM [Associations] WHERE [Associations].[ROFstID]=[ROFsts].[ROFstID]) [AssociationCount], + (SELECT COUNT(1) FROM [Figures] WHERE [Figures].[ROFstID]=[ROFsts].[ROFstID]) [FigureCount] + FROM [ROFsts] + WHERE + [ROFsts].[RODbID]=@RODbID + + RETURN + GO + + IF (@@Error = 0) PRINT 'Procedure Creation: [getROFstsByRODbID] Succeeded' + ELSE PRINT 'Procedure Creation: [getROFstsByRODbID] Error on Creation' + GO + + + + + /****** Object: StoredProcedure [dbo].[getROFsts] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'getROFsts' AND type in (N'P')) + DROP PROCEDURE [dbo].[getROFsts] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: + Create Date: + Description: + ========================================================================================================== + */ + CREATE PROCEDURE [dbo].[getROFsts] + + WITH EXECUTE AS OWNER + AS + SELECT + [ROFstID], + [RODbID], + --[ROLookup], + null as [ROLookup], + [Config], + [DTS], + [UserID], + [LastChanged], + (SELECT Count(1) FROM [Associations] WHERE [Associations].[ROFstID]=[ROFsts].[ROFstID]) [AssociationCount], + (SELECT Count(1) FROM [Figures] WHERE [Figures].[ROFstID]=[ROFsts].[ROFstID]) [FigureCount] + FROM [ROFsts] + + RETURN + + GO + + IF (@@Error = 0) PRINT 'Procedure Creation: [getROFsts] Succeeded' + ELSE PRINT 'Procedure Creation: [getROFsts] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[getRoFstBySize] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'getRoFstBySize' AND type in (N'P')) + DROP PROCEDURE [dbo].[getRoFstBySize] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + Create PROCEDURE [dbo].[getRoFstBySize] + ( + @RODbID int, + @Len int + ) + WITH EXECUTE AS OWNER + AS + + select [ROFstID], + [RODbID], + --[ROLookup], + null as [ROLookup], + [Config], + [DTS], + [UserID], + [LastChanged], + (SELECT Count(1) FROM [Associations] WHERE [Associations].[ROFstID]=[ROFsts].[ROFstID]) [AssociationCount], + (SELECT Count(1) FROM [Figures] WHERE [Figures].[ROFstID]=[ROFsts].[ROFstID]) [FigureCount] + from [ROFsts] + where len(rolookup) = @len and [RODbID] = @RODbID + + RETURN + + GO + + IF (@@Error = 0) PRINT 'Procedure Creation: [getRoFstBySize] Succeeded' + ELSE PRINT 'Procedure Creation: [getRoFstBySize] Error on Creation' + GO + + + + + /****** Object: StoredProcedure [dbo].[getROFstByRODbID_DTS] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'getROFstByRODbID_DTS' AND type in (N'P')) + DROP PROCEDURE [dbo].[getROFstByRODbID_DTS] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: + Create Date: + Description: + ========================================================================================================== + */ + CREATE PROCEDURE [dbo].[getROFstByRODbID_DTS] + ( + @RODbID int, + @DTS datetime + ) + WITH EXECUTE AS OWNER + AS + SELECT + [ROFstID], + [RODbID], + --[ROLookup], + null as [ROLookup], + [Config], + [DTS], + [UserID], + [LastChanged], + (SELECT Count(1) FROM [Associations] WHERE [Associations].[ROFstID]=[ROFsts].[ROFstID]) [AssociationCount], + (SELECT Count(1) FROM [Figures] WHERE [Figures].[ROFstID]=[ROFsts].[ROFstID]) [FigureCount] + FROM [ROFsts] + WHERE [RODbID]=@RODbID AND [DTS]=@DTS + + RETURN + + GO + + IF (@@Error = 0) PRINT 'Procedure Creation: [getROFstByRODbID_DTS] Succeeded' + ELSE PRINT 'Procedure Creation: [getROFstByRODbID_DTS] Error on Creation' + GO + + + + + /****** Object: StoredProcedure [dbo].[getROFst] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'getROFst' AND type in (N'P')) + DROP PROCEDURE [dbo].[getROFst] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: + Create Date: + Description: + ========================================================================================================== + */ + CREATE PROCEDURE [dbo].[getROFst] + + ( + @ROFstID int + ) + WITH EXECUTE AS OWNER + AS + SELECT + [ROFstID], + [RODbID], + -- [ROLookup], + null as [ROLookup], + [Config], + [DTS], + [UserID], + [LastChanged], + (SELECT Count(1) FROM [Associations] WHERE [Associations].[ROFstID]=[ROFsts].[ROFstID]) [AssociationCount], + (SELECT Count(1) FROM [Figures] WHERE [Figures].[ROFstID]=[ROFsts].[ROFstID]) [FigureCount] + FROM [ROFsts] + WHERE [ROFstID]=@ROFstID + + SELECT + [Associations].[AssociationID], + [Associations].[VersionID], + [Associations].[ROFstID], + [Associations].[Config], + [Associations].[DTS], + [Associations].[UserID], + [Associations].[LastChanged], + [DocVersions].[FolderID] [DocVersion_FolderID], + [DocVersions].[VersionType] [DocVersion_VersionType], + [DocVersions].[Name] [DocVersion_Name], + [DocVersions].[Title] [DocVersion_Title], + [DocVersions].[ItemID] [DocVersion_ItemID], + [DocVersions].[FormatID] [DocVersion_FormatID], + [DocVersions].[Config] [DocVersion_Config], + [DocVersions].[DTS] [DocVersion_DTS], + [DocVersions].[UserID] [DocVersion_UserID] + FROM [Associations] + JOIN [DocVersions] ON + [DocVersions].[VersionID]=[Associations].[VersionID] + WHERE + [Associations].[ROFstID]=@ROFstID + + + SELECT + [Figures].[FigureID], + [Figures].[ROFstID], + [Figures].[ImageID], + [Figures].[Config], + [Figures].[DTS], + [Figures].[UserID], + [Figures].[LastChanged], + [ROImages].[RODbID] [ROImage_RODbID], + [ROImages].[FileName] [ROImage_FileName], + [ROImages].[Content] [ROImage_Content], + [ROImages].[Config] [ROImage_Config], + [ROImages].[DTS] [ROImage_DTS], + [ROImages].[UserID] [ROImage_UserID] + FROM [Figures] + JOIN [ROImages] ON + [ROImages].[ImageID]=[Figures].[ImageID] + WHERE + [Figures].[ROFstID]=@ROFstID + + RETURN + GO + + IF (@@Error = 0) PRINT 'Procedure Creation: [getROFst] Succeeded' + ELSE PRINT 'Procedure Creation: [getROFst] Error on Creation' + GO + + + + + /****** Object: StoredProcedure [dbo].[getRODb] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'getRODb' AND type in (N'P')) + DROP PROCEDURE [dbo].[getRODb] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: + Create Date: + Description: + ========================================================================================================== + */ + CREATE PROCEDURE [dbo].[getRODb] + ( + @RODbID int + ) + WITH EXECUTE AS OWNER + AS + SELECT + [RODbID], + [ROName], + [FolderPath], + [DBConnectionString], + [Config], + [DTS], + [UserID], + [LastChanged], + (SELECT Count(1) FROM [DROUsages] WHERE [DROUsages].[RODbID]=[RODbs].[RODbID]) [DROUsageCount], + (SELECT Count(1) FROM [ROFsts] WHERE [ROFsts].[RODbID]=[RODbs].[RODbID]) [ROFstCount], + (SELECT Count(1) FROM [ROImages] WHERE [ROImages].[RODbID]=[RODbs].[RODbID]) [ROImageCount], + (SELECT Count(1) FROM [RoUsages] WHERE [RoUsages].[RODbID]=[RODbs].[RODbID]) [RoUsageCount] + FROM [RODbs] + WHERE [RODbID]=@RODbID + + SELECT + [DROUsages].[DROUsageID], + [DROUsages].[DocID], + [DROUsages].[ROID], + [DROUsages].[Config], + [DROUsages].[DTS], + [DROUsages].[UserID], + [DROUsages].[LastChanged], + [DROUsages].[RODbID], + [Documents].[LibTitle] [Document_LibTitle], + [Documents].[DocContent] [Document_DocContent], + [Documents].[DocAscii] [Document_DocAscii], + [Documents].[Config] [Document_Config], + [Documents].[DTS] [Document_DTS], + [Documents].[UserID] [Document_UserID], + [Documents].[FileExtension] [Document_FileExtension] + FROM [DROUsages] + JOIN [Documents] ON + [Documents].[DocID]=[DROUsages].[DocID] + WHERE + [DROUsages].[RODbID]=@RODbID + + + SELECT + [ROFsts].[ROFstID], + [ROFsts].[RODbID], + --[ROFsts].[ROLookup], + null as [ROLookup], + [ROFsts].[Config], + [ROFsts].[DTS], + [ROFsts].[UserID], + [ROFsts].[LastChanged] + FROM [ROFsts] + WHERE + [ROFsts].[RODbID]=@RODbID + + + SELECT + [ROImages].[ImageID], + [ROImages].[RODbID], + [ROImages].[FileName], + [ROImages].[Content], + [ROImages].[Config], + [ROImages].[DTS], + [ROImages].[UserID], + [ROImages].[LastChanged] + FROM [ROImages] + WHERE + [ROImages].[RODbID]=@RODbID + + + SELECT + [RoUsages].[ROUsageID], + [RoUsages].[ContentID], + [RoUsages].[ROID], + [RoUsages].[Config], + [RoUsages].[DTS], + [RoUsages].[UserID], + [RoUsages].[LastChanged], + [RoUsages].[RODbID], + [Contents].[Number] [Content_Number], + [Contents].[Text] [Content_Text], + [Contents].[Type] [Content_Type], + [Contents].[FormatID] [Content_FormatID], + [Contents].[Config] [Content_Config], + [Contents].[DTS] [Content_DTS], + [Contents].[UserID] [Content_UserID] + FROM [RoUsages] + JOIN [Contents] ON + [Contents].[ContentID]=[RoUsages].[ContentID] + WHERE + [RoUsages].[RODbID]=@RODbID + + RETURN + + GO + + IF (@@Error = 0) PRINT 'Procedure Creation: [getRODb] Succeeded' + ELSE PRINT 'Procedure Creation: [getRODb] Error on Creation' + GO + + + + + /****** Object: StoredProcedure [dbo].[getJustROFst] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'getJustROFst' AND type in (N'P')) + DROP PROCEDURE [dbo].[getJustROFst] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: + Create Date: + Description: + ========================================================================================================== + */ + CREATE PROCEDURE [dbo].[getJustROFst] + ( + @ROFstID int + ) + WITH EXECUTE AS OWNER + AS + SELECT + [ROFstID], + [RODbID], + --[ROLookup], + null as [ROLookup], + [Config], + [DTS], + [UserID], + [LastChanged], + (SELECT Count(1) FROM [Associations] WHERE [Associations].[ROFstID]=[ROFsts].[ROFstID]) [AssociationCount], + (SELECT Count(1) FROM [Figures] WHERE [Figures].[ROFstID]=[ROFsts].[ROFstID]) [FigureCount] + FROM [ROFsts] + WHERE [ROFstID]=@ROFstID + + RETURN + + GO + + IF (@@Error = 0) PRINT 'Procedure Creation: [getJustROFst] Succeeded' + ELSE PRINT 'Procedure Creation: [getJustROFst] Error on Creation' + GO + + + + + /****** Object: StoredProcedure [dbo].[getFiguresByImageID] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'getFiguresByImageID' AND type in (N'P')) + DROP PROCEDURE [dbo].[getFiguresByImageID] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: + Create Date: + Description: + ========================================================================================================== + */ + CREATE PROCEDURE [dbo].[getFiguresByImageID] + ( + @ImageID int + ) + WITH EXECUTE AS OWNER + AS + + SELECT + [Figures].[FigureID], + [Figures].[ROFstID], + [Figures].[ImageID], + [Figures].[Config], + [Figures].[DTS], + [Figures].[UserID], + [Figures].[LastChanged], + [ROFsts].[RODbID] [ROFst_RODbID], + --[ROFsts].[ROLookup] [ROFst_ROLookup], + null as [ROFst_ROLookup], + [ROFsts].[Config] [ROFst_Config], + [ROFsts].[DTS] [ROFst_DTS], + [ROFsts].[UserID] [ROFst_UserID] + FROM [Figures] + JOIN [ROFsts] ON + [ROFsts].[ROFstID]=[Figures].[ROFstID] + WHERE + [Figures].[ImageID]=@ImageID + + RETURN + GO + + IF (@@Error = 0) PRINT 'Procedure Creation: [getFiguresByImageID] Succeeded' + ELSE PRINT 'Procedure Creation: [getFiguresByImageID] Error on Creation' + GO + + + + + /****** Object: StoredProcedure [dbo].[getDocVersion] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'getDocVersion' AND type in (N'P')) + DROP PROCEDURE [dbo].[getDocVersion] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: + Create Date: + Description: + ========================================================================================================== + */ + CREATE PROCEDURE [dbo].[getDocVersion] + ( + @VersionID int + ) + WITH EXECUTE AS OWNER + AS + SELECT + [VersionID], + [FolderID], + [VersionType], + [Name], + [Title], + [ItemID], + [FormatID], + [Config], + [DTS], + [UserID], + [LastChanged], + (SELECT COUNT(1) FROM [Associations] WHERE [Associations].[VersionID]=[DocVersions].[VersionID]) [AssociationCount] + FROM [DocVersions] + WHERE [VersionID]=@VersionID + + SELECT + [Associations].[AssociationID], + [Associations].[VersionID], + [Associations].[ROFstID], + [Associations].[Config], + [Associations].[DTS], + [Associations].[UserID], + [Associations].[LastChanged], + [ROFsts].[RODbID] [ROFst_RODbID], + --[ROFsts].[ROLookup] [ROFst_ROLookup], + null as [ROFst_ROLookup], + [ROFsts].[Config] [ROFst_Config], + [ROFsts].[DTS] [ROFst_DTS], + [ROFsts].[UserID] [ROFst_UserID] + FROM [Associations] + JOIN [ROFsts] ON + [ROFsts].[ROFstID]=[Associations].[ROFstID] + WHERE + [Associations].[VersionID]=@VersionID + + RETURN + GO + + IF (@@Error = 0) PRINT 'Procedure Creation: [getDocVersion] Succeeded' + ELSE PRINT 'Procedure Creation: [getDocVersion] Error on Creation' + GO + + + + /* + ---------------------------------------------------------------------------------- + Stored Procs: (Create New) + ---------------------------------------------------------------------------------- + [dbo].[vesp_RofstHeaderInsert] + [dbo].[vesp_RofstHeaderFinalizeLoad] + [dbo].[vesp_RofstDataSearch] + [dbo].[vesp_RofstDataGetValueDifferences] + [dbo].[vesp_RofstDataGetRofstByID] + [dbo].[vesp_RofstDataGetHeaderRofstByID] + [dbo].[vesp_RofstDataGetDatabases] + [dbo].[vesp_RofstDataGetDatabaseByID] + [dbo].[vesp_RofstDataGetChildrenByType] + [dbo].[vesp_RofstDataGetChildrenByRoid] + [dbo].[vesp_RofstDataGetChildrenByRofstID] + [dbo].[vesp_RofstDataGetChildrenByID] + [dbo].[vesp_RofstDataGetChildByRoid] + [dbo].[vesp_RofstDataGetChildByID] + [dbo].[vesp_RofstDataGetChildByAccPageID] + [dbo].[vesp_RofstDatabaseInsert] + [dbo].[vesp_RofstChildInsert] + */ + + + /****** Object: StoredProcedure [dbo].[vesp_RofstHeaderInsert] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstHeaderInsert' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstHeaderInsert] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Inserts New Rofst Header Record + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstHeaderInsert] + ( + @RofstID Int, + @hSize Int, + @hMonth Int, + @hDay Int, + @hcYear Int, + @hcMonth Int, + @hcDay Int, + @hcHour Int, + @hcMin Int, + @hcSec Int, + @hcHund Int, + @UserID VarChar(50) + ) + With Execute as Owner + As + Begin + + -- Clear Existing Values (If Any) + Delete From RofstHeader Where RofstID = @RofstID; + + -- Create RofstHeader records and Set LoadedDate to null + Insert Into RofstHeader (RofstID, hSize, hMonth, hDay, hcYear, hcMonth, hcDay, hcHour, hcMin, hcSec, hcHund, LoadedDate, CreateUserID, CreateDate) + Values (@RofstID, @hSize, @hMonth, @hDay, @hcYear, @hcMonth, @hcDay, @hcHour, @hcMin, @hcSec, @hcHund, null, @UserID, GetDate()); + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstHeaderInsert] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstHeaderInsert] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstHeaderFinalizeLoad] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstHeaderFinalizeLoad' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstHeaderFinalizeLoad] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Finalizes Rofst Header Record / Updates LoadedDate if Success + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstHeaderFinalizeLoad] + ( + @RofstID Int + ) + With Execute as Owner + As + Begin + + -- Set LoadedDate on RofstHeader + Update RofstHeader + Set LoadedDate = GetDate() + Where RofstID = @RofstID; + + -- Rebuild/Reorganize Indexes + Exec [dbo].[vesp_UtilityCheckIndexes] 20.0, 5.0, 0, 1; + + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstHeaderFinalizeLoad] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstHeaderFinalizeLoad] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataSearch] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataSearch' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDataSearch] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: RO Default Value Search + + @SearchTypeID => (1) Starts With (2) Ends With (3) Contains (4) Exact Match + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataSearch] + ( + @RofstID int, + @Value VarChar(Max) = null, + @SearchTypeID Int = 1, -- Starts With + @MaxNumOfRecords Int = null + ) + With Execute as Owner + As + Begin + + -- Remove any leading/trailing white spaces + Set @Value = dbo.vefn_Clean( @Value, 0, null ); + + -- Escape any % signs in the search value + Set @Value = Replace( @Value, '%', '[%]' ); + + -- Format search value + If (Len(@Value) = 0) Set @Value = null; + + -- Create Temp Results Table + Create Table #SearchResults + (roid VarChar(50) Not Null, [value] VarChar(Max), RowNum Int Not Null Primary Key); + + -- Select roids/values based on search criteria + Insert Into #SearchResults (roid, [value], RowNum) + Select rdv.roid, + rdv.[value], + Row_Number() Over (Order By rdv.[value] Asc, rdv.roid Asc) as 'RowNum' + From vwRofstData_RofstDefaultValues rdv + Where rdv.RofstID = @RofstID + And ((@Value is null) + Or (@SearchTypeID = 1 And rdv.[value] like @Value + '%') -- Starts With + Or (@SearchTypeID = 2 And rdv.[value] like '%' + @Value) -- Ends With + Or (@SearchTypeID = 3 And rdv.[value] like '%' + @Value + '%') -- Contains + Or (@SearchTypeID = 4 And rdv.[value] = @Value)) -- Exact Match + Order By rdv.[value] Asc, rdv.roid Asc + Option (Recompile); + + -- Return the specified number of results + Select sr.roid, sr.[value] + From #SearchResults sr + Where (@MaxNumOfRecords is null Or sr.RowNum <= @MaxNumOfRecords) + Order By sr.RowNum Asc; + + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataSearch] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataSearch] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataGetValueDifferences] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataGetValueDifferences' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDataGetValueDifferences] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Gets Value Differences between (2) Rofst (Ro.fst) Files + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataGetValueDifferences] + ( + @OriginalRofstID Int, + @CurrentRofstID Int + ) + With Execute as Owner + As + Begin + + Declare @Differences Table (OriginalRoid VarChar(25), OriginalValue VarChar(Max), + CurrentRoid VarChar(25), CurrentValue VarChar(Max)); + + + With OriginalRofst as + ( + Select rc.roid, rc.[value] + From vwRofstData_RofstChildren rc + Where rc.RofstID = @OriginalRofstID + And Not rc.[value] is null + + ), CurrentRofst as ( + + Select rc.roid, rc.[value] + From vwRofstData_RofstChildren rc + Where rc.RofstID = @CurrentRofstID + And Not rc.[value] is null + ) + Insert Into @Differences (OriginalRoid, OriginalValue, CurrentRoid, CurrentValue) + Select o.roid, o.[value], c.roid, c.[value] + From OriginalRofst o + left outer join CurrentRofst c on c.roid = o.roid + Where o.[value] <> c.[value]; + + + Select OriginalRoid as 'Roid', + Case When (CurrentValue is null) Then 1 Else 0 End as 'IsDeleted', + Case When (Not CurrentValue is null) Then 1 Else 0 End as 'IsModified' + From @Differences; + + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataGetValueDifferences] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataGetValueDifferences] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataGetRofstByID] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataGetRofstByID' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDataGetRofstByID] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Gets Rofsts Info by ID + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataGetRofstByID] + ( + @RofstID int, + @IncludeRoLookup Bit + ) + With Execute as Owner + As + Begin + + Select r.ROFstID, + r.RODbID, + Case (@IncludeRoLookup) When 1 Then r.ROLookup Else null End as 'ROLookup', + r.DTS, + r.UserID, + r.LastChanged + From ROFsts r with (NoLock) + Where r.RofstID = @RofstID; + + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataGetRofstByID] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataGetRofstByID] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataGetHeaderRofstByID] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataGetHeaderRofstByID' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDataGetHeaderRofstByID] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Gets Rofst Header Info by ID + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataGetHeaderRofstByID] + ( + @RofstID int + ) + With Execute as Owner + As + Begin + + Select rh.RofstID as 'RofstID', + rh.RofstHeaderStatusID as 'RofstHeaderStatusID', + rh.RofstHeaderStatus as 'RofstHeaderStatus', + rh.hSize as 'hSize', + rh.hMonth as 'hMonth', + rh.hDay as 'hDay', + rh.hcYear as 'hcYear', + rh.hcMonth as 'hcMonth', + rh.hcDay as 'hcDay', + rh.hcHour as 'hcHour', + rh.hcMin as 'hcMin', + rh.hcSec as 'hcSec', + rh.hcHund as 'hcHund', + rh.LoadedDate as 'LoadedDate', + rh.CreateUserID as 'CreateUserID', + rh.CreateDate as 'CreateDate' + From vwRofstData_RofstHeaders rh + Where rh.RofstID = @RofstID; + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataGetHeaderRofstByID] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataGetHeaderRofstByID] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataGetDatabases] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataGetDatabases' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDataGetDatabases] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Gets all Rofst Databases for a specified Rofst File + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataGetDatabases] + ( + @RofstID int + ) + With Execute as Owner + As + Begin + + Select rd.RofstID, + rd.dbiID, + rd.dbiType, + rd.dbiAW, + rd.dbiTitle, + rd.dbiAP, + rd.ID, + rd.ParentID + From vwRofstData_RofstDatabases rd + Where rd.RofstID = @RofstID + Order By rd.dbiID Asc; + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataGetDatabases] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataGetDatabases] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataGetDatabaseByID] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataGetDatabaseByID' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDataGetDatabaseByID] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Gets Rofst Database Info by ID + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataGetDatabaseByID] + ( + @RofstID int, + @dbiID int + ) + With Execute as Owner + As + Begin + + Select rd.RofstID, + rd.dbiID, + rd.dbiType, + rd.dbiAW, + rd.dbiTitle, + rd.dbiAP, + rd.ID, + rd.ParentID + From vwRofstData_RofstDatabases rd + Where rd.RofstID = @RofstID + And rd.dbiID = @dbiID; + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataGetDatabaseByID] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataGetDatabaseByID] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataGetChildrenByType] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataGetChildrenByType' AND type in (N'P')) + DROP PROCEDURE[dbo].[vesp_RofstDataGetChildrenByType] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Gets Rofst Children Info by Type + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataGetChildrenByType] + ( + @RofstID int, + @ValueTypes VarChar(Max) + ) + With Execute as Owner + As + Begin + + -- Remove any leading/trailing white spaces + Set @ValueTypes = dbo.vefn_Clean( @ValueTypes, 0, null ); + + -- Format search value + If (Len(@ValueTypes) = 0) Set @ValueTypes = null; + + With ValueTypes as + ( + Select Cast(x.ListValue as Int) as 'ListValue' + From dbo.vefn_ParseStringListToTable(@ValueTypes, ',') as x + ) + Select rc.ROFstID, + rc.dbiID, + rc.ID, + rc.ParentID, + rc.[type], + rc.title, + rc.roid, + rc.appid, + rc.[value], + rc.AccPageID + From vwRofstData_RofstChildren rc + Left outer join ValueTypes vt on vt.ListValue = rc.[type] + Where rc.RofstID = @RofstID + And Not rc.[value] is null + And (@ValueTypes is null Or Not vt.ListValue is null) + Option (Recompile); + + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataGetChildrenByType] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataGetChildrenByType] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataGetChildrenByRoid] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataGetChildrenByRoid' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDataGetChildrenByRoid] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Gets Rofst Children (RoChild) Info by Roid + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataGetChildrenByRoid] + ( + @RofstID int, + @Roid VarChar(50) + ) + With Execute as Owner + As + Begin + + With RoParent as + ( + Select RofstID, dbiID, ID, [type], title, roid + From vwRofstData_RofstChildren + Where RofstID = @RofstID And roid = @Roid + ) + Select rc.RofstID, + rc.dbiID, + -- Ro Parent Info + rp.[type] as 'ParentType', + rp.title as 'ParentTitle', + rp.roid as 'ParentRoid', + -- Ro Child Info + rc.ID, + rc.ParentID, + rc.[type], + rc.title, + rc.roid, + rc.appid, + rc.[value], + rc.AccPageID + From RoParent rp + inner join vwRofstData_RofstChildren rc on rc.RofstID = rp.RofstID and rc.dbiID = rp.dbiID and rc.ParentID = rp.ID + Order By rc.ID Asc; + + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataGetChildrenByRoid] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataGetChildrenByRoid] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataGetChildrenByRofstID] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataGetChildrenByRofstID' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDataGetChildrenByRofstID] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Gets All Rofst Children Info by Rofst ID + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataGetChildrenByRofstID] + ( + @RofstID int + ) + With Execute as Owner + As + Begin + + Select rc.RofstID, + rc.dbiID, + rc.ID, + rc.ParentID, + rc.[type], + rc.title, + rc.roid, + rc.appid, + rc.[value], + rc.AccPageID + From vwRofstData_RofstChildren rc + Where rc.RofstID = @RofstID + And Not rc.[value] is null + Order By rc.dbiID Asc, rc.[type] Asc, rc.roid Asc; + + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataGetChildrenByRofstID] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataGetChildrenByRofstID] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataGetChildrenByID] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataGetChildrenByID' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDataGetChildrenByID] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Gets Rofst Children Info by DbiID and Object ID + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataGetChildrenByID] + ( + @RofstID int, + @DbiID int, + @ID Int + ) + With Execute as Owner + As + Begin + + + Select rc.RofstID, + rc.dbiID, + rc.ID, + rc.ParentID, + rc.[type], + rc.title, + rc.roid, + rc.appid, + rc.[value], + rc.AccPageID + From vwRofstData_RofstChildren rc + Where rc.RofstID = @RofstID + And rc.dbiID = @DbiID + And rc.ParentID = @ID + Order By rc.ID Asc; + + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataGetChildrenByID] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataGetChildrenByID] Error on Creation' + GO + + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataGetChildByRoid] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataGetChildByRoid' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDataGetChildByRoid] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Gets Rofst Child Info by Roid + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataGetChildByRoid] + ( + @RofstID int, + @Roid VarChar(50) + ) + With Execute as Owner + As + Begin + + Select rc.ROFstID, + rc.dbiID, + rc.ID, + rc.ParentID, + rc.[type], + rc.title, + rc.roid, + rc.appid, + rc.[value], + rc.AccPageID + From vwRofstData_RofstChildren rc + Where rc.RofstID = @RofstID + And rc.roid = @Roid; + + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataGetChildByRoid] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataGetChildByRoid] Error on Creation' + GO + + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataGetChildByID] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataGetChildByID' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDataGetChildByID] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Gets Rofst Child Info by dbiID and Object ID + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataGetChildByID] + ( + @RofstID int, + @DbiID int, + @ID Int + ) + With Execute as Owner + As + Begin + + Select rc.RofstID, + rc.dbiID, + rc.ID, + rc.ParentID, + rc.[type], + rc.title, + rc.roid, + rc.appid, + rc.[value], + rc.AccPageID + From vwRofstData_RofstChildren rc + Where rc.RofstID = @RofstID + And rc.dbiID = @DbiID + And rc.ID = @ID; + + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataGetChildByID] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataGetChildByID] Error on Creation' + GO + + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDataGetChildByAccPageID] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDataGetChildByAccPageID' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDataGetChildByAccPageID] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Gets Rofst Child Info by AccPageID + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDataGetChildByAccPageID] + ( + @RofstID int, + @AccPageID VarChar(50) + ) + With Execute as Owner + As + Begin + + Select rc.ROFstID, + rc.dbiID, + rc.ID, + rc.ParentID, + rc.[type], + rc.title, + rc.roid, + rc.appid, + rc.[value], + rc.AccPageID + From vwRofstData_RofstChildren rc + Where rc.RofstID = @RofstID + And rc.AccPageID = @AccPageID; + + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDataGetChildByAccPageID] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDataGetChildByAccPageID] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstDatabaseInsert] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstDatabaseInsert' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstDatabaseInsert] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Inserts New Rofst Database Record + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstDatabaseInsert] + ( + @RofstID Int, + @dbiID Int, + @dbiType Int, + @dbiAW Int, + @dbiTitle VarChar(Max), + @dbiAP VarChar(Max), + @ID Int, + @ParentID Int + ) + With Execute as Owner + As + Begin + + + Insert Into RofstDatabase (RofstID, dbiID, dbiType, dbiAW, dbiTitle, dbiAP, ID, ParentID) + Values (@RofstID, @dbiID, @dbiType, @dbiAW, @dbiTitle, @dbiAP, @ID, @ParentID ); + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstDatabaseInsert] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstDatabaseInsert] Error on Creation' + GO + + + + /****** Object: StoredProcedure [dbo].[vesp_RofstChildInsert] Script Date: 06/23/2022 ******/ + If Exists(SELECT * FROM sys.objects Where name = 'vesp_RofstChildInsert' AND type in (N'P')) + DROP PROCEDURE [dbo].[vesp_RofstChildInsert] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + + /***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2020 - Volian Enterprises, Inc. All rights reserved. + *****************************************************************************/ + /* + ========================================================================================================== + Author: Jake Ropar + Create Date: 06/23/2022 + Description: Inserts New Rofst Child Record / Default Values + ========================================================================================================== + */ + Create Procedure [dbo].[vesp_RofstChildInsert] + ( + @RofstID Int, + @ID Int, + @ParentID Int, + @dbiID Int, + @type Int, + @title VarChar(Max), + @roid VarChar(50), + @appid VarChar(Max) = null, + @value VarChar(Max) = null + ) + With Execute as Owner + As + Begin + + Declare @AccPageID VarChar(Max) = null; + Declare @DefaultValues VarChar(Max); + + + -- Create Rofst Child/Group Record + Insert Into RofstChild (RofstID, ID, ParentID, dbiID, [type], title, roid, appid, [value]) + Values (@RofstID, @ID, @ParentID, @dbiID, @type, @title, @roid, @appid, @value); + + + -- Check for appid, if exists, then insert the default value for each return type if multi-value + If (Len(@appid) > 0) + Begin + + -- Get Accessory Page ID + Select @AccPageID = Concat(d.dbiAP, '-', @appid) + From RofstDatabase d with (NoLock) + Where d.RofstID = @RofstID And d.dbiID = @dbiID; + + -- Insert Rofst Default Value (Parent RoChild) [roid = 12] + Insert Into RofstDefaultValue (RofstID, roid, [value], AccPageID) + Values (@RofstID, @roid, Replace(@title, '\u160?', ' '), @AccPageID); + + -- Insert Rofst Default Value(s) (Children RoChild) [roid = 16] (Do Not Insert Duplicates) + Select @DefaultValues = Replace(dbo.vefn_RofstDataReplaceVars(@value), '{', ''); + + With ChildrenValues as + ( + Select (x.ListPosition + 40) as 'OffsetIndex', + Case When (PatIndex('%=%', x.ListValue) > 0) Then Right(x.ListValue, Len(x.ListValue)-PatIndex('%=%', x.ListValue)) Else x.ListValue End as 'DefaultValue' + From [dbo].[vefn_ParseStringListToTable](@DefaultValues, '}') x + Where Len(x.ListValue) > 0 + ) + Insert Into RofstDefaultValue (RofstID, roid, [value], AccPageID) + Select @RofstID as 'RofstID', + Concat(@roid, Cast(Format(Min(OffsetIndex), 'D4') as VarChar(4))) as 'roid', + DefaultValue as 'value', + null as 'AccPageID' + From ChildrenValues + Group By DefaultValue + Order By Min(OffsetIndex) Asc + + End -- (Len(@appid) > 0) + + + Return; + End + Go + + IF (@@Error = 0) PRINT 'Procedure Creation: [vesp_RofstChildInsert] Succeeded' + ELSE PRINT 'Procedure Creation: [vesp_RofstChildInsert] Error on Creation' + GO + + + + + +/* +========================================================================================================== + End: B2022-026 RO Memory reduction coding (Jakes Merge) [Version 2.0] +========================================================================================================== +*/ + + ----------------------------------------------------------------------------- /* --------------------------------------------------------------------------- @@ -17427,6 +20059,14 @@ GO --------------------------------------------------------------------------- */ ----------------------------------------------------------------------------- +-- Rebuild / Reorganize All Indexes +exec [dbo].[vesp_UtilityCheckIndexes]; + +IF (@@Error = 0) PRINT 'Running vesp_UtilityCheckIndexes Succeeded' +ELSE PRINT 'Running vesp_UtilityCheckIndexes Failed to Execute' +GO + + IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vesp_GetSQLCodeRevision]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) DROP PROCEDURE [vesp_GetSQLCodeRevision]; GO @@ -17445,8 +20085,8 @@ BEGIN TRY -- Try Block DECLARE @RevDate varchar(255) DECLARE @RevDescription varchar(255) - set @RevDate = '06/02/2022 12:30 PM' - set @RevDescription = 'getGridIds fix for table searches' + set @RevDate = '06/22/2022 5:30 PM' + set @RevDescription = 'ROFST Lookup / Memory Fixes (v2.0) -> [B2022-026 RO Memory reduction coding (Jakes Merge)]' Select cast(@RevDate as datetime) RevDate, @RevDescription RevDescription PRINT 'SQL Code Revision ' + @RevDate + ' - ' + @RevDescription