[Zope] ZSQL dtml request problem

Davis Mr MR M.R.Davis@rmcs.cranfield.ac.uk
Tue, 17 Jun 2003 16:32:28 +0100


Thanks for everyone's help with this.

I managed to fix it by rejigging the way my results were called, as I'm
using ZPT with macros for the displays. Instead of retrieving the record in
the macro, I moved the retrieve out, and just used the macro for the display
(would be better for reuse anyway, I think).

So the record just inserted can easily be retrieved just using the same SQL

INSERT INTO suppliers etc..
<dtml-var sql_delimiter>
SELECT * FROM suppliers WHERE supplierid=last_insert_id()

Works fine.

-----Original Message-----
From: Dieter Maurer [mailto:dieter@handshake.de]
Sent: 13 June 2003 21:46
To: Davis Mr MR
Cc: 'zope@zope.org'
Subject: Re: [Zope] ZSQL dtml request problem

Davis Mr MR wrote at 2003-6-12 17:11 +0100:
 > I'm trying to push the last_inset_id from an Insert statement onto the
 > request namespace, so I can pick it up and retrieve the new record for
 > display.
 > My ZSQL method looks like this.
 > INSERT INTO suppliers (insert statements removed)
 > <dtml-var sql_delimiter>
 > SELECT last_insert_id() AS lastinsertid
 > <dtml-call "REQUEST.set('id',lastinsertid)">
 > It comes back with a NameError - global name 'lastinsertid' is not

The results of ZSQL methods are not automatically added to the
DTML namespace. You can use

     <dtml-with expr="your_ZSQL_Method()[0]"> ... </dtml-with>

to push the first result row onto the DTML namespace ("during" the with).