Subject | Re: UPDATE/INSERT strategy |
---|---|
Author | Adam |
Post date | 2007-05-03T02:07:43Z |
>This reduces the chance of the problem, but the other person could
> I have a similar instance of the same problem and overcame it with
> simply using an additional transaction, creating an UPDATE statement
> on the fly when the INSERT fails with a duplicate entry, and running
> the UPDATE via isc_dsql_execute_immediate().
still have the insert uncommitted when you start the update
transaction. It is simply a fact of life for transaction isolation
when you have global constraints and an isolated view.
>Why? If an insert statement raises an exception, it has no effect.
> Don't forget to roll back the original INSERT.
Firebird automatically undoes anything it did within the operation if
there is an unhandled exception.
You only need to rollback if prior operations within your transactions
should be considered atomic to your insert.
Start Transaction T1
Insert -> fails with Unique constraint violation
Rollback T1
has exactly the same effect as:
Start Transaction T1
Insert -> fails with Unique constraint violation
Commit T1
Adam