[Zope-DB] Using <dtml-var>s in ZSQL methods?
Ken Winter
ken at sunward.org
Sun Jun 17 14:22:37 EDT 2007
> -----Original Message-----
> From: Charlie Clark [mailto:charlie at egenix.com]
> Sent: Saturday, June 16, 2007 6:24 PM
> To: Ken Winter; 'Zope-DB List'
> Subject: Re: [Zope-DB] Using <dtml-var>s in ZSQL methods?
>
...
> FWIW you
> might want to call the query or execute methods directly on the DA
> connection object if they are supported.
ZPsycopgDA is my database adapter. I haven't found any documentation of
ZPsycopgDA's methods except its code. In the code, I found a class "DB"
with a "query" method (which in turn uses "execute" and "fetchall" methods,
whose definitions I can't locate).
I tried to invoke the "query" method of my adapter (which is named
"dhatabase") with this code:
"
p = context.REQUEST.get('delete_this')
if p:
s = ', '.join([str(x) for x in p])
t = "delete from person where person_id in (%s);" % s
context.dhatabase.query(query_string=t)
"
...and got this error: "AttributeError: query" (full traceback at end of
message). What's wrong with my method call?
I also have a broader question: When one is composing dynamic SQL in Python
scripts, what are the pros and cons of executing them by going directly to
the database adapter (as suggested above) vs passing it in as the sole
argument of an "empty" ZSQL method? By "empty" ZQL method I mean something
like:
"
<dtml-comment>
title: Query whose whole body is passed in as an argument
connection_id: dhatabase
arguments: foo
</dtml-comment>
<dtml-var foo>
"
~ Thanks
~ Ken
P.S. Full details of error:
"
Time
2007-06-17 13:59
User Name
admin (admin)
Request URL
http://localhost/DAgroups/portal_factory/People/people.2007-06-17.6691253086
/people_edit
Exception Type
AttributeError
Exception Value
query
Traceback (innermost last):
* Module ZPublisher.Publish, line 115, in publish
* Module ZPublisher.mapply, line 88, in mapply
* Module ZPublisher.Publish, line 41, in call_object
* Module Products.CMFPlone.FactoryTool, line 369, in __call__
* Module ZPublisher.mapply, line 88, in mapply
* Module ZPublisher.Publish, line 41, in call_object
* Module Products.CMFFormController.FSControllerPageTemplate, line 90,
in __call__
* Module Products.CMFFormController.BaseControllerPageTemplate, line 28,
in _call
* Module Products.CMFFormController.ControllerBase, line 232, in getNext
__traceback_info__: ['id = people_edit', 'status = success',
'button=delete', 'errors={}', 'context=<People at
people.2007-06-17.6691253086>', "kwargs={'portal_status_message': 'People
allegedly deleted: 69394, 77084'}", 'next_action=None', '']
* Module Products.CMFFormController.Actions.TraverseTo, line 38, in
__call__
* Module ZPublisher.mapply, line 88, in mapply
* Module ZPublisher.Publish, line 41, in call_object
* Module Products.CMFFormController.FSControllerPythonScript, line 104,
in __call__
* Module Products.CMFFormController.Script, line 145, in __call__
* Module Products.CMFCore.FSPythonScript, line 108, in __call__
* Module Shared.DC.Scripts.Bindings, line 311, in __call__
* Module Shared.DC.Scripts.Bindings, line 348, in _bindAndExec
* Module Products.CMFCore.FSPythonScript, line 164, in _exec
* Module None, line 6, in people_delete_control
<FSControllerPythonScript at /DAgroups/people_delete_control used for
/DAgroups/portal_factory/People/people.2007-06-17.6691253086>
Line 6
AttributeError: query
REQUEST
form
delete_this [69394, 77084]
form.button.delete 'Delete Selected People'
cookies
tree-s 'eJzTyCkw5NLIKTDiClZ3hANXW3WuAmOuRKCECUjWFEnWNTEbJGvGlQgEegAEWRAt'
__ac 'YWRtaW46cHAyMTA3'
lazy items
SESSION <bound method SessionDataManager.getSessionData of
<SessionDataManager at /session_data_manager>>
other
tree-s 'eJzTyCkw5NLIKTDiClZ3hANXW3WuAmOuRKCECUjWFEnWNTEbJGvGlQgEegAEWRAt'
__factory__info__ {'stack': ['People', 'people.2007-06-17.6691253086',
'people_edit'], 'People': <TempFolder at /DAgroups/portal_factory/People>}
URL5 'http://localhost'
URL4 'http://localhost/DAgroups'
__ac 'YWRtaW46cHAyMTA3'
URL0
'http://localhost/DAgroups/portal_factory/People/people.2007-06-17.669125308
6/people_edit'
URL3 'http://localhost/DAgroups/portal_factory'
URL2 'http://localhost/DAgroups/portal_factory/People'
AUTHENTICATION_PATH ''
AUTHENTICATED_USER <PropertiedUser 'admin'>
SERVER_URL 'http://localhost'
delete_this [69394, 77084]
form.button.delete 'Delete Selected People'
ACTUAL_URL
'http://localhost/DAgroups/portal_factory/People/people.2007-06-17.669125308
6/people_edit'
portal_status_message 'People allegedly deleted: 69394, 77084'
URL
'http://localhost/DAgroups/portal_factory/People/people.2007-06-17.669125308
6/people_edit'
PUBLISHED <FactoryTool at /DAgroups/portal_factory>
controller_state
<Products.CMFFormController.ControllerState.ControllerState object at
0x0681DB10>
TraversalRequestNameStack []
BASE0 'http://localhost'
BASE1 'http://localhost/DAgroups'
BASE2 'http://localhost/DAgroups/portal_factory'
BASE3 'http://localhost/DAgroups/portal_factory/People'
BASE4
'http://localhost/DAgroups/portal_factory/People/people.2007-06-17.669125308
6'
BASE5
'http://localhost/DAgroups/portal_factory/People/people.2007-06-17.669125308
6/people_edit'
URL1
'http://localhost/DAgroups/portal_factory/People/people.2007-06-17.669125308
6'
URL0
http://localhost/DAgroups/portal_factory/People/people.2007-06-17.6691253086
/people_edit
URL1
http://localhost/DAgroups/portal_factory/People/people.2007-06-17.6691253086
URL2 http://localhost/DAgroups/portal_factory/People
URL3 http://localhost/DAgroups/portal_factory
URL4 http://localhost/DAgroups
URL5 http://localhost
BASE0 http://localhost
BASE1 http://localhost/DAgroups
BASE2 http://localhost/DAgroups/portal_factory
BASE3 http://localhost/DAgroups/portal_factory/People
BASE4
http://localhost/DAgroups/portal_factory/People/people.2007-06-17.6691253086
BASE5
http://localhost/DAgroups/portal_factory/People/people.2007-06-17.6691253086
/people_edit
environ
HTTP_COOKIE
'tree-s="eJzTyCkw5NLIKTDiClZ3hANXW3WuAmOuRKCECUjWFEnWNTEbJGvGlQgEegAEWRAt";
__ac="YWRtaW46cHAyMTA3"'
SERVER_SOFTWARE 'Zope/(Zope 2.9.6-final, python 2.4.3, win32) ZServer/1.1
Plone/2.5.2'
SCRIPT_NAME ''
REQUEST_METHOD 'POST'
HTTP_KEEP_ALIVE '300'
SERVER_PROTOCOL 'HTTP/1.1'
channel.creation_time 1182103175
CONNECTION_TYPE 'keep-alive'
HTTP_ACCEPT_CHARSET 'ISO-8859-1,utf-8;q=0.7,*;q=0.7'
HTTP_USER_AGENT 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1)
Gecko/20061204 Firefox/2.0.0.1'
HTTP_REFERER
'http://localhost/DAgroups/portal_factory/People/people.2007-06-17.669125308
6/people_read_for_edit_control?portal_status_message=People%20allegedly%20de
leted%3A%2069393'
SERVER_NAME 'KenIBM'
REMOTE_ADDR '127.0.0.1'
PATH_TRANSLATED
'\\DAgroups\\portal_factory\\People\\people.2007-06-17.6691253086\\people_ed
it'
SERVER_PORT '80'
CONTENT_LENGTH '120'
HTTP_HOST 'localhost'
HTTP_ACCEPT
'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q
=0.8,image/png,*/*;q=0.5'
GATEWAY_INTERFACE 'CGI/1.1'
HTTP_ACCEPT_LANGUAGE 'en-us,en;q=0.5'
CONTENT_TYPE 'application/x-www-form-urlencoded'
HTTP_ACCEPT_ENCODING 'gzip,deflate'
PATH_INFO
'/DAgroups/portal_factory/People/people.2007-06-17.6691253086/people_edit'
"
More information about the Zope-DB
mailing list