Mailing List Archive

ZPTs and database accesses
The Zope Book (version 2.7,
http://www.plope.com/Books/2_7Edition/ZPT.stx#1-8) implies that you can't do
"SQL queries" from Zope Page Templates. If this implication is correct, I
(for one) have a problem, as I'm trying to do all my work with ZPTs (rather
than DTML) in order to use my WYSIWYG HTML editor (DreamWeaver) to design my
pages.



The RDB chapter in the Zope book
(http://www.plope.com/Books/2_7Edition/RelationalDatabases.stx#1-10) shows a
ZPT example that works for getting retrieved data from the database through
ZSQL objects onto web pages. But I haven't found an example of a ZPT for an
HTML form that can take data from the web page into the database.



Could anybody tell me how to do this, or point to a reference that does? In
case it matters, the DBMS I'm using is MySQL.



- Thanks

- Ken Winter
Re: ZPTs and database accesses [ In reply to ]
--On Donnerstag, 28. April 2005 14:05 Uhr -0400 Ken Winter
<ken@sunward.org> wrote:

> The Zope Book (version 2.7,
> http://www.plope.com/Books/2_7Edition/ZPT.stx#1-8) implies that you can't
> do "SQL queries" from Zope Page Templates. If this implication is
> correct, I (for one) have a problem, as I'm trying to do all my work with
> ZPTs (rather than DTML) in order to use my WYSIWYG HTML editor
> (DreamWeaver) to design my pages.
>
>
>
> The RDB chapter in the Zope book
> (http://www.plope.com/Books/2_7Edition/RelationalDatabases.stx#1-10)
> shows a ZPT example that works for getting retrieved data from the
> database through ZSQL objects onto web pages. But I haven't found an
> example of a ZPT for an HTML form that can take data from the web page
> into the database.

You have not read the book correctly. First statement just said that you
can't SQL queries using ZPT. In Zope you specify SQL queries using
*ZSQL methods* that use DTML as markup language...this is not the same
as defining SQL inside DTML methods/documents or Page Templates.
Since ZSQL methods are first-class objects in Zope, you can call them
of course from DTML method/documents, Python Scripts *and* Zope
Pagetemplates
(as shown in the RDBMS chapter).

Hope this makes things clearer,
-aj
RE: ZPTs and database accesses [ In reply to ]
Andreas -

Thanks for your answer. I'm relieved to know that the ZPT-ZSQL combination
will suffice for database accesses. As a Zope neophyte, though, I still
need an example or tutorial showing me how to get data from page to database
via ZPTs and ZSQL objects. Can you point me to such a reference?

- Thanks, Ken

> -----Original Message-----
> From: Andreas Jung [mailto:lists@andreas-jung.com]
> Sent: Thursday, April 28, 2005 2:17 PM
> To: ken@sunward.org; zope-db@zope.org
> Subject: Re: [Zope-DB] ZPTs and database accesses
>
>
>
> --On Donnerstag, 28. April 2005 14:05 Uhr -0400 Ken Winter
> <ken@sunward.org> wrote:
>
> > The Zope Book (version 2.7,
> > http://www.plope.com/Books/2_7Edition/ZPT.stx#1-8) implies that you
> can't
> > do "SQL queries" from Zope Page Templates. If this implication is
> > correct, I (for one) have a problem, as I'm trying to do all my work
> with
> > ZPTs (rather than DTML) in order to use my WYSIWYG HTML editor
> > (DreamWeaver) to design my pages.
> >
> >
> >
> > The RDB chapter in the Zope book
> > (http://www.plope.com/Books/2_7Edition/RelationalDatabases.stx#1-10)
> > shows a ZPT example that works for getting retrieved data from the
> > database through ZSQL objects onto web pages. But I haven't found an
> > example of a ZPT for an HTML form that can take data from the web page
> > into the database.
>
> You have not read the book correctly. First statement just said that you
> can't SQL queries using ZPT. In Zope you specify SQL queries using
> *ZSQL methods* that use DTML as markup language...this is not the same
> as defining SQL inside DTML methods/documents or Page Templates.
> Since ZSQL methods are first-class objects in Zope, you can call them
> of course from DTML method/documents, Python Scripts *and* Zope
> Pagetemplates
> (as shown in the RDBMS chapter).
>
> Hope this makes things clearer,
> -aj


_______________________________________________
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db
RE: ZPTs and database accesses [ In reply to ]
On 2005-04-28 at 20:26:47 [+0200], Ken Winter <ken@sunward.org> wrote:
> Andreas -
>
> Thanks for your answer. I'm relieved to know that the ZPT-ZSQL combination
> will suffice for database accesses. As a Zope neophyte, though, I still
> need an example or tutorial showing me how to get data from page to database
> via ZPTs and ZSQL objects. Can you point me to such a reference?

Yes, the Zope book is the place to look.

You create a ZSQL method with the SQL code

You then call this method through your ZPT or better in the case of posting
from page to database a PythonScript which in turn calls the ZSQL method and
passes the parameters.

Charlie
--
Charlie Clark
eGenix.com

Professional Python Services directly from the Source
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::
_______________________________________________
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db
RE: ZPTs and database accesses [ In reply to ]
> Date: Thu, 28 Apr 2005 23:48:58 +0200
> From: Charlie Clark <charlie@egenix.com>
> Subject: RE: [Zope-DB] ZPTs and database accesses
> To: zope-db@zope.org
> Message-ID: <20050428234858.60637.19@bepc.1114682852.fake>
> Content-Type: text/plain; charset="us-ascii"
>
>
> On 2005-04-28 at 20:26:47 [+0200], Ken Winter <ken@sunward.org> wrote:
> > Andreas -
> >
> > Thanks for your answer. I'm relieved to know that the ZPT-ZSQL
> combination
> > will suffice for database accesses. As a Zope neophyte, though, I still
> > need an example or tutorial showing me how to get data from page to
> database
> > via ZPTs and ZSQL objects. Can you point me to such a reference?
>
> Yes, the Zope book is the place to look.
>
> You create a ZSQL method with the SQL code
>
> You then call this method through your ZPT or better in the case of
> posting
> from page to database a PythonScript which in turn calls the ZSQL method
> and
> passes the parameters.
>
> Charlie
> --
> Charlie Clark
> eGenix.com
>
So, is it true that for posting (moving data from page to database) it's NOT
possible to do this by a direct ZPT-to-ZSQL method call? - i.e. that it can
ONLY be done via a Python script?

I've been trying to figure out a way to do it directly, because it seemed
that if possible that would be the simplest way. But if it's not possible,
then I can stop wasting my time on that path and start learning to do it
with Python.

- Ken


_______________________________________________
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db
Re: RE: ZPTs and database accesses [ In reply to ]
Sql methods can do any type of database interaction, including inserts,
updates & deletes. You can find all kinds of documentation online about
how to do this. One example (using dtml) is here:
http://www.informit.com/articles/article.asp?p=24698

I suggest you re-read the zope database chapter, then look at some of
the code examples in zopelabs. You should also look at the Znolk SQL
Wizard from BlueDynamics.

One case where you would use an external method (python) would be
inserting blob data such as an image. Generally, you don't need to write
python for accessing text data.

Cheers,

--Aaron Fosdick


Ken Winter wrote:

>>Date: Thu, 28 Apr 2005 23:48:58 +0200
>>From: Charlie Clark <charlie@egenix.com>
>>Subject: RE: [Zope-DB] ZPTs and database accesses
>>To: zope-db@zope.org
>>Message-ID: <20050428234858.60637.19@bepc.1114682852.fake>
>>Content-Type: text/plain; charset="us-ascii"
>>
>>
>>On 2005-04-28 at 20:26:47 [+0200], Ken Winter <ken@sunward.org> wrote:
>>
>>
>>>Andreas -
>>>
>>>Thanks for your answer. I'm relieved to know that the ZPT-ZSQL
>>>
>>>
>>combination
>>
>>
>>>will suffice for database accesses. As a Zope neophyte, though, I still
>>>need an example or tutorial showing me how to get data from page to
>>>
>>>
>>database
>>
>>
>>>via ZPTs and ZSQL objects. Can you point me to such a reference?
>>>
>>>
>>Yes, the Zope book is the place to look.
>>
>>You create a ZSQL method with the SQL code
>>
>>You then call this method through your ZPT or better in the case of
>>posting
>>from page to database a PythonScript which in turn calls the ZSQL method
>>and
>>passes the parameters.
>>
>>Charlie
>>--
>>Charlie Clark
>>eGenix.com
>>
>>
>>
>So, is it true that for posting (moving data from page to database) it's NOT
>possible to do this by a direct ZPT-to-ZSQL method call? - i.e. that it can
>ONLY be done via a Python script?
>
>I've been trying to figure out a way to do it directly, because it seemed
>that if possible that would be the simplest way. But if it's not possible,
>then I can stop wasting my time on that path and start learning to do it
>with Python.
>
>- Ken
>
>
>_______________________________________________
>Zope-DB mailing list
>Zope-DB@zope.org
>http://mail.zope.org/mailman/listinfo/zope-db
>
>

_______________________________________________
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db
RE: RE: ZPTs and database accesses [ In reply to ]
Hello,

Last time I tried znolk it had a bad bug where the field contents were not
html-quoted when they where inserted into the edit forms.

For example, if a field had contents of


17" wheels


then all that would show up in the edit form would be

17

So I recommend proceed with caution with this product.


On a positive note, I have found another product to be excellent: zetadb
(only works with mysql and postgresql, but very nice product)

Regards, Josh

_______________________________________________
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db
Re: ZPTs and database accesses [ In reply to ]
Dne ètvrtek, 28. dubna 2005 20:17 Andreas Jung <lists@andreas-jung.com>
napsal(a):
> You have not read the book correctly. First statement just said that you
> can't SQL queries using ZPT. In Zope you specify SQL queries using
> *ZSQL methods* that use DTML as markup language...this is not the same
> as defining SQL inside DTML methods/documents or Page Templates.

with discuss about security it is possible to query sql directly from dtml/zpt
with yourZSQLmethod like this:

<param>
sqlquery:string
</params>
<dtml-var sqlquery>

and corresponding dtml method:

<dtml-call "REQUEST.set('sqlquery','select * from table')">
<dtml-in yourZSQLmethod>
...
</dtml-in>

--

Jaroslav Lukesh
-----------------------------------------------------------
This e-mail can not contain any viruses because I use Linux

_______________________________________________
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db
Re: ZPTs and database accesses [ In reply to ]
Jaroslav Lukesh wrote:
> with discuss about security it is possible to query sql directly from dtml/zpt
> with yourZSQLmethod like this:
>
> <param>
> sqlquery:string
> </params>
> <dtml-var sqlquery>
>
> and corresponding dtml method:
>
> <dtml-call "REQUEST.set('sqlquery','select * from table')">
> <dtml-in yourZSQLmethod>
> ...
> </dtml-in>

Yes, although you're opening yourself to a world of SQL injection
vulnerabilities by doing so ;-)

Chris

--
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk

_______________________________________________
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db