Fri, 18 Jul 2003 16:26:06 -0400
On Fri, 18 Jul 2003 18:09:47 +0100
Philip Kilner <firstname.lastname@example.org> wrote:
> Hi List,
> Philip Kilner wrote:
> > - How do I call the "insertBook" ZSQL method from within a ZPT?
> > - Do I have to do anything special to map my field names to the
> > parameters that the ZSQl expects?
> > (I've written this partly as a test of whether I understand it
> > myself - I'll fire the email off and go RTFM now!)
> OK - have now read up on Form Processing in AvZPT in the Zope book.
> Looks like the answer to my first question is "Write a Pythion script
> to call the ZSQL, and call this script from the ZPT". I can suss the
> ZPT syntax from the Zope Book- can anyone point me to a good example
> of Python calling ZSQL?
OK, suppose my_sql_method is a query having parameters foo, and bar and
it lies in the current container.
Foo and bar can be in the request, or they can be passed as named
parameters. In the first case, the call would simply look like:
In the second, it would look like
where foo_value and bar_value are the values of the parameters that you
want my_sql_method to use.
Now, what is res?
Spinwing has a howto on this, (I have another) but short version is:
res is an object that looks like an array returned rows.
res is first row, first column; res is first row, 2nd
column; res is second row, first column, etc.
len(res) is number of rows returned.
res.names() is the names of the columns.
I like to work with column names, rather than column numbers. I do
for i in range(len(nms)):
Now, if 'baz' is the name of a column, I can index into a row like:
(that is, the index of the column named 'baz' in the first row returned.
Thats all there is to it, really.
> Email: email@example.com / Voicemail & Facsimile: 07092 070518
> "As we enjoy great advantages from inventions of others,
> we should be glad of an opportunity to serve others by
> any invention of ours; and this we should do freely and
> generously." - Benjamin Franklin