Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using GET_LOCK in MySQL
Message
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:
01325046
Views:
21
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
Next
Reply
Map
View

Click here to load this message in the networking platform