Recent

Author Topic: Zeos/Firebird Exception Handling  (Read 6745 times)

dogriz

  • Full Member
  • ***
  • Posts: 119
    • Tech blog - Delphi, Lazarus, Firebird, Windows, Linux, Android...
Zeos/Firebird Exception Handling
« on: January 25, 2014, 03:00:17 pm »
Is there a way to handle Firebird Exception message in Lazarus?

ZEOS 7.1.2
Firebird 2.5.2
Lazarus 1.0.xx
FPC 3.0.4
Lazarus 2.0.6
Debian x86_64, arm

mangakissa

  • Hero Member
  • *****
  • Posts: 1101
Re: Zeos/Firebird Exception Handling
« Reply #1 on: January 26, 2014, 03:56:52 pm »
The most datacomponments has the following events.
- OnDeleteError
- OnPosterror
- OnInsertError
 Sometimes (SQBdb has) OnUpdateError
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

sin_dragan

  • Full Member
  • ***
  • Posts: 127
Re: Zeos/Firebird Exception Handling
« Reply #2 on: January 27, 2014, 09:23:54 pm »
Hi i use this with SqlDB, I think you can do the same with Zeos:

Code: [Select]
with dmCv.MestaQ do
    begin
      if Izmena then MestoID := Fields[0].AsInteger;
      Close;
      if Izmena then
      begin
        SQL := UpdateSQL;
        Params[2].AsInteger := MestoID;
      end
      else SQL := InsertSQL;
      Params[0].AsString := edtNazivMesta.Text;
      Params[1].AsString := mmKomentarMesta.Text;
      ExecSQL;
      dmCv.FBTran.Commit;
    end;

  except
    on E: EIBDatabaseError do
    begin
      case E.GDSErrorCode of
      335544665 : ShowMessage('Mesto ' + edtNazivMesta.Text + ' već postoji u bazi.'); //record already exist in DB
      else
        ShowMessage('Greška u radu sa bazom podataka, pozovite IT službu!');
        Close;
      end;
    end;

//or with Zeos

procedure TForm1.Button1Click(Sender: TObject);
begin
  try
  ZQuery1.ExecSQL;
  ZQuery1.Open;

  except
    on E:EZSQLException do
      ShowMessage('sql error code' + inttostr(e.ErrorCode) + sLineBreak +e.Message);
  end;
end;                     

« Last Edit: January 27, 2014, 09:34:39 pm by sin_dragan »
Windows 7 64 bit
Lazarus 1.4.1 (w/fixes) FPC 2.6.4 win32

dogriz

  • Full Member
  • ***
  • Posts: 119
    • Tech blog - Delphi, Lazarus, Firebird, Windows, Linux, Android...
Re: Zeos/Firebird Exception Handling
« Reply #3 on: January 27, 2014, 10:16:48 pm »
Actually, I want to catch exception message like the one in employee database.
For example, in employee database there are a few exceptions defined (CUSTOMER_CHECK, CUSTOMER_ON_HOLD...) and I want to catch exception message string ("Overdue balance -- can not ship.").
Simple use of try except on E: Exception doesn't give me the message I want.
And, btw, which version of ZEOS has E:EZSQLException?
« Last Edit: January 27, 2014, 10:20:59 pm by dogriz »
FPC 3.0.4
Lazarus 2.0.6
Debian x86_64, arm

sin_dragan

  • Full Member
  • ***
  • Posts: 127
Re: Zeos/Firebird Exception Handling
« Reply #4 on: January 28, 2014, 12:21:37 am »
Try this, it's not a perfect solution but it could serve you.

In ZDbcInterbase6Utils.pas line 814 change to ErrorMessage := ErrorMessage + '|' + String(Msg);

Rebuild clean Zeos package.
Add Zstoredproc.

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var
  SL: TStringList;
begin
  try
  sl := TStringList.Create;
  ZStoredProc1.StoredProcName := 'SHIP_ORDER';
  ZStoredProc1.Params[0].AsString := 'V93N5822';
  ZStoredProc1.ExecProc;
  except
    on E:EZSQLException do
    begin
      sl.Delimiter := '|';
      sl.StrictDelimiter := true;
      sl.DelimitedText := E.Message;
      ShowMessage(sl[3]);
    end;
  end;
end;                   
Windows 7 64 bit
Lazarus 1.4.1 (w/fixes) FPC 2.6.4 win32

dogriz

  • Full Member
  • ***
  • Posts: 119
    • Tech blog - Delphi, Lazarus, Firebird, Windows, Linux, Android...
Re: Zeos/Firebird Exception Handling
« Reply #5 on: January 28, 2014, 10:34:03 am »
Try this, it's not a perfect solution but it could serve you.

In ZDbcInterbase6Utils.pas line 814 change to ErrorMessage := ErrorMessage + '|' + String(Msg);

Rebuild clean Zeos package.
Add Zstoredproc.

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var
  SL: TStringList;
begin
  try
  sl := TStringList.Create;
  ZStoredProc1.StoredProcName := 'SHIP_ORDER';
  ZStoredProc1.Params[0].AsString := 'V93N5822';
  ZStoredProc1.ExecProc;
  except
    on E:EZSQLException do
    begin
      sl.Delimiter := '|';
      sl.StrictDelimiter := true;
      sl.DelimitedText := E.Message;
      ShowMessage(sl[3]);
    end;
  end;
end;                   


I get this error:
Quote
unit1.pas(45,10) Error: Identifier not found "EZSQLException"
I use ZEOS 7.1.2-stable.
FPC 3.0.4
Lazarus 2.0.6
Debian x86_64, arm

sin_dragan

  • Full Member
  • ***
  • Posts: 127
Re: Zeos/Firebird Exception Handling
« Reply #6 on: January 29, 2014, 04:58:27 pm »
I also use 7.1.2-stable, add ZDbcIntfs to use list.

You can try to read the full message from exception, I'll try to find a way to parse the message without the need to modify zeos source.
Windows 7 64 bit
Lazarus 1.4.1 (w/fixes) FPC 2.6.4 win32

 

TinyPortal © 2005-2018