Simple multi-user problem Locks/Transactions?
Posted: Mon 08 Dec 2008 10:18
Hi
Sorry to be naïve but I'm new to SDAC and TSQL and I can’t work out how to perform a simple task.
SDAC 4.70
Delphi 2006
I’m developing a multiuser system with over 100 users. Blocks of work are queued and I need to allocate the next unallocated block to a user. It is essential that the same block of work cannot be assigned to two users.
I have a table representing the blocks and the block ID is then used to deliver the actual block of work to the user (the block of work is actually many records gathered from many tables).
There is a field that indicates the user the block is allocated to - say ALLOCATED_USER - NULL before the block's been allocated.
If this were a single user application, I could simply do
TMSquery1.open;
blockID:=query1.fieldbyname('ID').asstring;
TMSquery2.execute;
where TMSquery1 SELECTed the ID of the next block in the queue (the WHERE CLAUSE is actually quite complicated but includes ALLOCATED_USER IS NULL) and where TMSquery2.sql is of the form
UPDATE BLOCKS SET ALLOCATED_USER = WHERE ID =
What I want to achieve is that, once I've selected the record, no-one else would be able to to select that record with TMSquery1.
I assume that means that I would need to lock the record on the SELECT in TMSquery1 and release it after the update has been committed in TMSquery2.
I have looked at the lock and transaction demo files and read what I can in the help and on this forum but can't see how to do this.
This is clearly a similar problem to booking theatre tickets/airline seats so I'm sure it's a well trodden path.
Thank you
Jeff
Sorry to be naïve but I'm new to SDAC and TSQL and I can’t work out how to perform a simple task.
SDAC 4.70
Delphi 2006
I’m developing a multiuser system with over 100 users. Blocks of work are queued and I need to allocate the next unallocated block to a user. It is essential that the same block of work cannot be assigned to two users.
I have a table representing the blocks and the block ID is then used to deliver the actual block of work to the user (the block of work is actually many records gathered from many tables).
There is a field that indicates the user the block is allocated to - say ALLOCATED_USER - NULL before the block's been allocated.
If this were a single user application, I could simply do
TMSquery1.open;
blockID:=query1.fieldbyname('ID').asstring;
TMSquery2.execute;
where TMSquery1 SELECTed the ID of the next block in the queue (the WHERE CLAUSE is actually quite complicated but includes ALLOCATED_USER IS NULL) and where TMSquery2.sql is of the form
UPDATE BLOCKS SET ALLOCATED_USER = WHERE ID =
What I want to achieve is that, once I've selected the record, no-one else would be able to to select that record with TMSquery1.
I assume that means that I would need to lock the record on the SELECT in TMSquery1 and release it after the update has been committed in TMSquery2.
I have looked at the lock and transaction demo files and read what I can in the help and on this forum but can't see how to do this.
This is clearly a similar problem to booking theatre tickets/airline seats so I'm sure it's a well trodden path.
Thank you
Jeff