[Zope] Check null from SQL method

Philip Aylesworth zopelist@regalint.com
Tue, 27 Apr 1999 10:11:28 -0400


> 
> Howto check if a SQL method result is 'null' ?
> 

You can use the null= attribute in the var tag to set a default value if
it is null. That might do what you want without actually testing for
null. eg:

<!--#var test null="N/A" fmt="%d"--> 

There is a bug in Zope that makes this not work unless fmt is also there
and it won't work with strings (fmt="%s"). There is a patch that works
great. Add the lines with + (take the + out, though) after line 271 in
the file ./lib/python/DocumentTemplate/DT_Var.py and make sure
indentation matches the following line (# finally,...)

                      val = special_formats[fmt](val, name, md)
                  elif fmt=='': val=''
                  else: val = fmt % val
+                  
+         # null patch by Richard Jones modified by John Jarvis
+         elif have_arg('null') and not val:
+             val = args['null']
  
          # finally, pump it through the actual string format...
          fmt=self.fmt

Then null= will work on strings and with or without the fmt=.

(Hopefully this will be built into 1.11, hint, hint)

If you need to test for null I think you can test for 
<!--#if "varname==none"-->

Phil A.