Subject Re: [firebird-support] What I am missing in the transaction ?
Author Mark Rotteveel
On 24-9-2018 14:13, m_brahim11@... [firebird-support] wrote:
>
>
> Hi all,
>
> Two users access at the same record. The first delete it and the second
> update the delete record after the first user.  The second who update
> the record must obtains something like :
>
> Statement failed, SQLCODE = -901
>
> cannotupdate erased record
>
> In my case I don't obtain that message maybe I am missing parameter in the transaction isolation ?

If the second transaction is started **after** the first transaction has
been committed, then nothing happens, as there is no record matching the
where clause.

That is:

T1. set transaction ..;
T1. delete from table where id = 1;
T1. commit work;
T2. set transaction ..;
T2. update table ... where id = 1;
T2. commit work;

On the other hand if the T2 transaction is start after T1, and T1
deletes before T2 updates, then the T2 update will wait until T1 commits
or rolls back. When T1 then commits, the update is cancelled with error

Statement failed, SQLSTATE = 40001
deadlock
-update conflicts with concurrent update
-concurrent transaction number is <transaction nr>

That is:

T1. set transaction ..;
T2. set transaction ..;
T1. delete from table where id = 1;
T2. update table .. where id = 1;
T2... waiting...
T1. commit work;
T2... update fails with error: update conflict.

This assumes normal updates / deletes.

Mark
--
Mark Rotteveel