Subject | Re: [IBO] Explicit transaction and FK Violation |
---|---|
Author | Helen Borrie |
Post date | 2001-02-17T11:10:12Z |
At 09:57 PM 17-02-01 +1100, you wrote:
Rollback;
{{ handle the error }}
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.
HB
All for Open and Open for All
InterBase Developer Initiative ยท http://www.interbase2000.org
_______________________________________________________
>Do it this way:Sorry, just noticed this try..finally.. which I mistakenly thought was a try...except. So here's replacement code for the end part:
>
>procedure DoSQLWork( mySQL : String);
>begin
> 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}
>end;{DoSQLWork}
> try..........
> Prepare;except
> Execute;
> end;{with ibDSQLWork}
> Commit
Rollback;
{{ handle the error }}
> end;{try}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.
> end;{with trWork}
>end;{DoSQLWork}
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.
HB
All for Open and Open for All
InterBase Developer Initiative ยท http://www.interbase2000.org
_______________________________________________________