Update AddPDF stored procedure to keep duplicates from causing PROMs to crash when adding an existing record.

This commit is contained in:
Rich 2017-04-10 17:52:03 +00:00
parent 1e7004b5d6
commit 499c09b9c0

View File

@ -13053,6 +13053,78 @@ ELSE PRINT 'StoredProcedure [vesp_CleanUpROAssociations] Error on Creation'
go
PRINT 'Added IX_contentsLastChanged Index. Speeds up session queries'
/****** Object: StoredProcedure [addPdf] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[addPdf]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [addPdf];
GO
/*****************************************************************************
Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
Copyright 2012 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
CREATE PROCEDURE [dbo].[addPdf]
(
@DocID int,
@DebugStatus int,
@TopRow int,
@PageLength int,
@LeftMargin int,
@PageWidth int,
@PageCount float,
@DocPdf varbinary(MAX)=null,
@DTS datetime,
@UserID nvarchar(100),
@newLastChanged timestamp output
)
WITH EXECUTE AS OWNER
AS
BEGIN TRY -- Try Block
BEGIN TRANSACTION
IF not exists(select * FROM [Pdfs] WHERE [DocID]=@DocID AND [DebugStatus]=@DebugStatus AND [TopRow]=@TopRow AND [PageLength]=@PageLength AND [LeftMargin]=@LeftMargin AND [PageWidth]=@PageWidth)
BEGIN
INSERT INTO [Pdfs]
(
[DocID],
[DebugStatus],
[TopRow],
[PageLength],
[LeftMargin],
[PageWidth],
[PageCount],
[DocPdf],
[DTS],
[UserID]
)
VALUES
(
@DocID,
@DebugStatus,
@TopRow,
@PageLength,
@LeftMargin,
@PageWidth,
@PageCount,
@DocPdf,
@DTS,
@UserID
)
END
SELECT @newLastChanged=[LastChanged]
FROM [Pdfs] WHERE [DocID]=@DocID AND [DebugStatus]=@DebugStatus AND [TopRow]=@TopRow AND [PageLength]=@PageLength AND [LeftMargin]=@LeftMargin AND [PageWidth]=@PageWidth
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: addPdf Succeeded'
ELSE PRINT 'Procedure Creation: addPdf Error on Creation'
GO
-----------------------------------------------------------------------------
/*
@ -13079,8 +13151,8 @@ BEGIN TRY -- Try Block
set nocount on
DECLARE @RevDate varchar(255)
DECLARE @RevDescription varchar(255)
set @RevDate = '3/23/2017 1:20PM'
set @RevDescription = 'Fixed the update of IX_contentsLastChanged Index procedure.'
set @RevDate = '4/7/2017 10:21 AM'
set @RevDescription = 'Corrected AddPDF Stored Procedure'
Select cast(@RevDate as datetime) RevDate, @RevDescription RevDescription
PRINT 'SQL Code Revision ' + @RevDate + ' - ' + @RevDescription
IF( @@TRANCOUNT > 0 ) COMMIT