Returning exceptions from executing TOraScript

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Manfredt
Posts: 5
Joined: Tue 21 Jul 2009 19:01

Returning exceptions from executing TOraScript

Post by Manfredt » Fri 11 Jun 2010 11:00

I want to return error conditions from Executing TOraScript to indicate
wether posting to the database was successful or not. The insert statements
are generated dynamically at runtime and after executing TOraScript I would
like to return some sort of result indicating success or failure.

Thanks

Manfredt Kavetu

bork
Devart Team
Posts: 649
Joined: Fri 12 Mar 2010 07:55

Post by bork » Mon 14 Jun 2010 09:40

Hello

You should handle the OnError event. And you can use two ways.

The first one: set variable:

Code: Select all

function TForm1.ExecSQL(SQL: string): boolean;
begin
  HasError := False;
  OraScript1.SQL.Text := SQL;
  OraScript1.Execute;
  Result := not HasError;
end;

procedure TForm1.OraScript1Error(Sender: TObject; E: Exception;
  SQL: String; var Action: TErrorAction);
begin
  HasError := True;
end;
The second way is to raise an error:

Code: Select all

function ExecSQL(SQL: string): boolean;
begin
  OraScript1.SQL.Text := SQL;
  try
    OraScript1.Execute;
    Result := True;
  except  
    Result := False;
  end;
end;

procedure TForm1.OraScript1Error(Sender: TObject; E: Exception;
  SQL: String; var Action: TErrorAction);
begin
  Action := eaFail;
end;

Manfredt
Posts: 5
Joined: Tue 21 Jul 2009 19:01

Returning exceptions from executing TOraScript

Post by Manfredt » Mon 14 Jun 2010 10:42

Thanks Bork. I found a solution similar to your first one and put the
line Action := eaContinue in the OnError event of TOraScript but I like your second solution which also works well.

Manfredt Kavetu

Post Reply