TClientDataset ApplyUpdates error due to database table constraint

I have an old Delphi 7 application that loads data from one database table, does a lot of operations and calculations, and finally writes records to the destination table.

This legacy application calls ApplyUpdates every 500 records for performance reasons.

The problem is that sometimes there is one in this group of records, which will cause the database limitation; Delphi throws an exception on ApplyUpdates .

My problem is that I don't know who is responsible for this exception. There are 500 candidates!

Can a TClientDataset be requested that is an offensive entry?

I dont want to apply Updates to write attached entry for performance issues.

+3


source to share


2 answers


I think you can try to implement an event OnReconcileError

that fires once for every record that cannot be applied to the dataset, So I would try the following code, raSkip

means skip the current record here:

procedure TForm1.ClientDataSet1ReconcileError(DataSet: TCustomClientDataSet;
  E: EReconcileError; UpdateKind: TUpdateKind; var Action: TReconcileAction);
begin
  Action := raSkip;
  ShowMessage('The record with ID = ' + DataSet.FieldByName('ID').AsString +
    ' couldn''t be updated!' + sLineBreak + E.Context);
end;

      



But please note: I've never tried this before, and I'm not sure if it's too late to ignore the errors caused ApplyUpdates

. Forgot to mention, try using the passed parameter DataSet

, which should contain a record that cannot be updated; this could be a way to determine which entry caused the problem.

And here

updates that apply the workflow are described.

+7


source


The implementation OnReconcileError

will give you access to the record and data that is responsible for the exception. An easy way to do this is to add a "Recall Error Dialogue". It's in the New Items dialog box, which displays File | New | Others. Once you have added it to your project and used it on the form using clientdataset. The following code shows how it is called.

procedure TForm1.ClientDataSetReconcileError(DataSet: TCustomClientDataSet;
  E: EReconcileError; UpdateKind: TUpdateKind;
  var Action: TReconcileAction);
begin
  Action := HandleReconcileError(DataSet, UpdateKind, E);
end;

      



It will be displayed instead of the exception dialog. This will allow you to review the offending data and choose how you want to proceed. It's been over 5 years since I last used it, hopefully I haven't forgotten some of the details.

+2


source







All Articles