ZSQL: how to definde null
If posted twice: please excuse (mailserver problem at ISP) Hi , I have a ZSQL method, that looks like Attributes: some_name='empty' UPDATE foo SET bar = <dtml-sqlvar some_name type="string"> WHERE some contitions ... ; But when the variable "some_name" not is passed to the ZSQL method I don't want to have 'empty' in my db but a null value. So I changed the method to SET bar = <dtml-if "some_name=='empty'">null<dtml-else><dtml-sqlvar some_name type="string"></dtml-if> Maybe the is a more elegant way, like setting the default to null, so I can get rid of the if clause. Thanx for any hints! Regards Christoph
Christoph Landwehr wrote at 2003-10-21 00:57 +0200:
I have a ZSQL method, that looks like
Attributes: some_name='empty'
UPDATE foo SET bar = <dtml-sqlvar some_name type="string"> WHERE some contitions ... ;
You can try the "optional" attribute for "dtml-sqlvar". You might need to use "type=nb" (non blank) rather than "type=string". Dieter
Dieter Maurer schrieb:
Christoph Landwehr wrote at 2003-10-21 00:57 +0200:
I have a ZSQL method, that looks like
Attributes: some_name='empty'
UPDATE foo SET bar = <dtml-sqlvar some_name type="string"> WHERE some contitions ... ;
You can try the "optional" attribute for "dtml-sqlvar". You might need to use "type=nb" (non blank) rather than "type=string".
In this case I dont't see how this could work, because I have to define 'some_name' in the SQL-Method's Attributes and supply a default value in case the user does not supply a value for 'some _name' in the form that feeds the SQL-Method. Therefor sone_name is never blank and the optional never is true. Am I missing something?
Christoph Landwehr wrote at 2003-10-27 14:13 +0100:
Dieter Maurer schrieb:
Christoph Landwehr wrote at 2003-10-21 00:57 +0200:
I have a ZSQL method, that looks like
Attributes: some_name='empty'
UPDATE foo SET bar = <dtml-sqlvar some_name type="string"> WHERE some contitions ... ;
You can try the "optional" attribute for "dtml-sqlvar". You might need to use "type=nb" (non blank) rather than "type=string".
In this case I dont't see how this could work, because I have to define 'some_name' in the SQL-Method's Attributes and supply a default value in case the user does not supply a value for 'some _name' in the form that feeds the SQL-Method. Therefor sone_name is never blank and the optional never is true.
Am I missing something?
Yes, you should read the documentation for "dtml-sqlvar" and its attribute "optional": optional -- A flag indicating that a value is optional. If a value is optional and is not provided (or is blank when a non-blank value is expected), then the string 'null' is inserted. Thus, you would use "type=nb" and ensure that the value is blank (empty) iff you want to render "null". -- Dieter
participants (2)
-
Christoph Landwehr -
Dieter Maurer