Recovering from an updatebatch error with a clone



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...


.



Relevant Pages

  • Re: Recovering from an updatebatch error with a clone
    ... > scenario to cache changes in memory. ... > When posting, I start a transaction, try to run updatebatch and in ... to the database with updatebatch... ...
    (borland.public.delphi.database.ado)
  • Re: Recordset.AddNew and the recordset objects data retaining
    ... I absolutely think that in extremely large jobs, ... I know, I could send a single transaction containing 10,000 records but it ... > physical memory to accommodate the TWO sets of 100,000 records: ... >> The statement you make about the individual updates not hitting the ...
    (microsoft.public.data.ado)
  • Re: Memory Sizing Advice
    ... The working set of indexes simply don't fit in cache all that well. ... that you're acting as though cache memory isn't an analagous ... Oracle restricts block cleanout for a transaction of any size to 10% ...
    (comp.databases.oracle.server)
  • Re: ACID et al
    ... manager" when you said "locking". ... memory, and combines the multiple threads in a single process, the distinction between an in memory database and a database that's on disk with a cache in memory is trivial as far as ACID is concerned. ... If I've got that right, I'm going to call your attenttion to a long and involved recent thread in which some people compared SQL, which requires a "START TRANSACTION", and a "COMMIT" or "ROLLBACK" to a more developed language, in which an entire atomic transaction can always be expressed in the form of a single request. ...
    (comp.databases.theory)
  • Re: Recordset.AddNew and the recordset objects data retaining
    ... You may be right about the transaction. ... round trip per each loop. ... with one database update trip PER RECORD is catastrophic. ... paging issues to keep the memory resources under control if you need better ...
    (microsoft.public.data.ado)