gemisigo
Joined: 11 Mar 2010 Posts: 2137
|
|
[11.3.279 Pro] - Code Snippet Code Formatting Style |
|
The Code Formatting Style set for some of my snippets does not seem to be applied to the result of the snippet. For example, the simple test snippet
|
|
select 1 as a, 2 as b, 3 as c;
|
does get formatted to
|
|
SELECT 1 AS a
,2 AS b
,3 AS c;
|
But when the generated code for the slightly more complicated
|
|
$PROMPT(cursor_name,Enter cursor name (it will be prefixed with 'cur_'),my_cursor,Declare cursor)$
$PROMPT(scope,Cursor scope?,1,Declare cursor, " " LOCAL GLOBAL,"I don't care!" Local Global)$
$PROMPT(direction,Cursor direction?,1,Declare cursor, " " FORWARD_ONLY SCROLL,"I don't care!" "Forward only" Scrolling)$
$PROMPT(type,Cursor type?,2,Declare cursor, " " DYNAMIC FAST_FORWARD KEYSET STATIC,"I don't care!" Dynamic "Fast forward" Keyset Static)$
$PROMPT(lock,Lock mode?,2,Declare cursor, " " OPTIMISTIC READ_ONLY SCROLL_LOCKS,"I don't care :)" Optimistic "Read only" "Scroll locks")$
$PROMPT(typewarning,Type warning?,,Declare cursor, " " TYPE_WARNING,"Never heard of that o_O" "Yes\,please!")$
$PROMPT(update,Wanna update anything?,1,Declare cursor,"FOR UPDATE" " " "FOR UPDATE OF","Aye\,everything!" "Nay\,thanks!" "Yep\,here and there!")$
DECLARE @_$COLUMNS(vertical,types)$;
DECLARE cur_$cursor_name$ CURSOR
$scope$ $direction$ $type$ $lock$ $typewarning$
FOR
SELECT cur.$COLUMNS(vertical)$
FROM $OBJECT(table, view, mview, tblFunc)$ as cur
$update$;
OPEN cur_$cursor_name$;
FETCH FROM cur_$cursor_name$ INTO @_$COLUMNS$;
WHILE @@FETCH_STATUS = 0
BEGIN
-- *********************** Cursor logic starts here *********************************************************************
|
-- *********************** Cursor logic ends here ***********************************************************************
FETCH FROM cur_$cursor_name$ INTO @_$COLUMNS$
END;
CLOSE cur_$cursor_name$;
DEALLOCATE cur_$cursor_name$;
|
is executed for the table
|
|
CREATE TABLE x (a INT, b VARCHAR(10), c DECIMAL(10,3));
|
the code that is inserted is not formatted at all.
This is how it looks when inserted:
|
|
DECLARE @[_a] int,
@[_b] varchar(10),
@[_c] decimal(10,3);
DECLARE cur_my_cursor CURSOR
LOCAL FORWARD_ONLY FAST_FORWARD READ_ONLY
FOR
SELECT cur.[a],
cur.[b],
cur.[c]
FROM [x] as cur
;
OPEN cur_my_cursor;
FETCH FROM cur_my_cursor INTO @[_a], @[_b], @[_c];
WHILE @@FETCH_STATUS = 0
BEGIN
-- *********************** Cursor logic starts here *********************************************************************
-- *********************** Cursor logic ends here ***********************************************************************
FETCH FROM cur_my_cursor INTO @[_a], @[_b], @[_c]
END;
CLOSE cur_my_cursor;
DEALLOCATE cur_my_cursor;
|
And this is how it should look like and how it does after manually applying the same formatting rules that are set for the snippet (disregard the fact that the variable names should not contain brackets as delimiters, that's another issue):
|
|
DECLARE @ [_a] INT
,@ [_b] VARCHAR(10)
,@ [_c] DECIMAL(10 ,3)
;
DECLARE cur_my_cursor CURSOR LOCAL FORWARD_ONLY FAST_FORWARD READ_ONLY
FOR
SELECT cur.[a]
,cur.[b]
,cur.[c]
FROM [x] AS cur;
OPEN cur_my_cursor
;
FETCH FROM cur_my_cursor
INTO @[_a]
,@[_b]
,@[_c];
WHILE @@FETCH_STATUS = 0
BEGIN
-- *********************** Cursor logic starts here *********************************************************************
-- *********************** Cursor logic ends here ***********************************************************************
FETCH FROM cur_my_cursor
INTO @[_a]
,@[_b]
,@[_c]
END
;
CLOSE cur_my_cursor
;
DEALLOCATE cur_my_cursor
;
|
|
|