Page 1 of 1
CommitUpdates & RestoreUpdates
Posted: Sat 19 May 2012 10:46
by lauchuen
hi,
do i have to perform CommitUpdates & RestoreUpdates everytime after Connection.Commit & Connection.Rollback (for example i have 3 dataset component)?
Code: Select all
DataSet.Connection.StartTranscation;
try
DataSet1.ApplyUpdates;
DataSet2.ApplyUpdates;
DataSet3.ApplyUpdates;
DataSet.Connection.Commit;
DataSet1.CommitUpdates;
DataSet2.CommitUpdates;
DataSet3.CommitUpdates;
except
DataSet.Connection.Rollback;
DataSet1.RestoreUpdates;
DataSet2.RestoreUpdates;
DataSet3.RestoreUpdates;
raise;
end;
any simplest way? thanks
Re: CommitUpdates & RestoreUpdates
Posted: Wed 23 May 2012 08:10
by ROD
Instead of calling ApplyUpdates for each DataSet, you can call ApplyUpdates for the connection. That is, change the code like this:
Code: Select all
DataSet.Connection.StartTranscation;
try
DataSet.Connection.ApplyUpdates;
except
DataSet.Connection.Rollback;
DataSet1.RestoreUpdates;
DataSet2.RestoreUpdates;
DataSet3.RestoreUpdates;
raise;
end;
Also, if you, for example, have to apply changes to a DataSet in different parts of the program, you can use only CommitUpdates (which will call ApplyUpdates itself, if it finds unapplied changes). So the code will be as follows:
Code: Select all
DataSet.Connection.StartTranscation;
try
DataSet1.CommitUpdates;
DataSet2.CommitUpdates;
DataSet3.CommitUpdates;
DataSet.Connection.Commit;
except
DataSet.Connection.Rollback;
DataSet1.RestoreUpdates;
DataSet2.RestoreUpdates;
DataSet3.RestoreUpdates;
raise;
end;
RestoreUpdates in the except block must be called for every DataSet.
Re: CommitUpdates & RestoreUpdates
Posted: Wed 23 May 2012 08:24
by lauchuen
i think the second example will be good for me, because the application may contain Dataset4, Dataset5 in other from but using the same connection, if the first case will commit Dataset4, Dataset5 too, that i don't want to be.
i want to learn more about CommitUpdates, since refer to the document, its said will clear the dataset delta itself, is that means it will clear the delta after Connection.Commit ? or immediate clear the delta after call Dataset.CommitUpdates ?
thx.
Re: CommitUpdates & RestoreUpdates
Posted: Wed 23 May 2012 10:08
by ROD
If use CommitUpdates without ApplyUpdates, then it's better to do this before Connection.Commit, because when changes are not applied, it will explicitly call ApplyUpdates which requires Commit. Anyway, CommitUpdates can be put before Connection.Commit, since it just cleans the cache of changes.