C2019-045: Fix length of procedure number for CCR to work
C2019-045: For enhanced procedures, allow modification of number & title
This commit is contained in:
@@ -15228,6 +15228,263 @@ IF (@@Error = 0) PRINT 'TableFunction Creation: vefn_SiblingAndChildrenItemsNew
|
||||
ELSE PRINT 'TableFunction Creation: vefn_SiblingAndChildrenItemsNew Error on Creation'
|
||||
GO
|
||||
|
||||
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[addItemChild]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
|
||||
DROP PROCEDURE [addItemChild];
|
||||
GO
|
||||
CREATE PROCEDURE [dbo].[addItemChild]
|
||||
(
|
||||
@ItemID int=null, @Number nvarchar(256)=null, @Text nvarchar(MAX)=null, @FormatID int=null, @Config nvarchar(MAX)=null,
|
||||
@FromType int=null, @Type int=null, @DTS datetime, @UserID nvarchar(100), @newItemID int output
|
||||
)
|
||||
WITH EXECUTE AS OWNER
|
||||
AS
|
||||
BEGIN TRY -- Try Block
|
||||
BEGIN TRANSACTION
|
||||
DECLARE @ChildID int, @ContentID int, @ParentContentID int, @LastChanged timestamp
|
||||
, @newLastChanged timestamp, @Error int, @Rowcount int, @ChildDeleted int
|
||||
SELECT @ChildID = pp.[ItemID],@ParentContentID = ii.ContentID, @LastChanged = pp.LastChanged
|
||||
FROM [ITEMS] ii
|
||||
LEFT JOIN [PARTS] pp on pp.ContentID=ii.ContentID and pp.FromType=@FromType
|
||||
WHERE ii.[ItemID]=@ItemID
|
||||
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[tblParts]') AND OBJECTPROPERTY(id,N'IsTable') = 1)
|
||||
BEGIN
|
||||
SELECT @ChildDeleted = pp.[ItemID],@ParentContentID = ii.ContentID, @LastChanged = pp.LastChanged
|
||||
FROM [ITEMS] ii
|
||||
LEFT JOIN [tblPARTS] pp on pp.ContentID=ii.ContentID and pp.FromType=@FromType
|
||||
WHERE ii.[ItemID]=@ItemID and pp.DeleteStatus > 0
|
||||
END
|
||||
EXECUTE AddContent @Number, @Text, @Type, @FormatID, @Config, @DTS, @UserID, @ContentID output, @newLastChanged output
|
||||
EXECUTE AddItem null, @ContentID, @DTS, @UserID , @newItemID output, @newLastChanged output
|
||||
IF @ChildID is null -- No existing child - Add Parts record
|
||||
BEGIN
|
||||
IF @ChildDeleted is not null
|
||||
BEGIN
|
||||
-- INSERT INTO [PartAudits] ([ContentID],[FromType],[ItemID],[DTS],[UserID],[DeleteStatus])
|
||||
-- SELECT [ContentID],[FromType],[ItemID],[DTS],[UserID],[DeleteStatus] FROM [tblParts]
|
||||
-- WHERE ItemID = @ChildDeleted
|
||||
DELETE FROM [tblParts] WHERE ItemID = @ChildDeleted
|
||||
END
|
||||
EXECUTE AddPart @ParentContentID, @FromType, @newItemID, @DTS, @UserID, @newLastChanged output
|
||||
END
|
||||
ELSE -- Update existing Parts record
|
||||
BEGIN
|
||||
EXECUTE UpdatePart @ParentContentID, @FromType, @newItemID, @DTS, @UserID, @LastChanged, @newLastChanged output
|
||||
UPDATE [Items] SET [PreviousID]=@newItemID WHERE [ItemID]=@ChildID
|
||||
-- Update content records for the transitions
|
||||
Update CC
|
||||
Set Text = DBO.vefn_FixTransitionText(Text,TT.TransitionID,TT.TranType,TT.ToID,TT.RangeID,@ItemID,@newItemID)
|
||||
From CONTENTS CC
|
||||
JOIN Transitions TT ON TT.FromID = CC.ContentID
|
||||
WHERE TT.ToID = @ChildID OR TT.RangeID = @ChildID
|
||||
-- Update transitions that pointed to @ItemID to point to @newItemID
|
||||
Update TRANSITIONS
|
||||
Set ToID = CASE ToID WHEN @ChildID THEN @newItemID ELSE ToID END,
|
||||
RangeID = CASE RangeID WHEN @ChildID THEN @newItemID ELSE RangeID END
|
||||
WHERE ToID = @ChildID OR RangeID = @ChildID
|
||||
-- Add 'Verification Required' AnnotationType
|
||||
DECLARE @typeID int
|
||||
SELECT @typeID = TypeID from AnnotationTypes where Name = 'Verification Required'
|
||||
IF(@typeID IS NULL)
|
||||
BEGIN
|
||||
INSERT INTO [AnnotationTypes] ([Name],[UserID]) VALUES ('Verification Required','Volian')
|
||||
SELECT @typeID = SCOPE_IDENTITY()
|
||||
END
|
||||
-- Add "Verification Required" Annotation for each Transition that points to @newItemID or @NextID
|
||||
-- I don't expect to see any transitions that point to @ChildID. They should have changed in
|
||||
-- the update above to point to @newItemID. This is here for consistency with the other insert
|
||||
-- stored procedures
|
||||
INSERT INTO [Annotations] ([ItemID],[TypeID],[SearchText],[UserID])
|
||||
SELECT ItemID, @typeID,'Verify Transition Destination',@UserID
|
||||
FROM Items where CONTENTID in (SELECT FromID FROM TRANSITIONS
|
||||
where ToID IN(@ChildID,@newItemID) OR RangeID IN(@ChildID,@newItemID))
|
||||
-- Transition Text gets updated in ItemInsertExt.cs
|
||||
END
|
||||
IF( @@TRANCOUNT > 0 ) COMMIT
|
||||
PRINT 'Child Added ' + ltrim(str(@newItemID))
|
||||
EXECUTE GetItem @newItemID
|
||||
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
|
||||
-- Display the status of Proc creation
|
||||
IF (@@Error = 0) PRINT 'Procedure Creation: addItemChild Succeeded'
|
||||
ELSE PRINT 'Procedure Creation: addItemChild Error on Creation'
|
||||
GO
|
||||
|
||||
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[addItemSiblingAfter]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
|
||||
DROP PROCEDURE [addItemSiblingAfter];
|
||||
GO
|
||||
CREATE PROCEDURE [dbo].[addItemSiblingAfter]
|
||||
(
|
||||
@ItemID int=null, @Number nvarchar(256)=null, @Text nvarchar(MAX)=null, @FormatID int=null, @Config nvarchar(MAX)=null,
|
||||
@Type int=null, @DTS datetime, @UserID nvarchar(100), @newItemID int output
|
||||
)
|
||||
WITH EXECUTE AS OWNER
|
||||
AS
|
||||
BEGIN TRY -- Try Block
|
||||
BEGIN TRANSACTION
|
||||
DECLARE @NextID int, @ContentID int, @newLastChanged timestamp, @NewType int
|
||||
SELECT @NewType=ISNULL(@Type,[Type])
|
||||
FROM [ITEMS] II JOIN [CONTENTS] CC ON II.[ContentID]=CC.[ContentID]
|
||||
WHERE [ItemID]=@ItemID
|
||||
SELECT @NextID = [ItemID]
|
||||
FROM [ITEMS]
|
||||
WHERE [PreviousID]=@ItemID
|
||||
EXECUTE AddContent @Number, @Text, @NewType, @FormatID, @Config, @DTS, @UserID, @ContentID output, @newLastChanged output
|
||||
EXECUTE AddItem @ItemID, @ContentID, @DTS, @UserID , @newItemID output, @newLastChanged output
|
||||
UPDATE [ITEMS] SET [PreviousID]=@newItemID, [DTS]=@DTS, [UserID]=@UserID where [ItemID]=@NextID -- Should be UpdateItem
|
||||
-- Get a list of Transitions which need to change children of @ItemID that point to @NextID
|
||||
DECLARE @NextStepTransitions TABLE
|
||||
(
|
||||
[TransitionID] int PRIMARY KEY,
|
||||
[FromID] [int],
|
||||
[ToID] [int],
|
||||
[RangeID] [int],
|
||||
[TranType] [int],
|
||||
[Config] [nvarchar](max)
|
||||
)
|
||||
Insert into @NextStepTransitions select * from vefn_NextStepTransitions(@NextID,@ItemID)
|
||||
IF (SELECT COUNT(*) from @NextStepTransitions) > 0 -- Next Step Transitions
|
||||
BEGIN
|
||||
-- Update all transitions in the list to point to @newItemID
|
||||
Update TT
|
||||
Set TT.ToID = CASE TT.ToID WHEN @NextID THEN @newItemID ELSE TT.ToID END,
|
||||
TT.RangeID = CASE TT.RangeID WHEN @NextID THEN @newItemID ELSE TT.RangeID END
|
||||
From TRANSITIONS TT
|
||||
JOIN @NextStepTransitions NS ON NS.TransitionID = TT.TransitionID
|
||||
-- Update content records for the transitions
|
||||
Update CC
|
||||
Set Text = DBO.vefn_FixTransitionText(Text,NS.TransitionID,NS.TranType,NS.ToID,NS.RangeID,@NextID,@newItemID)
|
||||
From CONTENTS CC
|
||||
JOIN @NextStepTransitions NS ON NS.FromID = CC.ContentID
|
||||
END
|
||||
-- Add 'Verification Required' AnnotationType
|
||||
DECLARE @typeID int
|
||||
SELECT @typeID = TypeID from AnnotationTypes where Name = 'Verification Required'
|
||||
IF(@typeID IS NULL)
|
||||
BEGIN
|
||||
INSERT INTO [AnnotationTypes] ([Name],[UserID]) VALUES ('Verification Required','Volian')
|
||||
SELECT @typeID = SCOPE_IDENTITY()
|
||||
END
|
||||
-- Add "Verification Required" Annotation for each Transition that points to @newItemID or @NextID
|
||||
INSERT INTO [Annotations] ([ItemID],[TypeID],[SearchText],[UserID])
|
||||
SELECT ItemID, @typeID,'Verify Next Step Transition Destination',@UserID
|
||||
FROM Items where CONTENTID in (SELECT FromID FROM TRANSITIONS
|
||||
where ToID IN(@newItemID) OR RangeID IN(@newItemID))
|
||||
INSERT INTO [Annotations] ([ItemID],[TypeID],[SearchText],[UserID])
|
||||
SELECT ItemID, @typeID,'Verify Transition Destination',@UserID
|
||||
FROM Items where CONTENTID in (SELECT FromID FROM TRANSITIONS
|
||||
where ToID IN(@NextID) OR RangeID IN(@NextID))
|
||||
-- Transition Text gets updated in ItemInsertExt.cs
|
||||
IF( @@TRANCOUNT > 0 ) COMMIT
|
||||
EXECUTE GetItem @newItemID
|
||||
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
|
||||
-- Display the status of Proc creation
|
||||
IF (@@Error = 0) PRINT 'Procedure Creation: addItemSiblingAfter Succeeded'
|
||||
ELSE PRINT 'Procedure Creation: addItemSiblingAfter Error on Creation'
|
||||
GO
|
||||
|
||||
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[addItemSiblingBefore]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
|
||||
DROP PROCEDURE [addItemSiblingBefore];
|
||||
GO
|
||||
CREATE PROCEDURE [dbo].[addItemSiblingBefore]
|
||||
(
|
||||
@ItemID int=null, @Number nvarchar(256)=null, @Text nvarchar(MAX)=null, @FormatID int=null, @Config nvarchar(MAX)=null,
|
||||
@Type int=null, @DTS datetime, @UserID nvarchar(100), @newItemID int output
|
||||
)
|
||||
WITH EXECUTE AS OWNER
|
||||
AS
|
||||
BEGIN TRY -- Try Block
|
||||
BEGIN TRANSACTION
|
||||
DECLARE @PreviousID int, @ContentID int, @newLastChanged timestamp, @NewType int
|
||||
SELECT @PreviousID = [PreviousID], @NewType=ISNULL(@Type,[Type])
|
||||
FROM [ITEMS] II
|
||||
JOIN [CONTENTS] CC ON CC.[ContentID]=II.[CONTENTID]
|
||||
WHERE [ItemID]=@ItemID
|
||||
EXECUTE AddContent @Number, @Text, @NewType, @FormatID, @Config, @DTS, @UserID, @ContentID output, @newLastChanged output
|
||||
EXECUTE AddItem @PreviousID, @ContentID, @DTS, @UserID , @newItemID output, @newLastChanged output
|
||||
UPDATE [ITEMS] SET [PreviousID]=@newItemID where [ItemID]=@ItemID -- Should be UpdateItem
|
||||
UPDATE [PARTS] SET [ItemID]=@newItemID where [ItemID]=@ItemID -- Should be UpdatePart
|
||||
IF @PreviousID is null -- The step is replacing the first step
|
||||
BEGIN
|
||||
-- Update content records for the transitions
|
||||
Update CC
|
||||
Set Text = DBO.vefn_FixTransitionText(Text,TT.TransitionID,TT.TranType,TT.ToID,TT.RangeID,@ItemID,@newItemID)
|
||||
From CONTENTS CC
|
||||
JOIN Transitions TT ON TT.FromID = CC.ContentID
|
||||
WHERE TT.ToID = @ItemID OR TT.RangeID = @ItemID
|
||||
-- Update transitions that pointed to @ItemID to point to @newItemID
|
||||
Update TRANSITIONS
|
||||
Set ToID = CASE ToID WHEN @ItemID THEN @newItemID ELSE ToID END,
|
||||
RangeID = CASE RangeID WHEN @ItemID THEN @newItemID ELSE RangeID END
|
||||
WHERE ToID = @ItemID OR RangeID = @ItemID
|
||||
END
|
||||
ELSE -- Check for Transitions that point to the Next Step
|
||||
BEGIN
|
||||
-- Get a list of Transitions which need to change children of @ItemID that point to @NextID
|
||||
DECLARE @NextStepTransitions TABLE
|
||||
(
|
||||
[TransitionID] int PRIMARY KEY,
|
||||
[FromID] [int],
|
||||
[ToID] [int],
|
||||
[RangeID] [int],
|
||||
[TranType] [int],
|
||||
[Config] [nvarchar](max)
|
||||
)
|
||||
Insert into @NextStepTransitions select * from vefn_NextStepTransitions(@ItemID,@PreviousID)
|
||||
IF (SELECT COUNT(*) from @NextStepTransitions) > 0 -- Next Step Transitions
|
||||
BEGIN
|
||||
-- Update all transitions in the list to point to @newItemID
|
||||
Update TT
|
||||
Set TT.ToID = CASE TT.ToID WHEN @ItemID THEN @newItemID ELSE TT.ToID END,
|
||||
TT.RangeID = CASE TT.RangeID WHEN @ItemID THEN @newItemID ELSE TT.RangeID END
|
||||
From TRANSITIONS TT
|
||||
JOIN @NextStepTransitions NS ON NS.TransitionID = TT.TransitionID
|
||||
-- Update content records for the transitions
|
||||
Update CC
|
||||
Set Text = DBO.vefn_FixTransitionText(Text,NS.TransitionID,NS.TranType,NS.ToID,NS.RangeID,@ItemID,@newItemID)
|
||||
From CONTENTS CC
|
||||
JOIN @NextStepTransitions NS ON NS.FromID = CC.ContentID
|
||||
END
|
||||
END
|
||||
-- Add 'Verification Required' AnnotationType
|
||||
DECLARE @typeID int
|
||||
SELECT @typeID = TypeID from AnnotationTypes where Name = 'Verification Required'
|
||||
IF(@typeID IS NULL)
|
||||
BEGIN
|
||||
INSERT INTO [AnnotationTypes] ([Name],[UserID]) VALUES ('Verification Required','Volian')
|
||||
SELECT @typeID = SCOPE_IDENTITY()
|
||||
END
|
||||
-- Add "Verification Required" Annotation for each Transition that points to @newItemID or @NextID
|
||||
INSERT INTO [Annotations] ([ItemID],[TypeID],[SearchText],[UserID])
|
||||
SELECT ItemID, @typeID,'Verify Transition Destination',@UserID
|
||||
FROM Items where CONTENTID in (SELECT FromID FROM TRANSITIONS
|
||||
where ToID IN(@ItemID,@newItemID) OR RangeID IN(@ItemID,@newItemID))
|
||||
-- Transition Text gets updated in ItemInsertExt.cs
|
||||
IF( @@TRANCOUNT > 0 ) COMMIT
|
||||
PRINT 'Sibling Added Before ' + ltrim(str(@newItemID))
|
||||
EXECUTE GetItem @newItemID
|
||||
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
|
||||
-- Display the status of Proc creation
|
||||
IF (@@Error = 0) PRINT 'Procedure Creation: addItemSiblingBefore Succeeded'
|
||||
ELSE PRINT 'Procedure Creation: addItemSiblingBefore Error on Creation'
|
||||
GO
|
||||
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
/*
|
||||
@@ -15243,7 +15500,7 @@ GO
|
||||
|
||||
/*****************************************************************************
|
||||
Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
|
||||
Copyright 2017 - Volian Enterprises, Inc. All rights reserved.
|
||||
Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
|
||||
*****************************************************************************/
|
||||
CREATE PROCEDURE [dbo].[vesp_GetSQLCodeRevision]
|
||||
WITH EXECUTE AS OWNER
|
||||
@@ -15254,8 +15511,8 @@ BEGIN TRY -- Try Block
|
||||
set nocount on
|
||||
DECLARE @RevDate varchar(255)
|
||||
DECLARE @RevDescription varchar(255)
|
||||
set @RevDate = '12/11/2019 02:32 PM'
|
||||
set @RevDescription = 'Text Search Duplicate Primary Key Fix'
|
||||
set @RevDate = '12/13/2019 7:00 AM'
|
||||
set @RevDescription = 'Procedure number length when adding procedures'
|
||||
Select cast(@RevDate as datetime) RevDate, @RevDescription RevDescription
|
||||
PRINT 'SQL Code Revision ' + @RevDate + ' - ' + @RevDescription
|
||||
IF( @@TRANCOUNT > 0 ) COMMIT
|
||||
|
Reference in New Issue
Block a user