Need help in record lock

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
97itr217
Posts: 19
Joined: Tue 31 Mar 2009 14:54
Location: Canada

Need help in record lock

Post by 97itr217 » Thu 03 Dec 2009 21:54

IDE: BDS2006
MyDAC: v5.55.0.39
Windows: XP sp 2
MySQL: v5.1.41 community

Let say I have a Depts and Employees table. I also have a view vEmpRec created in MySQL which has Employees left join Depts on idDepts (since new employee may not have a dept yet).

On my DataModule, I have a TMyQuery which queries this view as in

Code: Select all

SELECT * FROM vEmpRec;
The LockMode property is set to lmPessimistic.

On my employees form, I have a CRDBGrid to show rows from the above query. When I double click an employee, the code will do MyQuery->Edit() so that I should have the record in Employees table locked. But I discovered that both Depts and Employees table were locked, which is a problem because I cannot have another employee locked under the same dept.

I have tried setting UpdatingTable of TMyQuery to Employees but MyDAC doesn't like it, saying unknown table (guess it was because my select SQL statement does not have this table) when my project is run. So I put vEmpRec instead, but problem persists (both tables are locked).

I have also tried to put Lock SQL statement as:

Code: Select all

SELECT * FROM vEmpRec WHERE idEmployees = :Old_idEmployees FOR UPDATE;
into TMyQuery. TMyQuery accepts the statement and saves okay, but "forgets" it after closing and reopen. No matter what I did, the lock sql statement doesn't stay.


After many trial-and-error, I need to insert a dummy join in the select SQL to get only the row in Employees locked:

Code: Select all

SELECT * FROM Employees JOIN vEmpRec ON Employees.idEmployees = vEmpRec.idEmployees;
Is this what it supposes to be?
Any other ways to code my select SQL so that I don't need to do the dummy join?

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Re: Need help in record lock

Post by Dimon » Fri 04 Dec 2009 10:31

97itr217 wrote:I have also tried to put Lock SQL statement as:

Code: Select all

SELECT * FROM vEmpRec WHERE idEmployees = :Old_idEmployees FOR UPDATE;
into TMyQuery. TMyQuery accepts the statement and saves okay, but "forgets" it after closing and reopen. No matter what I did, the lock sql statement doesn't stay.
Thank you for information. We have reproduced this problem and fixed it. This fix will be included in the next MyDAC build.

97itr217
Posts: 19
Joined: Tue 31 Mar 2009 14:54
Location: Canada

Post by 97itr217 » Fri 04 Dec 2009 15:26

So is it true that for the time being, the work around is to put the dummy JOIN into the select SQL?

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Mon 07 Dec 2009 08:12

Yes, it's right.

Post Reply