Page 1 of 1

Returning exceptions from executing TOraScript

Posted: Fri 11 Jun 2010 11:00
by Manfredt
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

Posted: Mon 14 Jun 2010 09:40
by bork
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;

Returning exceptions from executing TOraScript

Posted: Mon 14 Jun 2010 10:42
by Manfredt
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