Integration of relational
databases in ZOPE
Authors: Cornel Nitu
Alin Voinea
The Zope Object Database (ZODB) is used to store all the pages, files and other objects you create.
It is fast and requires almost no setting up or maintenance. Like a file system, it is especially good
at storing moderately-sized binary objects such as graphics.
Relational Databases work in a very different way. They are based on tables of data such as this:
First Name
Last Name
Common Relational Databases for which Zope connection is
Here are some of the more popular database systems for which Zope connection support is
Oracle is arguably the most powerful and popular commercial relational database. It is,
however, relatively expensive and complex. Oracle can be purchased or evaluated from the
Oracle Website.
DB2 from IBM is the main commercial competitor to Oracle. It has similar power but also
similar expense and complexity. More information from
PostgreSQL is a leading open source relational database with good support for SQL standards.
You can find more information about PostgreSQL at the PostgreSQL web site.
MySQL is a fast open source relational database. You can find more information about
MySQL at
An open source database developed by SAP. Has an Oracle 7 compatibility mode. More
information and downloads from
Sybase is another popular commercial relational database. Sybase can be purchased or
evaluated from the Sybase Website.
SQL Sever
Microsoft's full featured SQL Server for the Windows operating systems. For any serious use
on Windows, it is preferable to Microsoft Access. Information from
Interbase is an open source relational database from Borland/Inprise. You can find more
information about Interbase at theBorland web site. You may also be interested in FireBird
which is a community maintained offshoot of Interbase. The Zope Interbase adapter is
maintained by Zope community member Bob Tierney.
Gadfly is a relational database written in Python by Aaron Waters. Gadfly is included with
Zope for demonstration purposes and small data sets. Gadfly is fast, but is not intended for
large amounts of information since it reads its entire data set into memory. You can find out
more about Gadfly at
For more information about connecting this databases with ZOPE see
Solution #1 MS Access
Microsoft Office Access, previously known as Microsoft Access, is a relational database
management system from Microsoft which combines the relational Microsoft Jet Database Engine
with a graphical user interface and software development tools.
To use MS Access with ZOPE you will need a commercial database adapter product (mxODBC)
and a ZOPE adapter (mxODBC Zope Database Adapter). These adapters can be downloaded
from the website. The installation instructions are included in the
To define a new data source type add this section to /etc/odbcinst.ini (the odbcinst.ini configuration
file may be in a different location on your machine):
Description = MDB Tools ODBC drivers
= /usr/lib/
Note that the file may be located in a different directory on your machine.
Finally, define a new database connection in the /etc/odbc.ini file (the odbc.ini configuration file
may be in a different location on your machine):
Description = Microsoft Access Database
Driver = MDBToolsODBC
Database = /tmp/example.mdb
Servername = localhost
UserName =
Password =
port = 5432
Use ‘isql example_test’ to test your connection. If the message is ‘Connected!’ everything should
be ok. Now, start the ZOPE server, login into ZMI and add a new eGenix mxODBC Database
And test your connection by executing a simple query:
If everything went well, you should create Z SQL Methods in order to interrogate your database
(see example in the next section).
Another way (cost free) would be to convert your MS Access database structure and data to
MySQL format using MDB Tools.
First download and install the MDB Tools package from and
checkout the ‘mdb2mysql’ script from EEA's Subversion repository (
Now use the mdb2mysql script to generate a MySQL dump from the MS Access database:
| mdb2mysql /tmp/example.mdb > example.sql
Run MySQL, create a new database and import the example.sql file. Instructions how to hook Zope
up to a MySQL database you will find in the next chapter.
2. MySQL
MySQL, the most popular Open Source SQL database management system, is developed,
distributed, and supported by MySQL AB. MySQL AB is a commercial company, founded by the
MySQL developers. It is a second generation Open Source company that unites Open Source values
and methodology with a successful business model.
To use MySQL with ZOPE you'll need a database adapter product called ZMySQLDA
(Zope MySQL Database Adapter).
The latest stable release can be downloaded from
ZMySQLDA depends on:
mysql-python (
Installing mysql, mysql-devel
yum install mysql mysql-devel
apt-get install mysql mysql-devel
Installing mysql-python
1. Download latest stable release from
2. Untar, unzip package
3. Run:
<path/to/python/used/by/zope> install
Installing ZmySQLDA
1. Download latest stable release from
2. Untar, unzip
3. Copy ZmySQLDA into your Zope Products directory
4. Run:
<path/to/python/used/by/zope> install
5. Restart zope
Zope connect and test
To add/edit databases, users, tables, grant access see
Login into ZMI and add a Z MySQL Database Connection
To browse available tables see Browse Tab
To test connection see the Test Tab
Z SQL Methods
Z SQL Methods are Zope objects that execute SQL code through a Database Connection. All Z SQL
Methods must be associated with a Database Connection. Z SQL Methods can both query and
change database data. Z SQL Methods can also contain more than one SQL command.
A ZSQL Method has two functions: it generates SQL to send to the database and it converts the
response from the database into an object.
Examples of ZSQL Methods
Create a new Z SQL Method called view that returns title and description from the chm table,
filtered and sorted by title.
SELECT title, description FROM chm WHERE
title LIKE <dtml-sqlvar title type="string">
ORDER BY title
Using ZSQL Methods
Add a Page Template named index and insert the following code:
<tal:block define="title request/title|string:">
<!-- Search -->
<form action="index">
<input type="text" name="title" tal:attributes="value title" />
<input type="submit" name="submit" value="GO" />
<!-- Results -->
<th i18n:translate="">Title</th>
<th i18n:translate="">Description</th>
<tr tal:repeat="item python:here.view(title=title).dictionaries()">
<td tal:content="item/title" />
<td tal:content="item/description" />
Related documents