ZSQL dtml request problem
Hi, 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 defined. How do I either get the dtml-call to see the lastinsetid variable, or grab the value by using the sql statement inside the dtml-call statement. It's driving me mad Cheers Michael
On Thu, 12 Jun 2003 17:11:43 +0100 GMT (..18:11 where i live(GMT+2) ) Davis Mr MR asked the Zope mailinglist about the following:
Hi,
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 defined.
How do I either get the dtml-call to see the lastinsetid variable, or grab the value by using the sql statement inside the dtml-call statement.
Your problem is that DTML and SQL are not executed at the same time. First the DTML is parsed to make the SQL statement, then the SQL is shipped off to the database. if you just lose the dtml-call, i would guess this method would return a single row with a property lastinsertid.. so , the calling script/template, could probably get to the value lastinsertid like this "nameofyouSQLmethod(paramters=values)[0].lastinsertid" :) -- Geir Bækholt
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 defined.
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). Dieter
participants (3)
-
Davis Mr MR -
Dieter Maurer -
Geir Bækholt