You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Davide Mora <d_...@yahoo.com> on 2001/03/26 17:12:58 UTC

know when i'm in the last element of a set

Hi!

i'm new to Velocity. I'm trying to generate SQL, so i
need to know when i have to add the "comma" for the
last parameter, something like that:

#foreach ( $table in $sqlTables )
CREATE TABLE $table.name (
 #foreach( $column in $table.columns )
   $column.name $column.type,
 #end
);
#end

But how i can detect when i don't have to add the ","
for the last column?

Thank you!


__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/

Re: know when i'm in the last element of a set

Posted by Jon Stevens <jo...@latchkey.com>.
on 3/26/01 10:56 AM, "Davide Mora" <d_...@yahoo.com> wrote:

> but when i call it the first row indentation is ok,
> while the others no, result: the code is messy.
> There is a solution for this?
> Thank you again,
> Davide

You have to make your VTL ugly in order to achieve pretty output. The reason
is that Velocity is *very* absolute about white space handling.

It is a trade off. All in all, you are generating code dynamically.

Personally, I prefer the template code to look nice and not really care what
the output looks like. In fact, take a look at Velocity's javacc generated
Parser.java code for an example of fugly looking unreadable code. :-)

-jon

-- 
If you come from a Perl or PHP background, JSP is a way to take
your pain to new levels. --Anonymous
<http://jakarta.apache.org/velocity/ymtd/ymtd.html>


Re: know when i'm in the last element of a set

Posted by Davide Mora <d_...@yahoo.com>.
I work! Thank you very much to everybody!

Another question! :)

I declared a macro like this:

#macro( relation_decl $relation )
	private java.util.Vector _orig_${relation.name} =
null;
	private java.util.Vector _${relation.name} = new
java.util.Vector();
#end


but when i call it the first row indentation is ok,
while the others no, result: the code is messy.
There is a solution for this?
Thank you again,
Davide

--- Jon Stevens <jo...@latchkey.com> wrote:
> on 3/26/01 7:33 AM, "Jason van Zyl"
> <jv...@apache.org> wrote:
> 
> > In Torque I just add a comma regardless and chop
> it
> > off when the column processing is done.
> 
> I like Geir's solution better. :-)
> 
> -jon
> 
> -- 
> If you come from a Perl or PHP background, JSP is a
> way to take
> your pain to new levels. --Anonymous
> <http://jakarta.apache.org/velocity/ymtd/ymtd.html>
> 


__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/

Re: know when i'm in the last element of a set

Posted by Jon Stevens <jo...@latchkey.com>.
on 3/26/01 7:33 AM, "Jason van Zyl" <jv...@apache.org> wrote:

> In Torque I just add a comma regardless and chop it
> off when the column processing is done.

I like Geir's solution better. :-)

-jon

-- 
If you come from a Perl or PHP background, JSP is a way to take
your pain to new levels. --Anonymous
<http://jakarta.apache.org/velocity/ymtd/ymtd.html>


Re: know when i'm in the last element of a set

Posted by Jason van Zyl <jv...@apache.org>.
Davide Mora wrote:
> 
> Hi!
> 
> i'm new to Velocity. I'm trying to generate SQL, so i
> need to know when i have to add the "comma" for the
> last parameter, something like that:
> 
> #foreach ( $table in $sqlTables )
> CREATE TABLE $table.name (
>  #foreach( $column in $table.columns )
>    $column.name $column.type,
>  #end
> );
> #end
> 
> But how i can detect when i don't have to add the ","
> for the last column?

You might want to look at Torque in the Turbine distribution.
It has been used to generate SQL from an XML for quite
some time.

http://jakarta.apache.org/turbine/torque.html

In Torque I just add a comma regardless and chop it
off when the column processing is done.

> 
> Thank you!
> 
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail.
> http://personal.mail.yahoo.com/

-- 
jvz.

Jason van Zyl
jvanzyl@apache.com

http://jakarta.apache.org/velocity
http://jakarta.apache.org/turbine
http://tambora.zenplex.org