check if a record has changed

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
mohamad
Posts: 4
Joined: Sun 18 Dec 2011 09:52

check if a record has changed

Post by mohamad » Mon 09 Sep 2013 08:05

How do I check if a record has changed or many records have been added or deleted in offline mode?

with TMSQuery and without TMemTable.

thanks

AndreyZ

Re: check if a record has changed

Post by AndreyZ » Tue 10 Sep 2013 11:04

If there is no connection to the server, there is no way to obtain the information about changed records.
Otherwise, you can use the following code:

Code: Select all

begin
  MSQuery1.LockMode := lmPessimistic;
  MSQuery1.SQL.Text := 'select * from tablename';
  MSQuery1.Open;
  try
    MSQuery1.Edit;
  except
    ShowMessage('Record was changed on the server');
  end;
end;
This way, you can check if the current record was changed on the server.

Another possible solution is to use query notifications. Query notifications allow applications to be notified when data has changed. For more information about query notifications, please refer to http://msdn.microsoft.com/en-us/library/ms130764.aspx . Please take a look at the example of query notifications in the SDACDemo->ChangeNotification demo. It demonstrates how to use query notifications and refresh the data on the client when it is modified on the server.

mohamad
Posts: 4
Joined: Sun 18 Dec 2011 09:52

Re: check if a record has changed

Post by mohamad » Fri 13 Sep 2013 06:54

Thank you Andre.

But I mean is that I can identify records that have changed(Update, Delete, Insert) in a dataset in my client(and not in other clients). this dataset is in offline mode(CachedUpdates = true).
When the loop (while not EOF) is executed I can do detect whether or not the current record has been modified in this client by this user.

AndreyZ

Re: check if a record has changed

Post by AndreyZ » Fri 13 Sep 2013 08:39

You can use the UpdateStatus property to determine the current update status for the dataset when cached updates are enabled. Here is a code example:

Code: Select all

begin
  if MSQuery.UpdateStatus = usModified then
    ShowMessage('The current record is modified')
  else
  if MSQuery.UpdateStatus = usInserted then
    ShowMessage('The current record is inserted')
  else
  if MSQuery.UpdateStatus = usDeleted then
    ShowMessage('The current record is deleted')
  else
    ShowMessage('The current record is unmodified');
end;

Post Reply