I'm experiencing a problem when I use curly brackets around the else directive (see example below). The problem is that the string #{else} is itself copied to the output instead of being recognized and parsed as a directive.
#if($column.Nullable)NULL#{else}NOT NULL#end
Can anybody give me a hint on how this feature is used? Or is it a bug perhaps?
Kind regards,
Ranco
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, I think that is supposed to work---it seems like a bug. You may need to use a workaround, like using two #if statements, or else define an empty string as a variable:
Normally, you can put curly braces around variables and directives to set them off from the surrounding alphanumeric characters. It could also be that NVelocity is based on a version of Velocity that hadn't implemented parentheses around a directive....
-Mike
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm experiencing a problem when I use curly brackets around the else directive (see example below). The problem is that the string #{else} is itself copied to the output instead of being recognized and parsed as a directive.
#if($column.Nullable)NULL#{else}NOT NULL#end
Can anybody give me a hint on how this feature is used? Or is it a bug perhaps?
Kind regards,
Ranco
Hi-
Yes, I think that is supposed to work---it seems like a bug. You may need to use a workaround, like using two #if statements, or else define an empty string as a variable:
#set($empty="")
#if($column.Nullable)NULL#else${empty}NOT NULL#end
Cheers,
-Mike
Mike, thanks for your response. The workaround works perfectly.
Btw, why are the curly braces needed around empty?
Regards,
Ranco
Hi-
Normally, you can put curly braces around variables and directives to set them off from the surrounding alphanumeric characters. It could also be that NVelocity is based on a version of Velocity that hadn't implemented parentheses around a directive....
-Mike
I was just revisiting this; it is probably nicer to omit the "else" entirely:
#set($nulltest="NOT NULL")
#if($column.Nullable)#set($nulltest="NULL")#end
SELECT * FROM mytable WHERE mycol IS $nulltest
Cheers,
-Mike