[Zope] howto_database

Ken Kinder kkinder@messagemedia.com
Mon, 10 Apr 2000 16:13:00 -0600


The first thing you need to do is find an adapter for your database.
Zope has database adapters which generalize the interface with the
database, therefor making it transparent to other Zope components.

You can find some database adapters on http://www.zope.org/Products
such as the Oracle one.

Follow the installation instructions on the database adapter. After
that, you will be able to create objects in Zope that represent
connections to your database. To act on those connections, you
create Z SQL query templates. Then, you can have your own DTML
documents call those ZSQL queries... Here is a practical example:

Say you have a table: clients and you want to display a list of
clients on your web page. If the client is paying you more than
$1,000,000 you want it displayed in red. Here might be the create
table script for the clients table:

	create table clients (
	id number,
	name varchar2(60),
	amount_paying number
	);

(Of course, that kind of thing depends on db -- this is Oracle'ish).
Say your database service name is scooby and you already have
Oracle stuff set up on the server running Zope. Download the Zope
Oracle adapter from the URL above, and install it. You will be able
to create a "ZOracle Database Connection" in the Add box on the
Zope management screen. You enter your login stuff and create the
database connection. Next, you want to write the query template that
gets a list of clients. You add a Z SQL query in Zope and define the
query like this:

	select * from clients order by name

Assume you called the template qryClient. To use it inside a DTML
document, you would do something like...

	<h1>Client List</h1>
	<table border=1>
	  <tr><th>id</th><th>Name</th><th>Amount Paying</th></tr>
	  <dtml-in qryClients>
           <dtml-if "amount_paying > 1000000">
	    <tr><td><dtml-var id></td><td><font color=red><dtml-var
name></font></td><td><dtml-var amount_apying</td></tr>
	   <dtml-else>
	    <tr><td><dtml-var id></td><td><dtml-var name></td><td><dtml-var
amount_apying</td></tr>
           </dtml-if>
	  </dtml-in>
	  </table>

... Hope this helps

Mario Premke wrote:
> 
> Hi everybody,
> my question is, how to put a relational database in the back of zope.
> I want to make queries from a web-page and the results be shown on a
> page - I cannot find any hint on the zope-pages which interface
> is to be used for this purpose ...
> Any hints will be appreciated ..
> Greetings
> Mario
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )

-- 
Ken Kinder
303.381.7631