new settings to control conversion of approved data

fixed handling of this set only
deleted developer mode
add master slave menu item  (under development)
add loading of approved data to complete processing
remove background double-click event handler
added menu item for loading approved data
added menu item for master slave (under development)
added stored procedures and functions removed from BuildVEPROMS.sql
added purging of tables to support master slave (under development)
This commit is contained in:
Rich
2012-02-09 16:09:09 +00:00
parent f673a0a119
commit bcf31cdfa2
3 changed files with 349 additions and 307 deletions

View File

@@ -41,6 +41,37 @@ IF (@@Error = 0) PRINT 'Table Creation: DeleteLog Succeeded'
ELSE PRINT 'Table Creation: DeleteLog Error on Creation'
GO
/****** Object: StoredProcedure [vlnErrorHandler] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vlnErrorHandler]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [vlnErrorHandler];
GO
CREATE PROCEDURE [dbo].[vlnErrorHandler]
(@ExpectedCount int=-1
,@MessageFormat nvarchar(512)=N'Expected RowCount (%d) not met (%d)')
WITH EXECUTE AS OWNER
AS
BEGIN
DECLARE @ErrorMessage NVARCHAR(4000), @ErrorNumber INT, @ErrorSeverity INT, @ErrorState INT, @ErrorProcedure NVARCHAR(126)
, @ErrorLine INT, @RowCount INT;
SELECT @ErrorMessage = ERROR_MESSAGE(), @ErrorSeverity = ERROR_SEVERITY(), @ErrorState = ERROR_STATE(),@ErrorNumber = ERROR_NUMBER()
, @ErrorLine = ERROR_LINE(), @ErrorProcedure = ERROR_PROCEDURE(), @RowCount = @@RowCount;
IF @ErrorNumber > 0
BEGIN
IF @ErrorProcedure = OBJECT_NAME(@@PROCID) -- If the Procedure is the current procedure just pass the error message
RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState)
ELSE -- Add in the procedure name and line as well as the error number
RAISERROR (N'%s[%d] - (%d) %s', @ErrorSeverity, @ErrorState, @ErrorProcedure, @ErrorLine, @ErrorNumber, @ErrorMessage)
END
ELSE IF @ExpectedCount <> -1 AND @ExpectedCount <> @RowCount
RAISERROR (@MessageFormat, 16, 1, @ExpectedCount, @RowCount)
END
GO
-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: vlnErrorHandler Succeeded'
ELSE PRINT 'Procedure Creation: vlnErrorHandler Error on Creation'
GO
/****** Object: StoredProcedure [addAnnotation] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[addAnnotation]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [addAnnotation];
@@ -1086,6 +1117,264 @@ GO
IF (@@Error = 0) PRINT 'Procedure Creation: addItem Succeeded'
ELSE PRINT 'Procedure Creation: addItem Error on Creation'
GO
--HERE
/****** Object: StoredProcedure [addPart] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[addPart]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [addPart];
GO
CREATE PROCEDURE [dbo].[addPart]
(
@ContentID int,
@FromType int,
@ItemID int,
@DTS datetime,
@UserID nvarchar(100),
@newLastChanged timestamp output
)
WITH EXECUTE AS OWNER
AS
BEGIN TRY -- Try Block
BEGIN TRANSACTION
INSERT INTO [Parts]
(
[ContentID],
[FromType],
[ItemID],
[DTS],
[UserID]
)
VALUES
(
@ContentID,
@FromType,
@ItemID,
@DTS,
@UserID
)
SELECT @newLastChanged=[LastChanged]
FROM [Parts] WHERE [ContentID]=@ContentID AND [FromType]=@FromType
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
-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: addPart Succeeded'
ELSE PRINT 'Procedure Creation: addPart Error on Creation'
GO
/****** Object: StoredProcedure [updatePart] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[updatePart]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [updatePart];
GO
CREATE PROCEDURE [dbo].[updatePart]
(
@ContentID int,
@FromType int,
@ItemID int,
@DTS datetime,
@UserID nvarchar(100),
@LastChanged timestamp,
@newLastChanged timestamp output
)
WITH EXECUTE AS OWNER
AS
BEGIN TRY -- Try Block
BEGIN TRANSACTION
UPDATE [Parts]
SET
[ItemID]=@ItemID,
[DTS]=@DTS,
[UserID]=@UserID
WHERE [ContentID]=@ContentID AND [FromType]=@FromType AND [LastChanged]=@LastChanged
IF @@ROWCOUNT = 0
BEGIN
IF NOT exists(select * from [Parts] WHERE [ContentID]=@ContentID AND [FromType]=@FromType)
RAISERROR('Part record has been deleted by another user', 16, 1)
ELSE
RAISERROR('Part has been edited by another user', 16, 1)
END
SELECT @newLastChanged=[LastChanged]
FROM [Parts] WHERE [ContentID]=@ContentID AND [FromType]=@FromType
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
-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: updatePart Succeeded'
ELSE PRINT 'Procedure Creation: updatePart Error on Creation'
GO
/****** Object: StoredProcedure [getItem] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getItem]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [getItem];
GO
CREATE PROCEDURE [dbo].[getItem]
(
@ItemID int
)
WITH EXECUTE AS OWNER
AS
SELECT
[ItemID],
[PreviousID],
[ContentID],
[DTS],
[UserID],
[LastChanged],
(SELECT COUNT(*) FROM [Annotations] WHERE [Annotations].[ItemID]=[Items].[ItemID]) [AnnotationCount],
(SELECT COUNT(*) FROM [DocVersions] WHERE [DocVersions].[ItemID]=[Items].[ItemID]) [DocVersionCount],
(SELECT COUNT(*) FROM [Items] [Next] WHERE [Next].[PreviousID]=[Items].[ItemID]) [NextCount],
(SELECT COUNT(*) FROM [Parts] WHERE [Parts].[ItemID]=[Items].[ItemID]) [PartCount],
(SELECT COUNT(*) FROM [Transitions] WHERE [Transitions].[RangeID]=[Items].[ItemID]) [Transition_RangeIDCount],
(SELECT COUNT(*) FROM [Transitions] WHERE [Transitions].[ToID]=[Items].[ItemID]) [Transition_ToIDCount]
FROM [Items]
WHERE [ItemID]=@ItemID
SELECT
[Annotations].[AnnotationID],
[Annotations].[ItemID],
[Annotations].[TypeID],
[Annotations].[RtfText],
[Annotations].[SearchText],
[Annotations].[Config],
[Annotations].[DTS],
[Annotations].[UserID],
[Annotations].[LastChanged],
[AnnotationTypes].[Name] [AnnotationType_Name],
[AnnotationTypes].[Config] [AnnotationType_Config],
[AnnotationTypes].[DTS] [AnnotationType_DTS],
[AnnotationTypes].[UserID] [AnnotationType_UserID]
FROM [Annotations]
JOIN [AnnotationTypes] ON
[AnnotationTypes].[TypeID]=[Annotations].[TypeID]
WHERE
[Annotations].[ItemID]=@ItemID
SELECT
[DocVersions].[VersionID],
[DocVersions].[FolderID],
[DocVersions].[VersionType],
[DocVersions].[Name],
[DocVersions].[Title],
[DocVersions].[ItemID],
[DocVersions].[FormatID],
[DocVersions].[Config],
[DocVersions].[DTS],
[DocVersions].[UserID],
[DocVersions].[LastChanged],
[Folders].[ParentID] [Folder_ParentID],
[Folders].[DBID] [Folder_DBID],
[Folders].[Name] [Folder_Name],
[Folders].[Title] [Folder_Title],
[Folders].[ShortName] [Folder_ShortName],
[Folders].[FormatID] [Folder_FormatID],
[Folders].[ManualOrder] [Folder_ManualOrder],
[Folders].[Config] [Folder_Config],
[Folders].[DTS] [Folder_DTS],
[Folders].[UsrID] [Folder_UsrID]
FROM [DocVersions]
JOIN [Folders] ON
[Folders].[FolderID]=[DocVersions].[FolderID]
WHERE
[DocVersions].[ItemID]=@ItemID
SELECT
[Parts].[ContentID],
[Parts].[FromType],
[Parts].[ItemID],
[Parts].[DTS],
[Parts].[UserID],
[Parts].[LastChanged],
[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 [Parts]
JOIN [Contents] ON
[Contents].[ContentID]=[Parts].[ContentID]
WHERE
[Parts].[ItemID]=@ItemID
SELECT
[Transitions].[TransitionID],
[Transitions].[FromID],
[Transitions].[ToID],
[Transitions].[RangeID],
[Transitions].[IsRange],
[Transitions].[TranType],
[Transitions].[Config],
[Transitions].[DTS],
[Transitions].[UserID],
[Transitions].[LastChanged],
[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 [Transitions]
JOIN [Contents] ON
[Contents].[ContentID]=[Transitions].[FromID]
WHERE
[Transitions].[RangeID]=@ItemID
SELECT
[Transitions].[TransitionID],
[Transitions].[FromID],
[Transitions].[ToID],
[Transitions].[RangeID],
[Transitions].[IsRange],
[Transitions].[TranType],
[Transitions].[Config],
[Transitions].[DTS],
[Transitions].[UserID],
[Transitions].[LastChanged],
[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 [Transitions]
JOIN [Contents] ON
[Contents].[ContentID]=[Transitions].[FromID]
WHERE
[Transitions].[ToID]=@ItemID
RETURN
GO
-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: getItem Succeeded'
ELSE PRINT 'Procedure Creation: getItem Error on Creation'
GO
--HERE
/****** Object: StoredProcedure [addItemChild] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[addItemChild]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
@@ -1410,57 +1699,6 @@ IF (@@Error = 0) PRINT 'Procedure Creation: addMembership Succeeded'
ELSE PRINT 'Procedure Creation: addMembership Error on Creation'
GO
/****** Object: StoredProcedure [addPart] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[addPart]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [addPart];
GO
CREATE PROCEDURE [dbo].[addPart]
(
@ContentID int,
@FromType int,
@ItemID int,
@DTS datetime,
@UserID nvarchar(100),
@newLastChanged timestamp output
)
WITH EXECUTE AS OWNER
AS
BEGIN TRY -- Try Block
BEGIN TRANSACTION
INSERT INTO [Parts]
(
[ContentID],
[FromType],
[ItemID],
[DTS],
[UserID]
)
VALUES
(
@ContentID,
@FromType,
@ItemID,
@DTS,
@UserID
)
SELECT @newLastChanged=[LastChanged]
FROM [Parts] WHERE [ContentID]=@ContentID AND [FromType]=@FromType
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
-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: addPart Succeeded'
ELSE PRINT 'Procedure Creation: addPart Error on Creation'
GO
/****** Object: StoredProcedure [addPdf] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[addPdf]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [addPdf];
@@ -2341,7 +2579,6 @@ BEGIN CATCH -- Catch Block
EXEC vlnErrorHandler
END CATCH
--USE MASTER
GO
-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: CopyItemAndChildren Succeeded'
@@ -7812,161 +8049,6 @@ IF (@@Error = 0) PRINT 'Procedure Creation: getImagesByContentID Succeeded'
ELSE PRINT 'Procedure Creation: getImagesByContentID Error on Creation'
GO
/****** Object: StoredProcedure [getItem] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getItem]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [getItem];
GO
CREATE PROCEDURE [dbo].[getItem]
(
@ItemID int
)
WITH EXECUTE AS OWNER
AS
SELECT
[ItemID],
[PreviousID],
[ContentID],
[DTS],
[UserID],
[LastChanged],
(SELECT COUNT(*) FROM [Annotations] WHERE [Annotations].[ItemID]=[Items].[ItemID]) [AnnotationCount],
(SELECT COUNT(*) FROM [DocVersions] WHERE [DocVersions].[ItemID]=[Items].[ItemID]) [DocVersionCount],
(SELECT COUNT(*) FROM [Items] [Next] WHERE [Next].[PreviousID]=[Items].[ItemID]) [NextCount],
(SELECT COUNT(*) FROM [Parts] WHERE [Parts].[ItemID]=[Items].[ItemID]) [PartCount],
(SELECT COUNT(*) FROM [Transitions] WHERE [Transitions].[RangeID]=[Items].[ItemID]) [Transition_RangeIDCount],
(SELECT COUNT(*) FROM [Transitions] WHERE [Transitions].[ToID]=[Items].[ItemID]) [Transition_ToIDCount]
FROM [Items]
WHERE [ItemID]=@ItemID
SELECT
[Annotations].[AnnotationID],
[Annotations].[ItemID],
[Annotations].[TypeID],
[Annotations].[RtfText],
[Annotations].[SearchText],
[Annotations].[Config],
[Annotations].[DTS],
[Annotations].[UserID],
[Annotations].[LastChanged],
[AnnotationTypes].[Name] [AnnotationType_Name],
[AnnotationTypes].[Config] [AnnotationType_Config],
[AnnotationTypes].[DTS] [AnnotationType_DTS],
[AnnotationTypes].[UserID] [AnnotationType_UserID]
FROM [Annotations]
JOIN [AnnotationTypes] ON
[AnnotationTypes].[TypeID]=[Annotations].[TypeID]
WHERE
[Annotations].[ItemID]=@ItemID
SELECT
[DocVersions].[VersionID],
[DocVersions].[FolderID],
[DocVersions].[VersionType],
[DocVersions].[Name],
[DocVersions].[Title],
[DocVersions].[ItemID],
[DocVersions].[FormatID],
[DocVersions].[Config],
[DocVersions].[DTS],
[DocVersions].[UserID],
[DocVersions].[LastChanged],
[Folders].[ParentID] [Folder_ParentID],
[Folders].[DBID] [Folder_DBID],
[Folders].[Name] [Folder_Name],
[Folders].[Title] [Folder_Title],
[Folders].[ShortName] [Folder_ShortName],
[Folders].[FormatID] [Folder_FormatID],
[Folders].[ManualOrder] [Folder_ManualOrder],
[Folders].[Config] [Folder_Config],
[Folders].[DTS] [Folder_DTS],
[Folders].[UsrID] [Folder_UsrID]
FROM [DocVersions]
JOIN [Folders] ON
[Folders].[FolderID]=[DocVersions].[FolderID]
WHERE
[DocVersions].[ItemID]=@ItemID
SELECT
[Parts].[ContentID],
[Parts].[FromType],
[Parts].[ItemID],
[Parts].[DTS],
[Parts].[UserID],
[Parts].[LastChanged],
[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 [Parts]
JOIN [Contents] ON
[Contents].[ContentID]=[Parts].[ContentID]
WHERE
[Parts].[ItemID]=@ItemID
SELECT
[Transitions].[TransitionID],
[Transitions].[FromID],
[Transitions].[ToID],
[Transitions].[RangeID],
[Transitions].[IsRange],
[Transitions].[TranType],
[Transitions].[Config],
[Transitions].[DTS],
[Transitions].[UserID],
[Transitions].[LastChanged],
[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 [Transitions]
JOIN [Contents] ON
[Contents].[ContentID]=[Transitions].[FromID]
WHERE
[Transitions].[RangeID]=@ItemID
SELECT
[Transitions].[TransitionID],
[Transitions].[FromID],
[Transitions].[ToID],
[Transitions].[RangeID],
[Transitions].[IsRange],
[Transitions].[TranType],
[Transitions].[Config],
[Transitions].[DTS],
[Transitions].[UserID],
[Transitions].[LastChanged],
[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 [Transitions]
JOIN [Contents] ON
[Contents].[ContentID]=[Transitions].[FromID]
WHERE
[Transitions].[ToID]=@ItemID
RETURN
GO
-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: getItem Succeeded'
ELSE PRINT 'Procedure Creation: getItem Error on Creation'
GO
/****** Object: StoredProcedure [getItemAndChildren] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getItemAndChildren]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [getItemAndChildren];
@@ -10978,12 +11060,15 @@ BEGIN TRY -- Try Block
dbcc checkident([RODbs],reseed,0)
delete from [Transitions]
dbcc checkident([Transitions],reseed,0)
delete from [Applicabilities]
delete from [Items]
dbcc checkident([Items],reseed,0)
delete from [Contents]
dbcc checkident([Contents],reseed,0)
delete from [Formats]
dbcc checkident([Formats],reseed,0)
delete from [Scopes]
dbcc checkident([Scopes],reseed,0)
IF( @@TRANCOUNT > 0 ) COMMIT
END TRY
BEGIN CATCH -- Catch Block
@@ -12081,56 +12166,6 @@ IF (@@Error = 0) PRINT 'Procedure Creation: updateMembership Succeeded'
ELSE PRINT 'Procedure Creation: updateMembership Error on Creation'
GO
/****** Object: StoredProcedure [updatePart] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[updatePart]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [updatePart];
GO
CREATE PROCEDURE [dbo].[updatePart]
(
@ContentID int,
@FromType int,
@ItemID int,
@DTS datetime,
@UserID nvarchar(100),
@LastChanged timestamp,
@newLastChanged timestamp output
)
WITH EXECUTE AS OWNER
AS
BEGIN TRY -- Try Block
BEGIN TRANSACTION
UPDATE [Parts]
SET
[ItemID]=@ItemID,
[DTS]=@DTS,
[UserID]=@UserID
WHERE [ContentID]=@ContentID AND [FromType]=@FromType AND [LastChanged]=@LastChanged
IF @@ROWCOUNT = 0
BEGIN
IF NOT exists(select * from [Parts] WHERE [ContentID]=@ContentID AND [FromType]=@FromType)
RAISERROR('Part record has been deleted by another user', 16, 1)
ELSE
RAISERROR('Part has been edited by another user', 16, 1)
END
SELECT @newLastChanged=[LastChanged]
FROM [Parts] WHERE [ContentID]=@ContentID AND [FromType]=@FromType
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
-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: updatePart Succeeded'
ELSE PRINT 'Procedure Creation: updatePart Error on Creation'
GO
/****** Object: StoredProcedure [updatePdf] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[updatePdf]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [updatePdf];
@@ -16932,33 +16967,3 @@ IF (@@Error = 0) PRINT 'Procedure Creation: vesp_SearchROItemAndChildren Succeed
ELSE PRINT 'Procedure Creation: vesp_SearchROItemAndChildren Error on Creation'
GO
/****** Object: StoredProcedure [vlnErrorHandler] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vlnErrorHandler]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [vlnErrorHandler];
GO
CREATE PROCEDURE [dbo].[vlnErrorHandler]
(@ExpectedCount int=-1
,@MessageFormat nvarchar(512)=N'Expected RowCount (%d) not met (%d)')
WITH EXECUTE AS OWNER
AS
BEGIN
DECLARE @ErrorMessage NVARCHAR(4000), @ErrorNumber INT, @ErrorSeverity INT, @ErrorState INT, @ErrorProcedure NVARCHAR(126)
, @ErrorLine INT, @RowCount INT;
SELECT @ErrorMessage = ERROR_MESSAGE(), @ErrorSeverity = ERROR_SEVERITY(), @ErrorState = ERROR_STATE(),@ErrorNumber = ERROR_NUMBER()
, @ErrorLine = ERROR_LINE(), @ErrorProcedure = ERROR_PROCEDURE(), @RowCount = @@RowCount;
IF @ErrorNumber > 0
BEGIN
IF @ErrorProcedure = OBJECT_NAME(@@PROCID) -- If the Procedure is the current procedure just pass the error message
RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState)
ELSE -- Add in the procedure name and line as well as the error number
RAISERROR (N'%s[%d] - (%d) %s', @ErrorSeverity, @ErrorState, @ErrorProcedure, @ErrorLine, @ErrorNumber, @ErrorMessage)
END
ELSE IF @ExpectedCount <> -1 AND @ExpectedCount <> @RowCount
RAISERROR (@MessageFormat, 16, 1, @ExpectedCount, @RowCount)
END
GO
-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: vlnErrorHandler Succeeded'
ELSE PRINT 'Procedure Creation: vlnErrorHandler Error on Creation'
GO