[Zope-DB] Form evaluation in ZSQL-Method

Andreas Tille tillea at rki.de
Thu Sep 18 07:54:25 EDT 2003


I want to implement the folowing logic:

If no item form a selection List is selected, I want to get all items from
the database as return.  In a selection list I defined

   <option value="0">All items</option>
   <option value="1">Item 1</option>
   <option value="2">Item 2</option>
   <option value="3">Item 3</option>

The Z SQL method looks like

   SELECT item FROM itmes
   <dtml-sqlgroup where>
      <dtml-sqltest iditem column=iditem   op=eq  type=eq optional>

This perfectly selects the items if I select one of them but if I want to
get all items nothing will be found.  I wanted to do the following
trick now:

I defined in PostgreSQL

 CREATE FUNCTION test_item (integer, integer) RETURNS boolean AS '
      IF $1 = 0 OR $2 = 0 OR $1 = $2 THEN
        RETURN ''t'' ;
      END IF;
      RETURN ''f'' ;
    END; ' LANGUAGE 'plpgsql';

which returns true in the case that one integer is zero or if both are
equal.  To use this I tried the following ZSQL variation:

   SELECT item FROM itmes
   <dtml-sqlgroup where>
     test_land(<dtml-sqlvar iditem type="nb">, iditem)

This works for the first 20 results of the result set but if I want to
follow the link "Next 20 results" I get the answer

       Missing input variable, iditem

Any hint what's wrong here or rather, how to do this right?

Kind regards


More information about the Zope-DB mailing list