Change Record

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
siberya
Posts: 23
Joined: Thu 23 Mar 2006 19:00

Change Record

Post by siberya » Tue 13 Nov 2012 23:51

Hello,

I'm trying to disconnect mode

TDataSet.CachedUpdates = True
TCustomDADataSet.FetchAll = True
TCustomDADataSet.Options.LocalMasterDetail = True
AutoCommit = True

How do I know if a record has been changed by another user?

Thanks.

AndreyZ

Re: Change Record

Post by AndreyZ » Wed 14 Nov 2012 11:33

Hello,

There is no way to determine if a record has been changed by another user in the cached mode. But it is possible to prevent a record to be modified by another user in the non-cached mode using the locking engine. Here is a code example that demonstrates this:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
begin
  IBCQuery1.Connection := IBCConnection1; // IBCConnection1 represents the first user
  IBCQuery1.LockMode := lmLockImmediate; // locking is performed when the user starts editing a record
  IBCQuery1.SQL.Text := 'select * from dept';
  IBCQuery1.Open;
  IBCQuery1.Edit; // here the record is locked

  IBCQuery2.Connection := IBCConnection2; // IBCConnection2 represents the second user
  IBCQuery2.LockMode := lmLockImmediate;
  IBCQuery2.SQL.Text := 'select * from dept';
  IBCQuery2.Open;
  IBCQuery2.Edit; // here the 'Lock conflict' error occurs because this record is already being modified by the first user
end;

siberya
Posts: 23
Joined: Thu 23 Mar 2006 19:00

Re: Change Record

Post by siberya » Thu 15 Nov 2012 01:29

Thank you for your response.

Is it possible to make something using post_event with cached mode? Can you tell me what you think?

AndreyZ

Re: Change Record

Post by AndreyZ » Thu 15 Nov 2012 09:45

Using post events, you will be able to determine that some data in a table was changed. You will not be able to determine a particular record that was changed. If you are interested to determine if any data in a table was changed, you can use the TIBCAlerter component. Using TIBCAlerter, you can handle events to respond to actions and database changes made by other applications. You can find an example of using TIBCAlerter within IBDAC demos.

Post Reply