SunQuest
 
       Zope
  Home arrow Zope arrow Page 6 - Zope And MySQL
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ZOPE

Zope And MySQL
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 26
    2002-04-10

    Table of Contents:
  • Zope And MySQL
  • Making The Connection
  • Adapting To The Environment
  • The Magic Of The Movies
  • Visiting The Box Office
  • Adding Things Up
  • Submitting To The King
  • Erasing The Past
  • Of Methods And Madness

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Zope And MySQL - Adding Things Up


    (Page 6 of 9 )

    Next, how about adding a new record to the table?

    Here too, the process is similar - first create a Z SQL Method containing an INSERT query, and then invoke the Method from a DTML script. There's one important difference here, though - since the data to be entered is not hard-wired, but rather user-defined, the query string must be constructed dynamically.

    In order to see how this works, create a new Z SQL Method - I've called mine "insertMethod" - and add the following values to the argument field:

    title director cast genre
    These arguments can then be used to dynamically construct a query. Here's what I would put into the query template:

    INSERT INTO dvd (title, director, cast, genre) values (<dtml-sqlvar title type="string">, <dtml-sqlvar director type="string">, <dtml-sqlvar cast type="string">, <dtml-sqlvar genre type="string">)
    I'm sure the linkage between the arguments and the query template is now clear - the arguments passed to the Z SQL Method can be accessed in the query template to dynamically create a new INSERT query every time the method is invoked.

    In case you're wondering, the <dtml-sqlvar> construct is very similar to the <dtml-var> construct, except that it comes with a couple of additional, SQL-specific features - for example, the "type" attribute, which makes it possible to specify the data type of the values being inserted and thereby catch errors before the data gets inserted into the database, and the ability to automatically "quote" values before inserting them into the database.

    So that takes care of the SQL. Now, how about a form to invoke this method and pass arguments to it?

    <dtml-var standard_html_header> <h2>Add DVD</h2> <form action="someFormProcessor" method="POST"> <table border=0> <tr> <td>Title</td> <td><input name="title" width=30 value=""></td> </tr> <tr> <td>Director</td> <td><input name="director" width=30 value=""></td> </tr> <tr> <td>Cast</td> <td><input name="cast" width=30 value=""></td> </tr> <tr> <td>Genre</td> <td><input name="genre" width=30 value=""></td> </tr> <tr> <td colspan=2 align=center> <input type="submit" name="submit" value="Add DVD"> </td> </tr> </table> </form> <dtml-var standard_html_footer>
    Here's what it looks like:



    When this form is submitted, the form processor will need to invoke the "insertMethod" Z SQL Method, use the form variables to dynamically fill up the query template and execute the INSERT query. Here's what it looks like:

    <dtml-var standard_html_header> <dtml-call insertMethod> <h2>Item added!</h2> <p> <a href="list">View the entire collection</a> or <a href="add">add another title</a> <dtml-var standard_html_footer>
    Fairly simple, this - the <dtml-call> construct is used to invoke the selected Z SQL Method, and a neat little result screen is displayed. The form variables submitted to the form processor are automatically picked up by the Z SQL Method and used to construct the INSERT query string.

    Here's what it looks like:

    More Zope Articles
    More By icarus, (c) Melonfire


     

       

    ZOPE ARTICLES

    - Creating Zope Products
    - Plone Content Types With Archetypes
    - Flat User Management in Zope
    - Creating Basic Zope Applications
    - Getting started with Zope for Linux and Sola...
    - ZPT Basics (part 4)
    - ZPT Basics (part 3)
    - ZPT Basics (part 2)
    - ZPT Basics (part 1)
    - Exception Handling In DTML
    - DTML Basics (part 4)
    - DTML Basics (part 3)
    - DTML Basics (part 2)
    - DTML Basics (part 1)
    - Using Zope With Apache





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway