Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Still get error popup even when ApplyUpdates is inside try...except

Tags:

delphi

odbc

Solution found, see my comment below

D5, odbc to mysql database

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

(specifically the "ApplyUpdates") causes a popup to appear with the text "Update Failed" if the PnL field already has the value 97979, evidently 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 issue ApplyUpdates, and not have to worry about a popup if it doesn't do any updating. But if "try...except" doesn't work, what will?

TIA

like image 475
davej Avatar asked Apr 20 '11 19:04

davej


2 Answers

You're confusing the dialog displayed by the debugger with a dialog displayed by your program. Please see this article I wrote a few years ago:

  • Why do I continue getting error messages even after I have written an exception handler?

It describes several ways to avoid the debugger interfering:

  • Use "advanced breakpoints" to temporarily disable the debugger around the code that throws exceptions.
  • Configure the debugger to ignore certain exception types. (Read the debugger's message more carefully to see exactly what exception class you're dealing with.)
  • Configure the debugger not to interrupt on any exceptions.
  • Turn off integrated debugger entirely.
like image 104
Rob Kennedy Avatar answered Oct 16 '22 18:10

Rob Kennedy


The short answer is, you have to set up an eventhandler for OnUpdateError or no amount of "try...except" blocks will block the popup. The long answer is it appears to be a bug with odbc. The repro is here: http://www.codeupload.com/3919 for anyone who wants to take a look at it. You can skip the MySQL stuff, any odbc database will do.

like image 2
davej Avatar answered Oct 16 '22 18:10

davej