Back to OIM Explorer

dbo.QBM_PViewDrop

Stored ProcedureSQL_STORED_PROCEDURESandbox DB

Stored Procedure.

Source: sandbox-db sys.sql_modules

Source size: 1.931 characters

Interpretation

  • Database routine. Review parameters, called procedures, DBQueue inserts, and QBM_PJobCreate helper calls before assuming side effects.

Relations

  • No extracted relations.

Typed Edges

  • references source dbo.QBM_FGISessionErrorRethrow source text reference
  • references source dbo.QBM_FSQObjectComment source text reference
  • references source dbo.QBM_PSessionErrorAdd source text reference

Complete Source

SQL98 lines
1CREATE PROCEDURE QBM_PViewDrop(2  @pattern nvarchar(255),3  @force BIT = 04)5AS6BEGIN7  DECLARE @SQLcmd nvarchar(max)8  DECLARE @name nvarchar(255)9  DECLARE @LengthMessage nvarchar(256) = '#LDS#Name of Element {0} is too long (30).|'10  DECLARE @ElementBuffer QBM_YCursorBuffer11  DECLARE @ElementCount int12  DECLARE @ElementIndex int13  DECLARE @crlf nvarchar(16) = nchar(13) + nchar(10)14  DECLARE @CommentCode BIT = 015  DECLARE @DebugSwitch int = 016  SET XACT_ABORT OFF17  BEGIN TRY18    IF @@NESTLEVEL < 219    BEGIN20      IF EXISTS(21        SELECT TOP 1 122        FROM sys.tables t23        WHERE24          t.name = 'QBMModuleDef')25      BEGIN26        IF EXISTS(27          SELECT TOP 1 128          FROM QBMModuleDef d29          WHERE30            d.UID_ModuleDef = 'MDK-Moduledefinition') AND EXISTS(31        SELECT TOP 1 132        FROM information_schema.routines r33        WHERE34          r.ROUTINE_type = N 'function' AND r.ROUTINE_NAME = 'QBM_FSQObjectComment')35        BEGIN36          SELECT @CommentCode = 137        END38      END39    END40    INSERT INTO @ElementBuffer(LongIdent1,41    ContentFull)42    SELECT43      v.name,44      CONCAT(CASE @CommentCode45      WHEN 1 THEN46      CONCAT('print dbo.QBM_FSQObjectComment (''', v.name, ''')', @crlf)47    ELSE ''48    END,49    'drop view if exists "',50    v.name,51    N '"')52    FROM sys.views v53    WHERE54      v.name LIKE @pattern55    SELECT @ElementCount = @@ROWCOUNT56    IF EXISTS(57      SELECT TOP 1 158      FROM @ElementBuffer e59      WHERE60        len(e.LongIdent1) > 30 AND @force = 0)61    BEGIN62      SELECT TOP 1 @name = e.LongIdent163      FROM @ElementBuffer e64      WHERE65        len(e.LongIdent1) > 3066      SELECT67        @LengthMessage = CONCAT(@LengthMessage,68        @name,69        '|')70      RAISERROR(@LengthMessage,71      18,72      1)73        WITH nowait74    END75    SELECT @ElementIndex = 176    WHILE @ElementIndex <= @ElementCount77    BEGIN78      SELECT TOP 1 @SQLcmd = bu.ContentFull79      FROM @ElementBuffer bu80      WHERE81        bu.ElementIndex = @ElementIndex82      IF @DebugSwitch > 083      BEGIN84        print @sqlcmd85      END86      EXEC sp_executeSQL @SQLcmd87      SELECT @ElementIndex += 188    END89  END TRY90  BEGIN CATCH91    EXEC QBM_PSessionErrorAdd DEFAULT92    DECLARE @Rethrow varchar(1000) = dbo.QBM_FGISessionErrorRethrow()93    RAISERROR(@Rethrow,94    18,95    1)96      WITH NOWAIT97  END CATCH98END
Open raw exported source
SQL ยท Raw14 lines
1   create   procedure QBM_PViewDrop (@pattern nvarchar(255) , @force bit = 0 )  as begin  declare @SQLcmd nvarchar(max) declare @name nvarchar(2552)  declare @LengthMessage nvarchar(256) = '#LDS#Name of Element {0} is too long (30).|' declare @ElementBuffer QBM_YCursorBuffer    declare @ElementCount3 int declare @ElementIndex int declare @crlf nvarchar(16) = nchar(13) + nchar(10) declare @CommentCode bit = 0 declare @DebugSwitch int = 0 SET XACT_ABORT4 OFF BEGIN TRY if @@NESTLEVEL < 2  begin if exists (select top 1 1 from sys.tables t where t.name = 'QBMModuleDef' ) begin if exists (select top 1 1 from5 QBMModuleDef d where d.UID_ModuleDef = 'MDK-Moduledefinition' ) and exists (select top 1 1 from information_schema.routines r where r.ROUTINE_type = N'function'6 and r.ROUTINE_NAME = 'QBM_FSQObjectComment' ) begin select @CommentCode = 1 end end end insert into @ElementBuffer(LongIdent1, ContentFull) select v.name7 , concat( case @CommentCode when 1 then concat('print dbo.QBM_FSQObjectComment (''' , v.name , ''')' , @crlf ) else '' end , 'drop view if exists "' ,8 v.name , N'"' )  from sys.views v where v.name like @pattern select @ElementCount = @@ROWCOUNT if exists (select top 1 1 from @ElementBuffer e where len9(e.LongIdent1) > 30 and @force = 0 ) begin select top 1 @name = e.LongIdent1 from @ElementBuffer e where len(e.LongIdent1) > 30 select @LengthMessage =10 concat(@LengthMessage , @name , '|') raiserror(@LengthMessage, 18, 1) with nowait end select @ElementIndex = 1 while @ElementIndex <= @ElementCount begin11 select top 1 @SQLcmd = bu.ContentFull from @ElementBuffer bu where bu.ElementIndex = @ElementIndex if @DebugSwitch > 0 begin print @sqlcmd end exec sp_executeSQL12 @SQLcmd select @ElementIndex += 1 end END TRY BEGIN CATCH exec QBM_PSessionErrorAdd default declare @Rethrow varchar(1000) = dbo.QBM_FGISessionErrorRethrow13() RAISERROR (@Rethrow, 18, 1) WITH NOWAIT END CATCH end 14