SQL Methods - tokens or list parameters
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
"Ross J. Reedstrom" wrote:
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?
I can't reproduce this. :tokens should always give a list.
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>
Where is ':tokens'? Jim -- Jim Fulton mailto:jim@digicool.com Technical Director (888) 344-4332 Python Powered! Digital Creations http://www.digicool.com http://www.python.org Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email address may not be added to any commercial mail list with out my permission. Violation of my privacy with advertising or SPAM will result in a suit for a MINIMUM of $500 damages/incident, $1500 for repeats.
Jim Fulton wrote: <can't reproduce my problem>
in add_person_form:
<... rest of form/table deleted> <tr><td>PerDegree</td><td><input type=text name=PerDegree></td></tr>
Where is ':tokens'?
In the parameters list to the SQL-Method. That seems to do it for the space containing case. I didn't persue this any farther, since the natural seperator for degrees is a comma, and I got the list case working. I think it's a case of my being a python newbie as well as a zope newbie (and a sql newbie, and an HTML newbie, and ... Hey, I know Tcl, does that count? ;-) Here's what I did for the list: add_person_form send string to add_person_action, which contains: <!--#call "add_per_degree(PerID=PerID, PerDegree=_.string.split(PerDegree,','), ConferringInstitution=ConferringInstitution, DegreeDate=DegreeDate)"--> and add_per_degree is: Aguments: PerID:int PerDegree:list ... <!--#in PerDegree --> ... This may seem an unnatural way to do things. I have that familiar itch that I'm not quite groking something here - It's the Zope Zen, probably. Need that flash of enlightenment. Ahh! Minor flash - the name:type syntax applies to form inputs as well, doesn't it? I can make my original form like: <tr><td>PerDegree</td><td><input type=text name=PerDegree:list></td></tr> then remove the string.split from add_person_action or some such? Thanks, Ross -- 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
"Ross J. Reedstrom" wrote:
Jim Fulton wrote:
<can't reproduce my problem>
in add_person_form:
<... rest of form/table deleted> <tr><td>PerDegree</td><td><input type=text name=PerDegree></td></tr>
Where is ':tokens'?
In the parameters list to the SQL-Method. That seems to do it for the space containing case. I didn't persue this any farther, since the natural seperator for degrees is a comma, and I got the list case working. I think it's a case of my being a python newbie as well as a zope newbie (and a sql newbie, and an HTML newbie, and ... Hey, I know Tcl, does that count? ;-)
Here's what I did for the list:
add_person_form send string to add_person_action, which contains:
<!--#call "add_per_degree(PerID=PerID, PerDegree=_.string.split(PerDegree,','), ConferringInstitution=ConferringInstitution, DegreeDate=DegreeDate)"-->
and add_per_degree is:
Aguments: PerID:int PerDegree:list ...
<!--#in PerDegree --> ...
This may seem an unnatural way to do things. I have that familiar itch that I'm not quite groking something here - It's the Zope Zen, probably. Need that flash of enlightenment. Ahh! Minor flash - the name:type syntax applies to form inputs as well, doesn't it?
Yes.
I can make my original form like:
<tr><td>PerDegree</td><td><input type=text name=PerDegree:list></td></tr>
then remove the string.split from add_person_action or some such?
Yup. The type information in the argument list is there soley to aid input form generation wizards. If you selected "Z Search Interface" from the "Add" menu, the generated input form would reflect the type information specified in the argument list. Jim -- Jim Fulton mailto:jim@digicool.com Technical Director (888) 344-4332 Python Powered! Digital Creations http://www.digicool.com http://www.python.org Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email address may not be added to any commercial mail list with out my permission. Violation of my privacy with advertising or SPAM will result in a suit for a MINIMUM of $500 damages/incident, $1500 for repeats.
participants (2)
-
Jim Fulton -
Ross J. Reedstrom