update with locktable
Posted: Wed 16 Mar 2005 17:56
Hello,
i have a database of serial numbers, like
ID
SERIAL_NUMBER
IN_USE
so, first im doing a
SELECT * FROM serials WHEN IN_USE = "N" LIMIT 1
and im getting the first available serial number. then:
UPDATE serials SET IN_USE = "Y" WHERE ID = :id
:id is updated via ParamByName.
Everything is fine but the problem is that when 2 users tries to run the program at the same time, they read the same serial and i have serious problem. So, i think the only solution is
LOCK TABLES SERIALS WRITE;
I tried to add the LOCK TABLE SERIALS WRITE in the Query but Query is unable to execute a second command.
So, I tried the LockTable() of the Query but it says that it can lock the table in a closed dataset.
Then I used the TMyScript, but this script doesnt allow to use ParamByName to apply variables.
Can you please give me a workaround solution for LockTable in an UPDATE query.
Any comments or redirections are welcomed.
Thank you in advanced.
i have a database of serial numbers, like
ID
SERIAL_NUMBER
IN_USE
so, first im doing a
SELECT * FROM serials WHEN IN_USE = "N" LIMIT 1
and im getting the first available serial number. then:
UPDATE serials SET IN_USE = "Y" WHERE ID = :id
:id is updated via ParamByName.
Everything is fine but the problem is that when 2 users tries to run the program at the same time, they read the same serial and i have serious problem. So, i think the only solution is
LOCK TABLES SERIALS WRITE;
I tried to add the LOCK TABLE SERIALS WRITE in the Query but Query is unable to execute a second command.
So, I tried the LockTable() of the Query but it says that it can lock the table in a closed dataset.
Then I used the TMyScript, but this script doesnt allow to use ParamByName to apply variables.
Can you please give me a workaround solution for LockTable in an UPDATE query.
Any comments or redirections are welcomed.
Thank you in advanced.