[Zope] sql SELECT from a list - Beginner's Question

Todd Graham tgraham@speakeasy.net
Sat, 15 Dec 2001 10:53:20 -0800


I think you want to get the values returned from your form into a list and
then pass that list to a sql method as an "in list" rather than a series of
"or" statements.  You'll probably get much better performance out of it as
well.


The key is to get the html form to pass a "list" which can be done in a
couple of ways depending on how you want to set up the form.

<form action="parse_my_list">
<dtml-in sel_all_values>
  <input type=checkbox name=foo:list value="v1"><dtml-var v1><br>
</dtml-in>

<input type="submit">
</form>


>> create a zsql method named sel_all_values

arguments: none
select * from table_name

>> should return v1 and v2

parse_my_list  in this example is a dtml-method

the dtml method calls the zsqlmethod sel_from_list and passes the list of
values that are contained in the attribute foo


<dtml-in sel_from_list>
   <dtml-var id>
</dtml-in>

>> create a zsql method named sel_from list
sel_from_list

arguments: foo

select * from table_name
where <dtml-sqltest foo column_name=v1 type=nb multiple>


The sqltest operator is a zope specific piece of vodoo that will magically
convert the returned values to an in list if more than one are recieved.


Hope this helps

Todd
----- Original Message -----
From: Herring, William O. <WHerring@mail.ifas.ufl.edu>
To: <zope@zope.org>
Sent: Saturday, December 15, 2001 8:43 AM
Subject: [Zope] sql SELECT from a list - Beginner's Question


> I have a sql table which has 2 columns, v1 and v2.  v1 is unique.  I want
to
> allow the user to enter up to 50 or less possible v1's, of their own
> choosing, and then simply view them.  So the form page would have entries
> for up to 50 entry requests for v1.  However, they may enter only 25, 30,
> 40, whatever they would like.   So the sql without zope, if there were
only
> 3 records requested, might look like:
>
> SELECT v1, v2, FROM tablename
>    WHERE v1='1' or v1='3' or v1='5';
>
> How do I build the form, sql method, and return list to accomplish this?
> I'm sure this has been done, so if someone could point me to a HOWTO or an
> example, it would be greatly appreciated.  --Thanks.
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
>