-Original Message-
From: Charlie Clark [mailto:[EMAIL PROTECTED]
Sent: Saturday, June 16, 2007 6:24 PM
To: Ken Winter; 'Zope-DB List'
Subject: Re: [Zope-DB] Using dtml-vars 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