Zope And MySQL - Erasing The Past
(Page 8 of 9 )
So that takes care of adding records. Now, how about deleting them?
You'll remember, from the "list" DTML Method created at the beginning of this exercise, that every item in the DVD list has links pointing to "edit" and "delete" objects, and that these objects are passed the record ID of the corresponding item.
<font size="-1"><a href="edit?id=<dtml-var id>">edit</a> | <a
href="delete?id=<dtml-var
id>">delete</a></font>
So, in other words, the "delete" object - another DTML Method - needs simply
to use this ID to execute a DELETE query on the table. Let's take a look at the code for this DTML Method:
<dtml-var standard_html_header>
<dtml-call deleteMethod>
<h2>Item
deleted!</h2>
<p>
<a href="list">View the entire collection</a>
or <a href="add">add
another title</a>
<dtml-var standard_html_footer>
No biggie. Like the "add" DTML Method before it, this one too simply functions
as a wrapper for a Z SQL Method, which actually does all the work. In this case, the Z SQL Method is named "deleteMethod" and it receives a record ID as argument. Let's see what that looks like:
DELETE FROM dvd WHERE id = <dtml-sqlvar id type="int">
The "deleteMethod" Z SQL Method contains a simple DELETE query, with the record
ID passed to it inserted dynamically into the query template.
Here's what the result page looks like:

Next: Of Methods And Madness >>
More Zope Articles
More By icarus, (c) Melonfire