Help on locking
Help on locking
Hello,
I have a sofware that provides serial numbers. The DB name is "DB_SERIALS" and the table is "SERIALS" (InnoDB).
I have many agents/clients that are connected to DB to find an empty serial number and reserve it. So, the client is executing a TMyQuery
Query1:
SELECT * FROM serials
WHERE inuse = "N"
LIMIT 0,1
I get the serial in a local delphi variable
and then another query
Query2:
UPDATE serials
SET inuse = "Y" WHERE serial = :serial
The problem is when 2 agents tries to get a serial at the same time. I need to LOCK table until the UPDATE procedure is finishes and then other agents can work in the table.
I need an idea and/or example code please.
Thanks
I have a sofware that provides serial numbers. The DB name is "DB_SERIALS" and the table is "SERIALS" (InnoDB).
I have many agents/clients that are connected to DB to find an empty serial number and reserve it. So, the client is executing a TMyQuery
Query1:
SELECT * FROM serials
WHERE inuse = "N"
LIMIT 0,1
I get the serial in a local delphi variable
and then another query
Query2:
UPDATE serials
SET inuse = "Y" WHERE serial = :serial
The problem is when 2 agents tries to get a serial at the same time. I need to LOCK table until the UPDATE procedure is finishes and then other agents can work in the table.
I need an idea and/or example code please.
Thanks
-
- Posts: 387
- Joined: Fri 18 Nov 2005 00:26
- Location: Brazil
i have a solution..
Hello,
Query1:
Lock Tables serials write; <<< Lock the table.
SELECT * FROM serials
WHERE inuse = "N"
LIMIT 0,1;
I get the serial in a local delphi variable
and then another query
Query2:
UPDATE serials
SET inuse = "Y" WHERE serial = :serial;
Unlock Tables;
in my case this code resolve the problem
read in mySQL help about Lock Tables
good look
Query1:
Lock Tables serials write; <<< Lock the table.
SELECT * FROM serials
WHERE inuse = "N"
LIMIT 0,1;
I get the serial in a local delphi variable
and then another query
Query2:
UPDATE serials
SET inuse = "Y" WHERE serial = :serial;
Unlock Tables;
in my case this code resolve the problem
read in mySQL help about Lock Tables
good look