[Zope] Bug in sqlvar.py?

Jeff K. Hoffman jkhoffman@usa.net
Sat, 13 Mar 1999 21:38:07 -0500 (EST)


Hello, everyone. I'm bustin' ass on my project for the outdoors group and
ran into a problem with the #sqlvar command.

At the top of the file, in the docstring, it says:

    For example, given the tag::

      <!--#sqlvar x type=nb optional>

    if the value of 'x' is::

      Let\'s do it

    then the text inserted is:

      'Let''s do it'

    however, if x is ommitted or an empty string, then the value
    inserted is 'null'.

Either I'm totally off base somewhere, or this is not correct. In one of
my SQL Methods I have a query, with a line:

  <!--#sqlvar address2 type=nb optional-->

And, when I submit the query while leaving address2 blank I get:

  Invalid empty string value for address2

When reading the code, beginning on line 200 there is the else case which
handles values of types other than int or float:

        else:
            v=str(v)
            if not v and t=='nb':
                raise ValueError, (
                    'Invalid empty string value for <em>%s</em>' % name)

            v=md.getitem('sql_quote__',0)(v)
            #if find(v,"\'") >= 0: v=join(split(v,"\'"),"''")
            #v="'%s'" % v

There is absolutely no check for the optional flag in this case as there
are in the cases for int and float. Is this check supposed to be handled
elsewhere in the code, and never make it here, or is this an oversight? I
can patch it to fix the problem quite easily, but if this is not the
preferred way of doing things I'd like to know (to avoid patching it every
time a new Zope comes out.)

I have two address lines, address1 and address2. I just want it to set
address2 to null if the user does not fill it out. Is that too much to
ask? :^)

As I said, if I'm blatantly overlooking something, please let me know. If
not, I'll be happy to submit a patch and/or report this in the collector.

Thanks. Hope you all are having a good weekend!

jkh