Ed,
 I don't know how much this matters to what is going on but you can get the
last gen'd pkid from postgres withing a transaction...at least in the
example below it is ok...

begin transaction;
select * from mytable;
insert into agcostslot (fieldname) values (somevalue);
select currval('mytable_pkid_seq');

Larry

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Ed Leafe
Sent: Thursday, August 23, 2007 7:44 PM
To: Dabo developers' list
Subject: Re: [dabo-dev] The sequence of the saveall() not working

On Aug 23, 2007, at 6:35 PM, johnf wrote:

> But I changed my code to force the correct sequence and I still got an 
> error
> from Dabo.   So I thought I'd ask about how it is suppose to work when
> children are involved.

        There are two approaches: pre-fetching the next sequence and setting
the PK of your new parent record to it *before* the insert (we'll call this
'pregen'), and inserting the record without a PK value, and then asking the
database what value it gave the PK (call this 'postgen').

        Currently dbPostgreSQL uses the postgen strategy, but if I
understand your explanation of the problem you're now having, you cannot ask
Postgres what is the value of the last assigned PK until after the
transaction has been committed. As a result, you cannot populate the FKs of
the child records without first committing the parent insert, which means
that ACID transactions are not possible.

        The approach you need to use, if indeed you cannot query the
database for a newly-inserted PK while a transaction is pending, is to use a
pregen approach. In this case, the parent PK is gotten before the insert,
and thus is available for populating child FKs while still wrapped in the
transaction.

        The way that Dabo handles this is by defining a method in the
dBackend subclass named 'pregenPK()'. If that returns a non-empty value, the
PK of the record to be inserted will be set *before* the insert is made, and
the post-insert call to getLastInsertID() is skipped.

        Does this make the flow of events any clearer?

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com




[excessive quoting removed by server]

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/dabo-dev/[EMAIL PROTECTED]

Reply via email to