Subject Re: [firebird-support] Two users adding a record with the same code
Author Martijn Tonies
Gustavo,

> I will explain my problem with an example.
>
> Suppose I have a Table of ENTERPRISES with a field CODE (numeric), NAME,
ADDRESS, etc. Then I have a table EMPLOYEES with a field ENTERPRCODE, NAME,
AGE, ADDRESS, etc. Suppose there are already 100 entreprises in the table
ENTERPRISES.
>
> 1. User John begins to add a new enterprise. The application propose
automatically the CODE 101 and John begins to add (in a grid) the employees.
The field ENTERPRCODE of the employees he is adding will have the value 101.
>
> 2. Almost at the same time (before John post his new enterprise), the user
Peter begins to add a new enterprise. The application propose automatically
the CODE 101 (the same as the one that is using John) and Peter begins to
add (in a grid) the employees. The field ENTERPRCODE of the employees he is
adding will have the value 101.
>
> 3. John posts his enterprise.
>
> 4. Peter posts his enterprise. At this moment, the application shows a
message saying there is already an enterprise with CODE 101. Then Peter
change the CODE to 102 and the application automatically changes the field
ENTERPRCODE in the employees. Peter posts again his enterprise and
everithing is OK.
>
> But...
>
> Supose that after item 3 (John posted his enterprise), for any reason
Peter makes a refresh of the grid of employees. Then, as the refresh
executes a SELECT * FROM EMPLOYEES WHERE ENTERPRCODE = "101", he will now
see the employees that he (Peter) added and the ones that John added to his
other enterprise that is already posted. This is wrong!
>
> This is a simplified explanation, but shows the problem.
>
> I think, it could be a solution if the SELECT done by the refresh could
"see" only the records that are uncommited by the transaction in wich Peter
is working. So it will not see the records commited by John. The question
is: Is there a way to do this?
>

Peter should use a transaction that doesn't do "read committed", but have
a "read consistency" isolation, that way, he would only see HIS 101
employees, which have to be changed to 102 anyway and not see Johns
(committed) 101 employees.

Now, if I only could remember the exact Firebird wording for this
transaction.

What is it, snapshot?

Martijn Tonies
Database Workbench - tool for InterBase, Firebird, MySQL, NexusDB, Oracle &
MS SQL Server
Upscene Productions
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com