[antlr-interest] String Template Puzzle

David Beckedorff david.beckedorff at gmail.com
Tue Jul 1 13:19:23 PDT 2008


Later enhancements ...

          update $dto.tableName$
          set $dto.fields : { f |
$if(!f.idColumn)$$if(!f.versionColumn)$$if(!f.extraColumn)$
            $f.dbColName$ = #$f.name
;format="ilc"$:$f.dbColType$#$if(!f.penultimateField)$,$endif$
$endif$$endif$$endif$}$
          where current of c1; c1;


But I still have the blank line problem.




On 7/1/08, David Beckedorff <david.beckedorff at gmail.com> wrote:
>
> OK, Johannes, cool suggestion!
>
>
> So I added boolean fields 'reqForUpdate' and 'lastFieldForUpdate" to my
> DtoField class & now the template looks like this:
>
>           update $dto.tableName$
>           set $dto.fields : { f |
> $if(f.reqForUpdate)$
>             $f.dbColName$ = #$f.name
> ;format="ilc"$:$f.dbColType$#$if(!f.lastFieldForUpdate)$,$endif$
> $endif$}$
>           where current of c1;
>
>
> which generates:
>
>
>           update DP_JRNL_ENTRY
>           set
>
>             OWNR_PERS_NTL_ID = #ownerId:VARCHAR#,
>             OWNR_DP_TYPE_CD = #ownerDpType:VARCHAR#,
>             ATHR_PERS_NTL_ID = #authorId:VARCHAR#,
>             ATHR_PERS_SRC_ID = #authorSourceId:NUMERIC#,
>             SBJ_AREA_ID = #subjectAreaId:NUMERIC#,
>             DP_GOAL_TYPE_CD = #goalTypeCode:VARCHAR#,
>             DP_JRNL_TITLE_TX = #title:VARCHAR#,
>             DP_JRNL_ENTRY_TX = #entry:CLOB#,
>             DP_JRNL_ENTRY_CMNT = #comments:CLOB#,
>             DP_JRNL_CRTN_DT = #createDate:DATE#,
>             DP_JRNL_UPDT_DT = #modifiedDate:DATE#,
>             DP_JRNL_STRT_DT = #startDate:DATE#,
>             DP_JRNL_END_DT = #endDate:DATE#,
>             DP_JRNL_ACHV_DT = #achievementDate:DATE#
>
>           where current of c1;
>
>
>
> So, now, for the gold ring, how do I get rid of the 2 blank lines, one
> after 'set' and the second after 'DP_JRNL_ACHV_DT = ...'  ??   The $if$ test
> when false seems always to generate a blank line.
>
> -David
>
>
>  On 6/30/08, Johannes Luber <jaluber at gmx.de> wrote:
>>
>> David Beckedorff schrieb:
>>
>>> Dear String Templaters,
>>>  I have a ST template that generates a SQL update statement::
>>>  dtoSqlMap(service,dto) ::= <<
>>> ...
>>> update $dto.tableName$
>>> set $dto.fields : { f |
>>>  $f.dbColName$ = #$f.name <http://f.name>;format="ilc"$:$f.dbColType$#};
>>> separator=","$           <== "ilc" means to format the initial letter
>>> lowercase
>>> where current of c1;
>>> ...
>>>  >>
>>>  which in a specific case generates the following code:
>>>  update DP_JRNL_ENTRY
>>> set
>>>  DP_JRNL_ENTRY_ID = #id:NUMERIC,
>>>  OWNR_PERS_NTL_ID = #ownerId:VARCHAR,
>>>  OWNR_DP_TYPE_CD = #ownerDpType:VARCHAR,
>>>  ATHR_PERS_NTL_ID = #authorId:VARCHAR,
>>>  ATHR_PERS_SRC_ID = #authorSourceId:NUMERIC,
>>>  SBJ_AREA_ID = #subjectAreaId:NUMERIC,
>>>  DP_GOAL_TYPE_CD = #goalTypeCode:VARCHAR,
>>>  DP_JRNL_TITLE_TX = #title:VARCHAR,
>>>  DP_JRNL_ENTRY_TX = #entry:CLOB,
>>>  DP_JRNL_CRTN_DT = #createDate:DATE,
>>>  DP_JRNL_UPDT_DT = #modifiedDate:DATE,
>>>  DP_JRNL_STRT_DT = #startDate:DATE,
>>>  DP_JRNL_END_DT = #endDate:DATE,
>>>  DP_JRNL_ACHV_DT = #achievementDate:DATE,
>>>  VER_NBR = #version:NUMERIC         where current of c1;
>>>   However, I want to suppress the DP_JRNL_ENTRY_ID and VER_NBR fields.
>>> The former is implied by "where current of c1" and the latter is updated by
>>> a trigger, so should be omitted from the update statement. But they are
>>> valid fields of the Data Transfer Object (DTO).
>>>  It appears that the $if(...)$ construct allows to test for the presence
>>> of an attribute or the value of a boolean. But I don't think it allows to
>>> test for:  if  ( $f.dbColName$ == "DP_JRNL_ENTRY_ID" ).
>>>  Is there some other way to accomplish this?
>>>  Thanks,
>>> David
>>>
>>
>> Create a new attribute IsdbColNameJournalEntry.
>>
>> Johannes
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080701/68ddafda/attachment-0001.html 


More information about the antlr-interest mailing list