Subject RE: [IBO] Explicit transaction and FK Violation
Author Nico Callewaert

Do you have to call "StartTransaction", or does IBO this for you ?
Because I never call this method and everything seems to work fine. Maybe
you could explain me the advantage of this ? And is it necessary to call
"Unprepare" for a query, or is a hard "Commit" enough ?

Many thanks,
Kind regards,

Nico Callewaert
-----Oorspronkelijk bericht-----
Van: Helen Borrie [mailto:helebor@...]
Verzonden: zaterdag 17 februari 2001 12:10
Onderwerp: Re: [IBO] Explicit transaction and FK Violation

At 09:57 PM 17-02-01 +1100, you wrote:

>Do it this way:
>procedure DoSQLWork( mySQL : String);
> with DataModule1.trWork do
> begin
> try
> if InTransaction then
> try
> Commit
> except
> Rollback;
> {{ and do something }};
> end;
> StartTransaction;
> with DataModule1.ibDSQLWork do
> begin
> if Prepared then
> Prepared := False;
> SQL.Clear;
> SQL.Add(mySQL);
> Prepare;
> Execute;
> end;{with ibDSQLWork}
> finally
> Commit;
> end;{try}
> end;{with trWork}

Sorry, just noticed this try..finally.. which I mistakenly thought
was a try...except. So here's replacement code for the end part:

> try

> Prepare;
> Execute;
> end;{with ibDSQLWork}
> Commit

{{ handle the error }}
> end;{try}
> end;{with trWork}

You should use try...finally to force the program to run a piece of
code in the finally....end block *regardless* of what happens between
try.... and finally, e.g. restore a screen cursor, release/free an object
created by the method before the try... block began, etc.

With your use of finally... you are trying to run code which is
actually impossible because the unhandled error inside the try... block
makes the Commit impossible.


All for Open and Open for All
InterBase Developer Initiative ยท

Yahoo! Groups Sponsor

Stamp powered by

[Non-text portions of this message have been removed]