[Zope] SQL Methods - tokens or list parameters

Ross J. Reedstrom reedstrm@rice.edu
Tue, 02 Feb 1999 14:22:39 -0600


Hi all - 
I've got a form feeding an SQL insert query where I  need to be able to
allow the user to enter a list of items into a single form entry, which
is parsed by the SQL method into multiple 'insert' commands into a
table. I want to do this in the SQL Method, rather than my action page,
to avoid one level of calls. This looks like a job for a param:list type
parameter, and a #in param block, but I haven't been able to get that to
work. My comma separated list ends up being treated as a single item
list.  So, I decided to try the param:tokens trick - this worked great,
with a space separated list, but fails when there's only one item
entered - that returns a string, which gives me a "can't use a string
with #in" error. Any ideas?

Here's what I've got:

in add_person_form:

<... rest of form/table deleted>
<tr><td>PerDegree</td><td><input type=text name=PerDegree></td></tr>
<...>
Which calls to: add_person_action:


<!--#if PerDegree -->
<!--#call "add_per_degree(PerID=PerID, PerDegree=PerDegree,
ConferringInstitution=ConferringInstitution, DegreeDate=DegreeDate)"-->
<!--#/if-->

And here's add_per_degree: (token version)

Arguments: PerID:int PerDegree:tokens ConferringInstitution:string
DegreeDate:string

<!--#in PerDegree-->
insert into "PersonnelDegrees" (
"PerID","PerDegree","ConferringInstitution","DegreeDate")
values (<!--#sqlvar PerID type=int-->,
<!--#sqlvar expr=_['sequence-item'] type=string-->,
<!--#sqlvar ConferringInstitution type=string optional-->
<!--#sqlvar DegreeDate type=string optional-->)
<!--#var sql_delimiter-->
<!--#/in-->

-- 
Ross J. Reedstrom, Ph.D., <reedstrm@rice.edu> 
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St.,  Houston, TX 77005