Subject Re: [firebird-support] get_lock / release_lock
Author Kjell Rilbe
Doru Constantin wrote:

> I have an old app: vfp + odbc + mysql.
> I try to replace mysql with minimal change in code.
> In this app when a user is add/modify/delete a document the get_lock()
> function is called and if the lock is get then the user can continue
> otherwise don't.
> I read about RDB$SET_CONTEXT / RDB$GET_CONTEXT, but "... variables may be
> read and written to and by whom are determined by namespace which they
> belong to.".
> I need RDB$SET_CONTEXT / RDB$GET_CONTEXT but in a global context.

I suggest you create a separate table called "Locks", with (at least)
one column:

create table "Locks" (
"LockName" varchar(50) not null constraint "LocksPK" primary key

Then in your app write a get_lock function which uses a separate DB
transaction to do

insert into "Locks" ("LockName") values ('TheLockName');

If the insert fails, then another user holds the lock. If it succeeds,
commit, and return a successful lock.

A separate function release_lock would do

delete from "Locks" where "LockName" = 'TheLockName';

Your app has to make very sure all get_lock calls are matched with a
release_lock or your system will deadlock.

Others might add info about appropriate transaction settings etc to
achieve timeout functionality if your app so requires.

Kjell Rilbe
E-post: kjell@...
Telefon: 08-761 06 55
Mobil: 0733-44 24 64