Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using GET_LOCK in MySQL
Message
 
To
18/06/2008 08:23:09
General information
Forum:
Visual FoxPro
Category:
Client/server
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows XP
Database:
MySQL
Miscellaneous
Thread ID:
01324717
Message ID:
01325915
Views:
18
Hmm, hmm,

You have two ways:
1) for each record of any table create unique lock on MySQL
2) rewrite application

MartinaJ

>Thanks. But my remaining issue is that I may have multiple records "locked" at the same time. When I keep the name "TABLE_USER" locked, and in the meantime lock another name, for instance "TABLE_SESSION", then the previous lock "TABLE_USER" would be released right away.
>
>One workaround is to create a create one additional database connection for each separate simultaneous lock. But that would mean I am going to have a lot of database connections to maintain.
>
>>Hi Christian,
>>
>>The GET_LOCK() on MySQL is not equal to RLOCK() but - from help: "This function can be used to implement application locks or to simulate record locks. "
>>
>>
>>* !!!this code is not tested !!!
>>LOCAL lcALOCK,lcAlias
>>lcALOCK=SYS(2015)
>>lcAlias=SYS(2015)
>>=SQLEXEC(mySQLODBCHandle,"SELECT * FROM users WHERE userName = 'Christian'",lcAlias)
>>
>>=SQLEXEC(mySQLODBCHandle,"SELECT IS_FREE_LOCK('TABLE_USER') AS LOCKFLAG",lcALOCK)
>>IF EVAL(lcALOCK+".LOCKFLAG")=1
>>   =SQLEXEC(mySQLODBCHandle,"SELECT GET_LOCK('TABLE_USER',10) AS LOCKFLAG",lcALOCK)
>>
>>   ** update table users
>>
>>*   =SQLEXEC(mySQLODBCHandle,"SELECT RELEASE_LOCK('TABLE_USER') AS LOCKFLAG",lcALOCK)
>>ELSE
>>   MESSAGEBOX("User already logged in")
>>ENDIF
>><pre>
>>
>>MartinaJ
>>
>>>Hello,
>>>
>>>In VFP, I used to use RLOCK("MyAlias") to lock a record, if I wanted to make sure another instance of the application would "know" that a record was being used, for instance when the appplication should display that a certain user was logged in.
>>><PRE>
>>>USE Users
>>>LOCATE FOR userName = "Christian"
>>>IF NOT RLOCK("Users")
>>>    MESSAGEBOX("User already logged in")
>>>ENDIF
>>>
>>>Now after switching to MySQL, that simple functionality got more challenging. Then I found that Get_Lock can lock any name, so I used GET_LOCK(1,"Christian") to do the same thing as above in MySQL.
>>>
>>>However, I found out that Get_Lock allows only one lock per database connection. Issuing a new Get_Lock unlocks the previous lock. So I would not be able to lock a user name, and additionally for instance the computer name as well.
>>>
>>>Anybody knows what other methods I could use in MySQL to solve that problem?
"Navision is evil that needs to be erazed... to the ground"

Jabber: gorila@dione.zcu.cz
Jabber? Jabbim
Previous
Reply
Map
View

Click here to load this message in the networking platform