Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Zope: DB
Using <dtml-var>s in ZSQL methods?
 

Index | Next | Previous | View Flat


ken at sunward

Jun 15, 2007, 8:15 PM


Views: 2577
Permalink
Using <dtml-var>s in ZSQL methods?

Here's the definition of a ZSQL method, "people_delete_by_id.zsql":

"
<dtml-comment>
title: Method to delete People by ids given in a comma-separated list
connection_id: my_database
arguments:
id_list
</dtml-comment>

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
on person_id.

BUT when I invoke the same ZSQL method from a Python script with the
following code:

"
p = context.REQUEST.get('delete_this')
if p:
s = ', '.join([str(x) for x in p])
context.people_delete_by_id(id_list=s)
"

...and with a REQUEST variable 'delete_this' that comes from this snippet of
a form in a page template:

"
<form method="post" name="form2"
tal:attributes="action string:${here/absolute_url}/${template/id};">

<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>

<table>
<tr tal:repeat="person options/data"><a name="id" id="id"
tal:attributes="name person/person_id"></a>
<td tal:condition="not:options/selectall | nothing"
<input type="checkbox" name="delete_this:list:int" value=""
tal:attributes="value person/person_id"/>
</td>
...
</tr>
</table>
...
</form>
"

...and with the same three person_ids (9765, 10058, 11333) the 4th line of
the Python script evokes an error:

"
KeyError: 'id_list'
"

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:

WHY?

~ TIA
~ Ken

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
from Python?

_______________________________________________
Zope-DB mailing list
Zope-DB[at]zope.org
http://mail.zope.org/mailman/listinfo/zope-db

Subject User Time
Using <dtml-var>s in ZSQL methods? ken at sunward Jun 15, 2007, 8:15 PM
    Re: Using <dtml-var>s in ZSQL methods? lukesh at seznam Jun 15, 2007, 10:41 PM
        RE: Using <dtml-var>s in ZSQL methods? ken at sunward Jun 16, 2007, 12:19 PM
            RE: Using <dtml-var>s in ZSQL methods? lists at zopyx Jun 16, 2007, 12:27 PM
                RE: Using <dtml-var>s in ZSQL methods? ken at sunward Jun 16, 2007, 1:03 PM
                    RE: Using <dtml-var>s in ZSQL methods? dieter at handshake Jun 17, 2007, 11:50 AM
            Re: Using <dtml-var>s in ZSQL methods? charlie at egenix Jun 16, 2007, 12:54 PM
                RE: Using <dtml-var>s in ZSQL methods? ken at sunward Jun 16, 2007, 3:14 PM
                    Re: Using <dtml-var>s in ZSQL methods? charlie at egenix Jun 16, 2007, 3:24 PM
                        RE: Using <dtml-var>s in ZSQL methods? ken at sunward Jun 17, 2007, 11:22 AM
                            Re: Using <dtml-var>s in ZSQL methods? maciej.wisniowski at coig Jun 17, 2007, 10:33 PM
                                RE: Using <dtml-var>s in ZSQL methods? ken at sunward Jun 18, 2007, 8:37 AM
                            RE: Using <dtml-var>s in ZSQL methods? JPenny at ykksnap-america Jun 18, 2007, 7:03 AM
    Re: Using <dtml-var>s in ZSQL methods? maciej.wisniowski at coig Jun 17, 2007, 10:42 PM
    Re: Using <dtml-var>s in ZSQL methods? charlie at egenix Jun 18, 2007, 7:30 AM
    RE: Using <dtml-var>s in ZSQL methods? ken at sunward Jun 18, 2007, 1:10 PM
        Re: Using <dtml-var>s in ZSQL methods? charlie at egenix Jun 18, 2007, 1:44 PM

  Index | Next | Previous | View Flat
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.