Using {sap} Tag

Coordinator
Apr 5, 2008 at 12:03 AM
Edited Apr 5, 2008 at 12:04 AM
Now TinySQL has separator tag for any loop statement inside template. If you don’t want to place separator after last column of table, just put your separator (like comma etc.) inside {sap}{/sap} tags.

Like in following example, comma is not placed inside {sap} tag:
$table: {loop}$field, {/loop}

The code generated from above template will something like:
Action: Id, Action, ProjectId, IsNextAction, IsWaitingFor, WaitingForNotes, RemindOn, IsDefer, DeferDate, IsDone, Sequence,
Note the extra comma separator at the end of the list.

If you don’t want to have separator (like comma in above example), just place separator inside {sap}{/sap} tags. So our modified example template will be like:

$table: {loop}$field{sap}, {/sap} {/loop}

Generated code from last template will be:
Action: Id, Action, ProjectId, IsNextAction, IsWaitingFor, WaitingForNotes, RemindOn, IsDefer, DeferDate, IsDone, Sequence

This new separator tag is handy for generating list of table columns as function parameter or stored procedure parameters etc. Here is another example of using {sap} tag:

CREATE PROCEDURE dbo.usp_Update$table{loop}
@$field = $sp_type{sap},{/sap}{/loop}
AS
BEGIN

UPDATE dbo.$table WITH (ROWLOCK)
SET {loop}$field = @$field{sap},{/sap}
{/loop}
WHERE --TODO

RETURN -1
END

And generated code from above template:
CREATE PROCEDURE dbo.usp_UpdateAction
@Id = NUMERIC,
@Action = VARCHAR(250),
@ProjectId = NUMERIC,
@IsNextAction = BIT,
@IsWaitingFor = BIT,
@WaitingForNotes = VARCHAR(1000),
@RemindOn = DATETIME,
@IsDefer = BIT,
@DeferDate = DATETIME,
@IsDone = BIT,
@Sequence = INT
AS
BEGIN

UPDATE dbo.Action WITH (ROWLOCK)
SET Id = @Id,
Action = @Action,
ProjectId = @ProjectId,
IsNextAction = @IsNextAction,
IsWaitingFor = @IsWaitingFor,
WaitingForNotes = @WaitingForNotes,
RemindOn = @RemindOn,
IsDefer = @IsDefer,
DeferDate = @DeferDate,
IsDone = @IsDone,
Sequence = @Sequence
WHERE --TODO

RETURN -1
END