CodeSmith Community
Your Code. Your Way. Faster!

Patch to drop all procedures on generation

Latest post 08-29-2008 9:26 AM by blake05. 5 replies.
  • 04-22-2007 4:07 PM

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 925
    • Points 34,785

    Patch to drop all procedures on generation

    I created a patch to incorporate the code posted on http://community.codesmithtools.com/forums/thread/23863.aspx by smallinov

    This patch changes the "IncludeDrop" option from being a bool to a new enum with the options of Entity/All/None where...

    Entity - Equates to the old true i.e each stored proc generated will be preceded by a corresponding DROP statement

    None - Equates to the old false i.e. no procedures will be dropped

    All - All netTiers procedures will be dropped with the following caveats - the ProcedurePrefix must be specified (so we don't inadvertantly drop all procs in a db!) - any custom procs will not be touched.

    What this means is that if you select "All", then after a gen you will only have those created during that run. This means you shouldn't get any orphaned procs left hanging around.

    swin

     

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 35
  • 04-24-2007 7:38 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 735
    • Points 17,045

    Re: Patch to drop all procedures on generation

    Thanks! Applied to SVN (rev. 542)

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    Filed under:
    • Post Points: 35
  • 04-30-2007 9:59 AM In reply to

    • heckubus
    • Top 75 Contributor
    • Joined on 06-27-2006
    • Posts 56
    • Points 1,205

    Re: Patch to drop all procedures on generation

    Some SQL to accomplish the same thing manually.  I currently use this as part of a re-generation process (NAnt) and it is run before NetTiers.  Kudos though on having that option now in NetTiers.

     

    -- Cleanup any old custom stored procedures that start with "csp_"
    DECLARE @procedure varchar(max)
    WHILE (SELECT COUNT(*) FROM sysobjects WHERE name LIKE 'csp_%' and xtype = 'P') > 0
    BEGIN
        SET @procedure = (SELECT TOP 1 [name] FROM sysobjects WHERE name LIKE 'csp_%' and xtype='P')
        SET @procedure = 'DROP PROCEDURE ' + @procedure
        EXEC(@procedure)
    END
    GO

    -- Cleanup any old NetTiers stored procedures that start with "nsp_"
    DECLARE @procedure varchar(max)
    WHILE (SELECT COUNT(*) FROM sysobjects WHERE name LIKE 'nsp_%' and xtype = 'P') > 0
    BEGIN
        SET @procedure = (SELECT TOP 1 [name] FROM sysobjects WHERE name LIKE 'nsp_%' and xtype='P')
        SET @procedure = 'DROP PROCEDURE ' + @procedure
        EXEC(@procedure)
    END
    GO

    • Post Points: 35
  • 11-02-2007 5:04 PM In reply to

    • Polar
    • Top 100 Contributor
    • Joined on 09-04-2007
    • Posts 51
    • Points 935

    Re: Patch to drop all procedures on generation

    One issue I found was that if you seperate your tables using shemas (SQL 2005) then the drop procedure will fail. Making the following changes to StoredProceduresXml.cst fixed the problem.

     Original:

    SELECT name FROM sysobjects WHERE type = 'P' AND objectproperty(id, 'IsMSShipped') = 0
    AND name LIKE '<%=ProcedurePrefix%>%' 
    ......
    AND name <> '<%=command.Name%>' 
    ......
    AND name <> '<%=command.Name%>' 

    Modified:

    SELECT '[' + sc.name + '].[' + so.name + ']' FROM sysobjects so INNER JOIN sys.schemas sc ON sc.schema_id = so.uid WHERE type = 'P' AND objectproperty(id, 'IsMSShipped') = 0
    AND so.name LIKE '<%=ProcedurePrefix%>%' 
    ......
    AND so.name <> '<%=command.Name%>' 
    ......
    AND so.name <> '<%=command.Name%>' 

     

     


    • Post Points: 5
  • 08-28-2008 1:37 PM In reply to

    • Polar
    • Top 100 Contributor
    • Joined on 09-04-2007
    • Posts 51
    • Points 935

    Re: Patch to drop all procedures on generation

    I have decided to create a patch to fix the schema issue above.

    • Post Points: 35
  • 08-29-2008 9:26 AM In reply to

    • blake05
    • Top 10 Contributor
    • Joined on 04-03-2008
    • Wisconsin
    • Posts 524
    • Points 9,785

    Re: Patch to drop all procedures on generation

    Hello,

    Thanks for the patch, I have submitted an issue on our bug tracker. You can check the status of it here.

    Thanks again

    -Blake Niemyjski

    Blake Niemyjski

    CodeSmith Tools, LLC. Software Development Engineer

    Blog: http://windowscoding.com/blogs/blake/

    ----------------------------------------------------------------------
     Member of the .NetTiers team | Visit http://www.nettiers.com
    ----------------------------------------------------------------------

    • Post Points: 5
Page 1 of 1 (6 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems