Page 1 of 1

check if a record has changed

Posted: Mon 09 Sep 2013 08:05
by mohamad
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

Re: check if a record has changed

Posted: Tue 10 Sep 2013 11:04
by AndreyZ
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.

Re: check if a record has changed

Posted: Fri 13 Sep 2013 06:54
by mohamad
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.

Re: check if a record has changed

Posted: Fri 13 Sep 2013 08:39
by AndreyZ
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;