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 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 import queryForResults
from import IZopeDatabaseAdapter

class EditRoles:
    """This class reads a form data and updates Permissions """

    def getPrincipals(self):
            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/", 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/", 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?

Zope3-users mailing list
Zope3-users mailing list

Reply via email to