Forum > Databases

Multiple Access To Data

(1/2) > >>

Many years ago I was involved in a project that developed till software using Kylix3 and data enabled components.

I forget the exact details but we found a situation where:

One till read a stock figure for an item.
Another till read the same stock figure for the same item.
The first till decremented the stock figure by a number and posted the change
The second till decremented the original stock figure by a number and posted the change.

This resulted in an incorrect stock figure.

There were some events for the data components in Kylix which signalled to the data component that the underlying stock position on the database had changed and some code could be written to make sure the data was re-read before decrementing the stock. Admittedly, for Firebird, the events didn't trigger correctly and required some work to re-write the components to fix them first.

Do similar events exist on the FPC/Lazarus data components?


Sounds like race-conditions resp. a missing Write-Lock on the recordset

The problem with locking is that it isn't perfect when user input is required.

Normally I'd:
Read and Lock
Write and Unlock

In a till example though you've got:
Read (and if locked there's a problem if someone else want's to get the same item's data)
User spends some time making a change

IIRC it was something to do with the update type of the data set > Update where all fields matched the old fields before writing and if they didn't possibly threw an exception or triggered an event. Also IIRC there was some problem when the exception or event triggered: the old field value wasn't accurate, possibly having been overwritten by the new field.

For an example such as the till one above I could probably write increment/decrement functions that actually perform the quick, read & lock, modify, post & unlock and I can't remember at the time why we didn't do this.


Check what transaction isolation levels your backend database supports.



--- Quote from: MarkMLl on January 17, 2022, 07:25:28 pm ---Check what transaction isolation levels your backend database supports.


--- End quote ---

That's not something I've decided yet, so I can factor it in.


[0] Message Index

[#] Next page

Go to full version