[Zope] ZSQL - finding the id of what you just inserted?

The Doctor What docwhat@gerf.org
Thu, 19 Apr 2001 22:47:30 -0500


* The Doctor What (docwhat@gerf.org) [010419 21:02]:
> Howdy again....
> 
> I use a dtml-call to call a zsql object that does an insert.  I
> don't specify ID because ID is auto-sequenced by the DB.
> 
> How can I find out what the ID of that just inserted object is so I
> can do more operations on it?
> 
> Related question:  Why doesn't this work?
> <dtml-call expr="RESPONSE.redirect('index_html?message=Link+added&url_id='+url_id)">
> 
> Zope complains about a builtin...

If figured it out in the end.  It was actually a Postgres question:
INSERT INTO URL
    (val_ProtocolID, Url, Name, Summary, Description, Created)
VALUES
    ( 
      <dtml-sqlvar protocol_id type=int>,
      <dtml-sqlvar url_part type=nb>,
      <dtml-sqlvar url_name type=nb>,
      <dtml-sqlvar url_summary type=nb>,
      <dtml-sqlvar url_description type=nb>,
      now()
    )
<dtml-var sql_delimiter>
SELECT id as url_id
FROM URL
WHERE id = currval('url_id_seq')

Ciao!

-- 
Any programming language is at its best before it is implemented and used.

The Doctor What: Un-Humble                       http://docwhat.gerf.org/
docwhat@gerf.org                                                   KF6VNC