Recovering from an updatebatch error with a clone
- From: "damian marquez" <dmarquez34@xxxxxxxxxxx>
- Date: Thu, 27 Oct 2005 20:44:25 -0300
I am basically using batchoptimistic locking in a master/detail scenario to
cache changes in memory.
When posting, I start a transaction, try to run updatebatch and in case of
an error (let's say when
somebody else modified the same record) I try to recover using a clone...
but it seems the same old
status is preserved, so if i try to save data again, same problem will
happen...
How can I avoid this behaviour? Code follows:
// here goes the transaction.
MainDataModule.conMain.BeginTrans;
SWMaster:=TBetterADODataSet.Create(nil);
SWDetail:=TBetterADODataSet.Create(nil);
try
try
// clone the datasets to backup for reversion
SWMaster.Clone(dstMaster);
SWDetail.Clone(dstDetail);
// try to apply the changes.
dstMaster.UpdateBatch;
dstDetail.UpdateBatch;
if MainDataModule.conMain.InTransaction then
MainDataModule.conMain.CommitTrans;
Close;
except
on E:Exception do begin
if MainDataModule.conMain.InTransaction then
MainDataModule.conMain.RollbackTrans;
MessageDlg(_('Error, the transaction has been undone'), mtError,
[mbOK], 0);
Showmessage(e.Message);
// recover from ghost status! clone back. it closes the dataset.
dstMaster.DisableControls;
dstDetail.DisableControls;
dstMaster.Requery;
dstDetail.Requery;
dstmaster.Recordset.Status
dstMaster.Clone (SWMaster, SWMaster.LockType); dstMaster.Edit;
dstDetail.Clone (SWDetail, SWDetail.LockType);
end;
end;
finally
SWMaster.Free;
SWDetail.Free;
end;
--
Have you seen Marillion's Marbles? Visit www.marillion.com and get in touch
with the most amazing music...
.
- Follow-Ups:
- Re: Recovering from an updatebatch error with a clone
- From: damian marquez
- Re: Recovering from an updatebatch error with a clone
- Prev by Date: Re: "record not found or changed by another user"
- Next by Date: Re: Recovering from an updatebatch error with a clone
- Previous by thread: trigger causes exception
- Next by thread: Re: Recovering from an updatebatch error with a clone
- Index(es):
Relevant Pages
|