[Zope] Db connectivity with zope

J. Cameron Cooper jccooper@rice.edu
Mon, 13 Aug 2001 10:48:07 -0500


>
>
>I am a new user in zope, then there is a need for me to incorporate an
>existing database of an org. into their newly design website so that user
>can query the database. Presently i don't know any single thing on how to
>do this. But before i started craking my brain i want to you to give me the
>fundamental concept of how this thing work.
>
Note that I'm going on the assuption (as I read elsewhere) that you're 
working with an existing MS Access database. I might warn that Access is 
probably not going to be a good solution if you're planning on pounding 
on it.

Here's a quick startup plan:

o download and install the ZODBC database adapter product. Get it from 
zope.org. Note that it is binary-only, and if you're running Zope 2.4 
(or any Python not 1.5.2) you'll need the new version.

o set up your database as an ODBC source, and create a ZODBC Database 
Connection (yay acronyms!) with this source.

o create ZSQL Methods that use this connection to query your database 
for whatever data you need. You'll need to know some SQL and probably 
some DTML as well. Use the Zope help link and look in Zope Help > DTML 
Reference for dtml-sql* tags. What these allow you to do is dynamically 
create SQL statements that are sent to the database.

o create Zope objects that use these ZSQL Methods to render the data. In 
DTML you're usually using the 'dtml-in' tag on a ZSQL method and 
'dtml-var's on the contents. Similar in ZPT and Python Scripts.

Not very hard. Remember though that if you want to pass data to a ZSQL 
Method, you have to put the attribute in the 'Arguments' field, and ZSQL 
Methods only reliably find arguments in the REQUEST of the document that 
uses it. This isn't a problem if the data comes from a form POST or GET, 
but if it comes from anywhere else you'll have to do something like 
<dtml-var "REQUEST.set('attrib','value')"> before you use the method.

        --jcc
    (something to do)