Multiple Access To Data lazarus / 16-Databases ---------------------------------------------------------------------- StephenMilner · 2022-01-17 15:11 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? Regards, Stephen ---------------------------------------------------------------------- Zvoni · 2022-01-17 15:14 Sounds like race-conditions resp. a missing Write-Lock on the recordset ---------------------------------------------------------------------- StephenMilner · 2022-01-17 15:27 The problem with locking is that it isn't perfect when user input is required. Normally I'd: Read and Lock Change 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 Write 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. Regards, Stephen ---------------------------------------------------------------------- MarkMLl · 2022-01-17 18:25 Check what transaction isolation levels your backend database supports. MarkMLl ---------------------------------------------------------------------- StephenMilner · 2022-01-18 09:19 Quote from: MarkMLl on January 17, 2022, 07:25:28 pmCheck what transaction isolation levels your backend database supports. MarkMLl That's not something I've decided yet, so I can factor it in. ---------------------------------------------------------------------- Thaddy · 2022-01-18 09:37 Quote from: StephenMilner on January 18, 2022, 10:19:29 amQuote from: MarkMLl on January 17, 2022, 07:25:28 pmCheck what transaction isolation levels your backend database supports. MarkMLl That's not something I've decided yet, so I can factor it in. It is not "factor it in", it is the core question you should focus on. Locking should be done at the database level, not program level, except if you use a very ancient database that does not support locking. Your program needs to just check for locks before a commit. ---------------------------------------------------------------------- MarkMLl · 2022-01-18 10:51 Quote from: Thaddy on January 18, 2022, 10:37:19 am... except if you use a very ancient database that does not support locking. In which case it's time to select a more recent database. PostgreSQL (as a specific example) has had proper transaction isolation for 20+ years. /However/, using a backend database properly does imply that queries are issued and completed promptly, and this is not well-supported by RAD-style environments which assume that a connection can be held open indefinitely. Arguably, this has been responsible for the proliferation of "modern" browser-based apps which handle as much as possible in local scripting. MarkMLl ---------------------------------------------------------------------- Thaddy · 2022-01-18 12:31 @Mark Note most of the time I do not use Lazarus at all for db backend interfacing, so not RAD. (But I do use Lazarus)