Rolling back cached updates on error

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
pgimeno
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 11.10.2007, 15:34

Rolling back cached updates on error

Post by pgimeno »

I have two TZQuery components in a master-detail relationship. To edit a record (say, an invoice), the master dataset is permanently in edit mode and the detail one is freely editable (rows can be added or deleted or anything).

I have an Accept button which performs ApplyUpdates of the master, then ApplyUpdates of the detail, and a Cancel button which performs a CancelUpdates of each. Since it's not acceptable that a partial version of a record be accessible by other users, I'm wrapping the ApplyUpdates within a transaction block.

There's no problem as long as everything goes well in the server; the problem comes when one of the detail records fails on post for any reason. I have to rollback in this case, but the modifications made to all posted records (including the master) are lost.

For this purpose I would need a method that applies the updates without removing the record changes even if they're successfully posted, so that I can remove them manually on success at the end. Something like this:

Code: Select all

  Conn.StartTransaction;
  try
    Master.ApplyUpdatesNoFree;
    Detail.ApplyUpdatesNoFree;
  except
    Conn.Rollback;
    // changes are still cached at this point
    Master.Edit;
    raise;
  end;
  Conn.Commit;
  Master.FreeUpdates;
  Detail.FreeUpdates;
Is it possible at all to do such thing? I've seen there is a CommitUpdates method which apparently just clears the cached updates buffer, i.e. pretty much what FreeUpdates should do in my sample code. Is there a function which does what ApplyUpdatesNoFree is supposed to do? I'm trying to write a patch to implement this functionality but my knowledge of Zeos internals is quite limited at the moment.

TIA,

-- Pedro Gimeno
Post Reply