in reply to Re: Testing if DBI has a commit pending?
in thread Testing if DBI has a commit pending?

I have a update that is followed by an insert and if the insert fails I need the update to fail. I can't have the insert before the update because it would violate a business rule (unique index). It is very unlike that the insert will fail, but if it does the database will be left in a state that should be impossible.

I can think of lots of times when commit/rollback is needed to keep a database consistent. Though the INSERT ... ON DUPLICATE KEY functionality has reduced the number of those cases.

-- gam3
A picture is worth a thousand words, but takes 200K.
  • Comment on Re^2: Testing if DBI has a commit pending?

Replies are listed 'Best First'.
Re^3: Testing if DBI has a commit pending?
by eric256 (Parson) on Sep 19, 2006 at 17:48 UTC

    This is exactly what commit is for though. Issue your update, issue your insert. If the insert fails the rollback, otherwise commit. I'm not sure how an insert before an update would cause such a business rule to fail, but if that is indeed the case then just rollback on failure. At that point you would then retry with a new update/insert/commit cycle.


    ___________
    Eric Hodges