[antlr-interest] StringTemplate questions

G R relationalalgebra at gmail.com
Fri Nov 9 03:07:29 PST 2007


First of all, thanks Jeff.
I've try using your template by doing this one (I'm using a group template
file) :
difference(left, right, keyNames) ::= <<
SELECT *
FROM <left><if(keyNames)>
WHERE <keyNames: {keyName | <keyName> NOT IN ( SELECT <keyName> FROM <right>
)
}; separator="\nAND"><endif>
>>

My Tree grammar that is calling this template is here :
->difference(left={$left.st}, right={$right.st}, keyNames={
RATranslator.getPrimaryKeys($left.text)});

Where RATranslator.getPrimaryKeys(String tableName) returns a String[].
I've check the array returned by this methode, ans it's ok.
But when I try to use it as a list, I just get the physical adress of my
array. Instead of writing the content, I get something like this : [
Ljava.lang.String;@1931579.

So When I try your solution, it just acts as if my list were null and give
my something like :
SELECT *
FROM <left>

I don't understand what I am doing wrong with this list. Anyone can help ?
Thanks again.

2007/11/8, Barnes, Jeff <JB0284 at att.com>:
>
> I think you may want to try something like this:
>
> ArrayList keyNameList = new ArrayList( Arrays.asList( keyNames ) );
> templateObject.setLeft( leftTableName );
> templateObject.setRight( rightTableName );
> templateObject.setKeyNames( ( String[] ) keyNameList.toArray( new String[
> 0 ] ) );
>
> Then your template would look like this, perhaps:
>
> selectStmt ::= <<
> SELECT * FROM $templateObject.left$$if( templateObject.keyNames )$ WHERE
> $templateObject.keyNames | keyName {
> $keyName$ NOT IN ( SELECT $keyName$ FROM $templateObject.right$ )
> }; separator="\n"$$endif$
> >>
>
> I haven't tested this template, so the usual caveats apply.
>
> Best regards,
> Jeff
> ________________________________________
> From: antlr-interest-bounces at antlr.org [mailto:
> antlr-interest-bounces at antlr.org] On Behalf Of G R
> Sent: Thursday, November 08, 2007 8:33 AM
> To: antlr-interest Interest
> Subject: [antlr-interest] StringTemplate questions
>
> Hi,
>
> I'm trying to use ST to translate relational algebra into SQL, and I'm
> stuck with a template :
> "minus(left, right, keys)" where left, and right are just text, and keys
> is a list of string (I want it to be a list of String).
>
> So first question is how in Java do I build a ST list of string ?
>
> Then, using my 3 attributes (left, right and keys), I'd like to generate
> the following code :
>
> SELECT * FROM <left>
> WHERE key1 NOT IN (SELECT key1 FROM <right>)
> AND key2 NOT IN (SELECT key2 FROM <right>)
> ...
> AND keyN NOT IN (SELECT keyN FROM <right>)
>
> where key1, key2, ... keyN are the element of my list.
>
> How can i do this ? Can i use an attribute within the separator of a list
> ?
>
> Thanks for any help.
>
> G.R
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071109/613dbacc/attachment.html 


More information about the antlr-interest mailing list