SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
[SA 6 Beta] - Code formatting, commas in stored procedures

 
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant View previous topic
View next topic
[SA 6 Beta] - Code formatting, commas in stored procedures
Author Message
gemisigo



Joined: 11 Mar 2010
Posts: 2109

Post [SA 6 Beta] - Code formatting, commas in stored procedures Reply with quote
The default formatting rule that comes with SA does not work properly. When formatting stored procedures, SA pays no heed to setting Commas=stacked(leading), thus

Code:

CREATE PROCEDURE dbo.sp_aoeu @p1 INT, @p2 NUMERIC, @p3 INT
AS
BEGIN
   -- ...
   RETURN @@ERROR
END
GO


ends up formatted stacked(trailing) like this:

Code:

CREATE PROCEDURE dbo.sp_aoeu
   @p1 INT,
   @p2 NUMERIC,
   @p3 INT
AS
BEGIN
   RETURN @@ERROR
END
GO


I tried to change the default setting to

Code:

CREATE PROCEDURE ...
   @...
   ,@...
WITH ...
   ,...
AS
   <stmtList>
GO


but it only made things worse. The result:

Code:

CREATE PROCEDURE dbo.sp_aoeu
   @p1 INT
   ,
   @p2 NUMERIC
   ,
   @p3 INT
AS
BEGIN
   RETURN @@ERROR
END
GO

Fri Jul 22, 2011 5:34 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7849

Post Reply with quote
Please change formatting rule for CREATE PROCEDURE to

Code:
CREATE PROCEDURE ...
(
     ...
   ,@...
   ,@...
)
WITH ...
    ,...
AS
   <stmtList>
GO



To use that rule, please use brackets around procedure parameters as in the ANSI and SQL standards. That should do what you want.

Code:
CREATE PROCEDURE dbo.sp_aoeu (@p1 INT, @p2 NUMERIC, @p3 INT)
AS
BEGIN
   -- ...
   RETURN @@ERROR
END
GO

Fri Jul 22, 2011 11:24 am View user's profile Send private message
gemisigo



Joined: 11 Mar 2010
Posts: 2109

Post Reply with quote
Yes, I figured that out through try and err and already altered my snippet that creates procedures but I've got a vast number of different scripts written by other developers that still use this syntax (and it's quite difficult to convince them to change habits :) Not to mention that it also affects existing procedures when altering them.

I also tried to remove @-s but did not work. Result was:

Code:

CREATE PROCEDURE dbo.sp_aoeu
@p1 INT
   ,...@p2 NUMERIC
   ,...@p3 INT
AS
BEGIN
   RETURN @@ERROR
END
GO




Is this going to be fixed? It worked in previous version. If stays this way I'll have to create a pre-processor to modify all create/alter procedure script fragments to use the new syntax. It can be tedious to scan some several tens of thousand lines to check if formatting the script would break the code or not.
Fri Jul 22, 2011 12:22 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7849

Post Reply with quote
Are you saying this is a behavioral change? Can you tell me in which version the behavior is different?
Fri Jul 22, 2011 12:55 pm View user's profile Send private message
gemisigo



Joined: 11 Mar 2010
Posts: 2109

Post Reply with quote
No, sorry, my mistake. I reinstalled 5.1.40 and it isn't working either, it places the commas at the end of the lines or produces the
Code:

   @p1 INT
   ,
   @p2 NUMERIC
   ,
   @p3 INT

result.

I must have confused it with functions. Having brackets around parameters the code is formatted properly. I added them to the rule and now it does not format procedure parameters that lack brackets. The good news is it does not break the code either. I'm considering "whipping" my colleagues to start using the correct syntax. I like that better anyway.
Fri Jul 22, 2011 1:28 pm View user's profile Send private message
Display posts from previous:    
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant All times are GMT - 4 Hours
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


 

 

Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.