[ZPT] ZPT and ZSQL Methods

robert rottermann robert at redcor.ch
Thu Jul 15 03:05:57 EDT 2004


This is easy,
create the following objects. You can fold them into two (one form and 
one zsql method) but it is a bit easier to "see" what happens with 4:

- a ZSQL Method sqlGetNames (that *must* use dtml) with two parameters 
firstname, lastname you use to construct  a query.
- a form getusers_form with two input fields named
firstname, lastname and and action called getnames
- a python script named getnames that gets two parameters firstname, 
lastname
- an outputform named showusers that presents the result in a table

Here is a sketch of the four objects:

#----------------------
# sqlGetNames
# parameters :
#  firstname. lastname
#----------------------
select firstname. lastname from tblEmployee
where firstname. like <dtml-sqlvar firstname. type=string> +'%'
and   lastname like <dtml-sqlvar Lastname ype=string> + '%';

#----------------------
# getusers_form
#----------------------
<form action="getnames">
   <input type="text" name="firstname">
   <input type="text" name="lastname">
   <input type="submit" >
</form>

#----------------------
# getnames
# parameters :
#  firstname. lastname
#----------------------
users = context.sqlGetNames(firstname=firstname, lastname=lastname)
return context.showusers(users=users)

#----------------------
# show_form
#----------------------
<table tal:define="users options/users">
   <tr tal:repeat="user users">
     <td tal:ontent="user/firstname" />
     <td tal:ontent="user/lastname" />
   </tr>
</table>


I have included ein "realworld" example where everyting is folded into a 
single form (input, call to ZSQL Method and Output)
The used ZSQL Method and its parameters are paste in as comment.

Robert


Joao Paulo Liberato wrote:
> Hi everybody,
> 
> I have a very basic question.  I'm starting with Zope, and I'd like to 
> grab some data from a MySQL database.
> The DA for MySQL was installed without any problem, and I could connect 
> to my database.
> I was reading the Zope Book, chapter 18 - Relational Database 
> Connectivity, and all examples were given using DTML.
> But I don't want to use dtml.  Hence, I'd like to know how can I use ZPT 
> to call a ZSQL method, passing parameters to it, and how to process 
> those parameters within the ZSQL Method.
> Can anyone provide me a basic example of how to do it?
> 
> Thanks in advance,
> 
> Joao Paulo.
> _______________________________________________
> ZPT mailing list
> ZPT at zope.org
> http://mail.zope.org/mailman/listinfo/zpt
> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zpt/attachments/20040715/2095f337/telephone_list_form.htm


More information about the ZPT mailing list