Lesson 11. The Elvis Files

Zope cannot find the tutorial examples. You should install the tutorial examples before continuing. Choose "Zope Tutorial" from the product add list in the Zope management screen to install the examples.

If you have already installed the tutorial, you can either follow along manually, or reinstall the tutorial examples. Note: make sure that you have cookies turned on in your browser.

Everyone knows that serious web sites use databases. We agree. Let's convert our Elvis sightings system to use a relational database. This will provide us with scalability and interoperability.

Let's see how Zope gets data from a database.

  1. Click the connection Database Connection to edit it.

A Database Connection tells Zope how to access a relational database.

  1. Click the Browse tab to examine the database tables.

  2. Click the plus box next to the ELVIS_SIGHTINGS table to expand it.

Now you can see the column names and types for this table. Now let's see how to get information out of this table.

  1. Click the getSightings ZSQL Method in the lesson11 folder to edit it.

Notice that the SQL statement used to fetch information about Elvis sightings is editable in the Query template field.

  1. Click the Test tab.

  2. Click the Submit Query button.

This shows you what data the ZSQL Method returns.

A ZSQL Method is used to get information out of or into a relational database.

Now let's see how to use this ZSQL Method in a web page.

  1. Click the sightings DTML Document in the lesson11 folder to edit it.

Notice that the sightings are generated by iterating over the sightings ZSQL Method with the <dtml-in> tag.

  1. Add a line between each sighting by changing the contents of the sightings DTML Document to::

    <dtml-var standard_html_header>
    <h2><dtml-var title></h2>
    
    <dtml-in getSightings>
    <p><dtml-var date> -- <dtml-var location></p>
    <p>Reported by <dtml-var name></p>
    <p><dtml-var description></p>
    <hr>
    </dtml-in>
    
    <dtml-var standard_html_footer>
  2. Click the Change button.

  3. Click the View tab to view the document.

Summary

Zope can work with data from relational databases in the same way it treats other Zope objects.


Comments on this lesson? Email feedback.