CodeSmith Community
Your Code. Your Way. Faster!

Patch to drop all procedures on generation

rated by 0 users
This post has 6 Replies | 3 Followers

Top 10 Contributor
Posts 925
Points 35,460
swin Posted: 04-22-2007 4:07 PM

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
Top 10 Contributor
Posts 742
Points 17,965
Thanks! Applied to SVN (rev. 542)

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

Top 75 Contributor
Posts 56
Points 1,225

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
Top 75 Contributor
Posts 79
Points 1,830

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
Top 75 Contributor
Posts 79
Points 1,830

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

  • | Post Points: 35
Top 10 Contributor
Posts 2,328
Points 83,627

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/
.NetTiers team | Visit http://www.nettiers.com

  • | Post Points: 5
Top 10 Contributor
Posts 2,328
Points 83,627

Hello,

This has been fixed in Rev 776.

Thanks again

-Blake Niemyjski

Blake Niemyjski
CodeSmith Tools, LLC. Software Development Engineer
Blog: http://windowscoding.com/blogs/blake/
.NetTiers team | Visit http://www.nettiers.com

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