An error popup still appears, even when the ApplyUpdates application inside tries ... except

Solution found, see my comment below

D5, odbc database for mysql

This code:

  with QryCmdPerf do begin
    Close;
    ParamByName('ACCTID').AsInteger:= AcctId;
    ParamByName('FROMDT').AsString:= MySQLDate(FromDt);
    ParamByName('TODT').AsString:= MySQLDate(ToDt);
    Open;
    first;
    try
      edit;
      FieldByName('PnL').AsFloat:= 97979;
      ApplyUpdates;
    except
      close;
    end;
  end;    // with

(in particular, “ApplyUpdates”) brings up a pop-up window with the text “Update Failed” if the PnL field already has the value 97979, obviously because of this code:

procedure TUpdateSQL.ExecSQL(UpdateKind: TUpdateKind);
begin
  with Query[UpdateKind] do
  begin
    Prepare;
    ExecSQL;
    if RowsAffected <> 1 then DatabaseError(SUpdateFailed);
  end;
end;

in DBTables.pas. Anyway, I want to be able to give ApplyUpdates, and I don’t have to worry about a popup if it doesn’t do any updating. But if "try ... except" does not work, what will happen?

TIA

+5
source share
3 answers

: OnUpdateError "try... except" . - odbc. : http://www.codeupload.com/3919 , . MySQL, odbc .

+2

, , , . . , :

:

  • " ", , .
  • . ( , , .)
  • , .
  • .
+4

.

1

-, " " . . ApplyUpdates try...except, Application.HandleException .

, QryCmdPerf.Close, ?
, Application.HandleException ( Application.ShowException) .

, Application.OnException. , , , .
, , Application.HandleException , " ".

2

If you reach a breakpoint, but an exception is thrown again, then this should be much easier to solve.

The method Closeis probably trying to keep any pending changes, so it effectively applies the updates again. Instead of simply closing the dataset, call CancelChangesor equivalent.

0
source

All Articles