Board index » delphi » Record locking

Record locking

Hi all,

does anyone have an idea of how to do record locking in D2 using a
paradox table?

thanks,.....

 

Re:Record locking


How about: Table2.Edit;
Edit always locks the current record for you only to make
modifications, meanwhile all the other users can only view
that record.

Quote
Johan van Leur wrote:

> Hi all,

> does anyone have an idea of how to do record locking in D2 using a
> paradox table?

> thanks,.....

Re:Record locking


Quote
Markku Nevalainen wrote:
> How about: Table2.Edit;
> Edit always locks the current record for you only to make
> modifications, meanwhile all the other users can only view
> that record.

> Johan van Leur wrote:
> > does anyone have an idea of how to do record locking in D2 using a
> > paradox table?

Hi,

If it's true that the Table1.Edit locks the record, How can the second
application see that the record is locked?, If I call Table1.Edit in the
second application, it should not work!. Is there a property set when
the record is locked or is it something like result:=table1.edit.... if
result=tLocked then {do whatever }

Please help me out on this....

thanks...

Johan van Leur

Re:Record locking


This won't work because the BDE uses optimistic locking - the record is only
locked at the point of updating.

Kev
Northgate Systems

Quote
Markku Nevalainen wrote in message <34590C55.1...@netlife.fi>...
>How about: Table2.Edit;
>Edit always locks the current record for you only to make
>modifications, meanwhile all the other users can only view
>that record.

>Johan van Leur wrote:

>> Hi all,

>> does anyone have an idea of how to do record locking in D2 using a
>> paradox table?

>> thanks,.....

Re:Record locking


Quote
Johan van Leur wrote:

> If it's true that the Table1.Edit locks the record, How can the second
> application see that the record is locked?, If I call Table1.Edit in the
> second application, it should not work!. Is there a property set when
> the record is locked or is it something like result:=table1.edit.... if
> result=tLocked then {do whatever }

Sharing and locking data in multi user environment, that's a problem for
BDE to handle, by using some common .LCK, .NETDIR etc. files.

I suggest you to viev what Borland has said about this in their TI documents.
http://www.borland.com/devsupport/delphi/ti_list/

Here is another site, there Bill Todd gives some nice Paradox tips
http://www.futureone.com/~dgi/techpprs.htm

And of course there is always the great Deja News service. About 70% of all
the questions asked here have already been discussed and asked previously.
http://xp9.dejanews.com/dnquery.xp?search=word&query=*&maxhits=50&ST=...

Markku Nevalainen

Re:Record locking


Markku

When the BDE locks the record another user will not be allowed to update it
until the lock is released.  However, this only occurs at the point of
Posting any changes to the table - if the record is in Edit mode (i.e when
the tick becomes active on the DBNavigator) the record is not actually
locked.  If two users have the same record open it just depends on timing as
to which changes are saved.  If the first user makes changes and the second
does not and the first one posts then the second one posts the record will
remain the same.

However, I think it is possible to enforce pessimistic locking by using BDE
API calls (e.g DbiGetRecord allows a lock to be specified which then must be
released with DbiRelRecordLock)

Kev
Northgate Systems

Quote
>Kev wrote:

>> This won't work because the BDE uses optimistic locking - the record is
only
>> locked at the point of updating.

>Could you explain more accurately?  What does the Optimistic locking allow
for
>the other users to do, when someone has started Editing some Paradox
record?

>I have always understood that Edit is the lock to reserve Paradox record
update
>only for you self. In the following is an example from Bill Todd's
homepage.
>To get a unique incrementing key for some table, you make a table LastKey,
>containing only one field, LastNumber.
>  Then, using Edit prevents the others from updating the value also in
multi
>user environment. And Todd has created the following Try Except loop to
>wait for the table to get unlocked again, so the next user can get a new
unique
>key value.

>Is this kind of code useless? Starting from which Paradox/BDE version ?

>Markku Nevalainen

>function dgGetUniqueNumber(LastNumberTbl: TTable): LongInt;
>{Gets the next value from a one field one record
> table which stores the last used value in its first
> field.  The parameter LastNumberTbl is the table
> that contains the last used number.}
>const
>  ntMaxTries = 100;
>var
>  I,
>  WaitCount,
>  Tries:         Integer;
>begin
>  Tries := 0;
>  with LastNumberTbl do
>  begin
>    {Try to put the table that holds the last used
>     number into edit mode. If calling Edit raises
>     an exception wait a random period and try again.}
>    Randomize;
>    while Tries < ntMaxTries do
>      try
>        Inc(Tries);
>        Edit;
>        Break;
>      except
>        on EDBEngineError do
>          {The call to Edit failed because the record
>           could not be locked.}
>          begin
>            {Wait for a random period and try again.}
>            WaitCount := Random(20);
>            for I := 1 to WaitCount do
>              Application.ProcessMessages;
>            Continue;
>          end;
>      end; {try}
>    if State = dsEdit then
>    begin
>      Result := Fields[0].AsInteger + 1;
>      Fields[0].AsInteger := Result;
>      Post;
>    end
>    else
>      {If the record could not be locked after the
>       specified number of tries raise an exception.}
>      raise EGetUniqueNumber.Create('Cannot get next unique number.

(btGetUniqueNumber)');

- Show quoted text -

Quote
>  end;
>end;

Other Threads