[Zope] Can I capture results from insert in Z SQL methods?
Skip Montanaro
skip@pobox.com
Sat, 2 Nov 2002 08:49:04 -0600
Andrew> This is really a general SQL problem rather than anything to do
Andrew> with Zope/ZSQL.
So ZSQL methods don't provide any special syntactic sugar other than
<dtml-sqlvar>?
Andrew> Then do a select nextval('whatever'); to get the next id which
Andrew> can then be used for the inserts.
Thanks, I'll check it out. This seems (naively) like it would be a race to
me though. Let's say I do this:
insert into phone ( ... ) values ( ... );
The new row in phone got a unique id (I do use the serial type for my
primary keys). Now, I need the id that row got to use in another insert.
If I do something like:
insert into contact (
...
phone,
...
)
values (
...
(select currval(phone_id_seq)),
...
);
That will get the id of the record I just inserted assuming someone else
didn't sneak in and insert another row in the phone table before I queried
phone_id_seq.
Or were you suggesting I do something like:
<some dtml assignment ... select nextval(phone_id_seq); ...>
insert into phone (
id,
...
)
values (
<value retrieved above>
...
);
If so, how do I capture the value of nextval(...) within the ZSQL method?
Thx,
--
Skip Montanaro - skip@pobox.com
http://www.mojam.com/
http://www.musi-cal.com/