Small issue with pgscript component

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
snorkel
Posts: 384
Joined: Tue 08 Aug 2006 15:10
Location: Milwaukee WI USA

Small issue with pgscript component

Post by snorkel » Fri 09 Jan 2009 21:02

Hi,
I have been using the script component as a work around for the inability of the query component to execute multiple commands and for the most part it works ok, except when a error occurs.
In most of my situations I have my own exception handler, for example

try
myscript.sql.add('some sql');
myscript.sql.add('some sql');
myscript.sql.add('somesql');
excute; //does not allow script exceptions to bubble up
modalresult:=mrok;

except
on e:exception do
showmessage(e.message);
end;

Because the script handles the errors it always executes the modalresult line, I tried using the scripts on error handler but it does not work the way I need it to.
The error handler would be ok if it had a option to abort and re raise the exception so the outside error handler picks up the exception.

I tried to re raise the exception that is passed in the even and then do a
eaAbort, but that does not work because the passed exeption goes out of scope and I get a invalid pointer error.

Please advise,


Snorkel

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Tue 13 Jan 2009 09:08

Use the following handler for the OnError event:

Code: Select all

procedure TForm1.PgScript1Error(Sender: TObject; E: Exception;
  SQL: String; var Action: TErrorAction);
begin
  Action := eaFail;
end;
In this case the script raises the exception, and you can catch it.

snorkel
Posts: 384
Joined: Tue 08 Aug 2006 15:10
Location: Milwaukee WI USA

Post by snorkel » Tue 13 Jan 2009 16:08

Plash wrote:Use the following handler for the OnError event:

Code: Select all

procedure TForm1.PgScript1Error(Sender: TObject; E: Exception;
  SQL: String; var Action: TErrorAction);
begin
  Action := eaFail;
end;
In this case the script raises the exception, and you can catch it.
hmm, I tried that in the build I have and it didn't seem to re raise the exception so it was caught in the external try except.

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Wed 14 Jan 2009 08:13

This code works in my test.

snorkel
Posts: 384
Joined: Tue 08 Aug 2006 15:10
Location: Milwaukee WI USA

Post by snorkel » Wed 14 Jan 2009 16:50

Plash wrote:This code works in my test.
Ok, I will try it again.

Post Reply