* Dada:
Quote:
The program logs, which records are new or corrected. And only these
record are stored at the end. |
Problems can occur if the same records are edited by different users.
This may lead to data loss.
There is no generally applicable solution for this kind of problem.
Any introductory text on transaction processing will give you some
ideas of what can be done. For example, it is possible to implement
the read -- uper update -- write cycle as follows:
1. Start a first transaction.
2. Read the conceptual record from the database (this can involve
access to multiple database files).
3. End the first transaction.
4. Make an in-memory copy of the record for later reference.
5. Present the record to the user for editing, and wait until the
users saves his or her edits. This operation can block
indefinitely (because you don't know when the user will react).
6. Start a second transaction.
7. Read the record from the database, and compare it to the copy
made in step 4. If there is a difference, tell the user about
the conflict, update the in-memory copy of the record, and go to
step 5.
8. Write the edited record to the database.
9. Commit the second transaction.
It is also possible to include a version number in the record to
detect concurrent changes. Radically different approaches also exist.
For example, you could represent the user edits as some kind of delta,
in a way that all such deltas commute.