On Thursday 23 August 2007 16:43, Ed Leafe wrote: > 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 Yes thanks
-- John Fabiani _______________________________________________ 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]
