Subject Re: AW: [firebird-support] transaction the hundreth
Author mark@lawinegevaar.nl
On Fri, 10 Jun 2011 09:29:17 +0200, "Olaf Kluge" <olaf.kluge@...>
wrote:
> No, for this action there is no client application involved at the time.
>
> A Procedure named as PA which creates Test-Data for Table A, B and C
> started
> by IBExpert and commit after calling manually. The procedure do:
> insert in Table A,
> insert in Table B,
> insert in Table C (more records).
> I commit the call.
>
> My problem: As soon as a new record were inserted in Table A, a trigger
> calls a Stored Procedure to process data (named as PB) (Table A, B, C). I
> have test it and at this moment of calling, the records for table B and C
> not available yet! In tableA a job is announced but there are no records
in
> Table B and C yet at this moment of calling this stored procedure PB.
>
> If I set the status from Table A to parking and update this at the end of
> inserting Data in Table B and C to a value X, then all data were present.
> In
> this case, the status will be respected by the trigger. (all this with
> Procedure PA) The calling (Procedure PB) is done via a trigger, not an
> external application.
>
> I think, despite that the stored procedure inserts all data in one
> transaction, the trigger runs before the other records were inserted.
>
> Or think I'm wrong?

Yes you are wrong - or at least your expectation is wrong - , the trigger
is executed at INSERT and not deferred until commit which you seem to
expect. So it is executed as soon as you do the INSERT into the table. As
you haven't inserted into the secondary tables yet (those follow after that
INSERT into A), nothing is found at that time.

You either need to reorder your inserts, have the processing be triggered
by inserts into B and/or C, or use an entirely different method for
triggering this processing.

Mark