:SetVar Procedure "BKRG::RemoveBook"
:r $(DropProcedureScript_AUX)
create procedure [$(Procedure)]
   @ID                  uniqueidentifier,
   @IgnoreNotFoundError bit = 0,
   @Status              uniqueidentifier  = null out,
   @Message             $(dt_Message_AUX) = null out
AS
/*==================================================================================================
# BookRegistry app. | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# BOOK REMOVAL:
#
# === Usage: ===
# exec @RetValue = [BKRG::RemoveBook] <Book ID>,
#                  @Status=@Status out, @Message=@Message out
--------------------------------------------------------------------------------------------------*/
-- commstat_NotFound
--:SetVar Status_ "''"
/*================================================================================================*/
$(BEGIN_AUX)
----------------------------------------------------------------------------------------------------
select @Status=null, @Message=null
----------------------------------------------------------------------------------------------------
if @ID is null or @IgnoreNotFoundError is null
   exec [AUX:RaiseIncorrectProcedureCall] N'$(Procedure)'
if @ID = $(guid_Empty_AUX)
   exec [AUX:RaiseIncorrectProcedureCall] N'$(Procedure)',
      'Empty GUID for @ID-parameter (book ID).'
----------------------------------------------------------------------------------------------------
/*
select @Status=null, @Message=dbo.[AUX:LocalizedText](
   'Book-deletion is blocked (test error).',
   N'Удаление книг заблокировано (тестовая ошибка).' )
RETURN 1
*/
--RETURN 0 -- This will cause ficticious deletion (do nothing + successful result).
--RETURN 1 -- It will cause undefinite server operation error (visible at WASM-level).

delete [Books] where [ID] = @ID
if @@ROWCOUNT = 0 and @IgnoreNotFoundError = 0
begin
   select @Status=$(commstat_NotFound), @Message=dbo.[AUX:LocalizedText](
      'Deleted book record is not found.',
      N'Удаляемая запись книги не обнаружена.' )
   RETURN 1
end

----------------------------------------------------------------------------------------------------
$(END_AUX)
/*================================================================================================*/
GO
/*
declare @BookId uniqueidentifier, @RetValue int, @Status uniqueidentifier, @Message nvarchar(max)
set @BookId = NEWID()
exec @RetValue = [BKRG::RemoveBook] @BookId, @Status=@Status out, @Message=@Message out
if @RetValue<>0 select @RetValue 'RetValue', @Status 'Status', @Message 'Message'
*/
/*
declare @BookId uniqueidentifier, @RetValue int, @Status uniqueidentifier, @Message nvarchar(max)
set @BookId = NEWID()
exec @RetValue = [BKRG::RemoveBook] @BookId, 1, @Status=@Status out, @Message=@Message out
if @RetValue<>0 select @RetValue 'RetValue', @Status 'Status', @Message 'Message'
*/
