[Zope-DB] Using <dtml-var>s in ZSQL methods?
ken at sunward.org
Fri Jun 15 23:15:44 EDT 2007
Here's the definition of a ZSQL method, "people_delete_by_id.zsql":
title: Method to delete People by ids given in a comma-separated list
delete from person
where person_id in (<dtml-var id_list>)
Here's the puzzle:
When I define and test this ZSQL method through the ZMI, passing it a string
such as "9765, 10058, 11333", it indeed deletes the rows with those values
BUT when I invoke the same ZSQL method from a Python script with the
p = context.REQUEST.get('delete_this')
s = ', '.join([str(x) for x in p])
...and with a REQUEST variable 'delete_this' that comes from this snippet of
a form in a page template:
<form method="post" name="form2"
<input type="hidden" name="form.submitted" value="1" />
<p class="error_message" tal:define="err errors/n|nothing"
tal:condition="err"><b tal:content="err" /></p>
<tr tal:repeat="person options/data"><a name="id" id="id"
<td tal:condition="not:options/selectall | nothing"
<input type="checkbox" name="delete_this:list:int" value=""
...and with the same three person_ids (9765, 10058, 11333) the 4th line of
the Python script evokes an error:
The core idea is that the string id_list is passed into the ZSQL method,
where it is spliced into the "delete...where" clause via the <dtml-var
id_list>) to provide the list of person_ids to delete.
Here's the question:
P.S. I know that <dtml-var...> rather than <dtml-sqlvar...> is an
unorthodox and apparently undocumented construct to use within a ZSQL
definition. But I need it because <dtml-sqlvar...> malformats the string.
And if doing this trick is a no-no, how come it works in the ZMI test but
not when called from Python? More importantly, how can I get it to work
More information about the Zope-DB