[Zope] Database call before Product installation

Cliff Ford Cliff.Ford at ed.ac.uk
Sun Dec 19 12:46:06 EST 2004


Following the discussion of ZClasses vs Products earlie this year I 
decided to convert some of my ZClass utilities to real Products, and I 
have run into an early problem. Im developing with Zope 2.7.3 and MySQL 
3.23 but don't think the versions are particularly relevant. The 
database connection works fine - I used the Connection Test tab to 
create the table I need and make an initial entry.

I want to get some information from the database during the 
instanciation sequence. I have Googled for hours, looked at other 
Products and looked at the source code for ZSQLMethods and DB and lots 
of other things, and I am stuck. This is where I have got to:

I have a dtml form that lists available connections for the user to 
select from. That passes a connection id to a second form. In the second 
form I have a bit of dtml:

<dtml-in expr="getFilters(connection_id)">
<dtml-var Filter> [just a list at this stage]
<dtml-in>

In the product I have tried this:

def getFilters(self, connection_id):
     return SQL('getFilterSQL', 'Get Filter List', connection_id, '',
     _getFiltersSQL)

where _getFiltersSQL="""
select Filter from Table
group by Filter
order by Filter
""" [just the table name at this stage - no parameters]

(which I think creates an SQL object)
It gives me this (partial) traceback on submission of Form 2:

     *  Module App.special_dtml, line 175, in _exec
     * Module DocumentTemplate.DT_In, line 685, in renderwob
     * Module Shared.DC.ZRDB.DA, line 492, in __getitem__
     * Module Shared.DC.ZRDB.Aqueduct, line 313, in __getitem__

KeyError: 0 (Also, an error occurred while attempting to render the 
standard error message.)

and I have tried this:
def getFilters(self, connection_id):
     return SQL('getFilterSQL', 'Get Filter List', connection_id, '',
     _getFiltersSQL)()

(which I think calls the SQL object)
It gives me this output:
The database connection MySQL_database_connection cannot be found. 
(Also, an error occurred while attempting to render the standard error 
message.)

and I have tried this:
def getFilters(self, connection_id):
     connection = getattr(self, connection_id)
     return connection().query(_getFiltersSQL)
(which I think calls a method of the Connection object)

I know that this returns  ([{'width': 6, 'null': 1, 'type': 't', 'name': 
'Filter'}], (('Public',),)) but the dtml-in loop does not produce 
anything. [Public is one of the Filters, nothing to do with Zope]

I would be grateful if anybody can tell me the best way to read from 
(and write to) the database before the Product is installed, or point me 
to good documentation or an example Product.

Cliff


More information about the Zope mailing list