[Zope3-Users] Database access problem from form support Class
Cliff Ford
Cliff.Ford at ed.ac.uk
Wed Mar 8 16:17:21 EST 2006
To answer my own question for the record, the query call I had that
looked like this:
result = queryForResults(connection, query)
should have looked like this:
result = queryForResults(connection(), query)
However, it would be helpful to know whether calling the database
adapter utility directly has hidden implications - the thread safety
field of IManageableZopeDatabaseAdapter returned 0 (Threads may not
share the module) and I don't know what to do about it, if anything.
Cliff
Cliff Ford wrote:
> Zope-3.2.0: I have a MySQL database Utility installed that works fine
> via its Test tab, via an SQL Script, and with that script called from a
> page template. I want to to use a simple query from a class that
> supports a form in a context that has nothing to do with the database.
> The code I have tried looks like this:
>
>
> from zope.app.rdb import queryForResults
> from zope.app.rdb.interfaces import IZopeDatabaseAdapter
>
> class EditRoles:
> """This class reads a form data and updates Permissions """
>
> def getPrincipals(self):
> try:
> connection = zapi.getUtility(IZopeDatabaseAdapter, 'mysql')
> except KeyError:
> raise AttributeError("The database connection '%s' cannot be "
> "found." % ('mysql'))
> query = "select * from z3users"
> result = queryForResults(connection, query)
>
> And when I try to invoke the form I get this error
>
> File "/usr/local/Zope320i/lib/python/cefsite/browser/editroles.py",
> line 47, in getPrincipals
> result = queryForResults(connection, query)
> File
> "/home/ceford/temp/Zope-3.2.0/build/lib.linux-i686-2.4/zope/app/rdb/__init__.py",
> line 401, in queryForResults
> cursor = conn.cursor()
> AttributeError: 'MySQLdbAdapter' object has no attribute 'cursor'
>
> Can anyone suggest what I might be missing or suggest another way of
> accessing the database?
>
> Cliff
> _______________________________________________
> Zope3-users mailing list
> Zope3-users at zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users
More information about the Zope3-users
mailing list