Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 2 of 2 total
Thread Triggers and fails
Mon, Mar 1 2010 8:39 AMPermanent Link

Laszlo Szabo

Hi!

I want to ask that what will happen when I have table with two triggers (before and after), and some of them are failed?

Is this order is good?
1.) Before insert (DataSet)
2.) Before insert (Trigger)
3.) AfterInsert (Trigger)
4.) AfterInsert (DataSet)

If BI Trigger failed (for example it is try to update a row that locked) then what will happen?
I got an Exception and Delphi Failed on call next statement?
What happened if the AI Trigger failed? Delphi TDataSet record is created, so it is exists but possible with wrong content?

Can I post it???

My boss have an idea to use Trigger for incrementing or decrementing a number (a table field - to determine the count) but I'm afraid of this resource modification may cause row lock error, and the new element creation failed fully...

If I use transaction in the trigger can I try this resource locking again?
Or can I wait for N msecs/secs for the resource (the row)?

Thanks for your help!
Tue, Mar 2 2010 7:01 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Laszlo,

<< Is this order is good?
1.) Before insert (DataSet)
2.) Before insert (Trigger)
3.) AfterInsert (Trigger)
4.) AfterInsert (DataSet) >>

Correct.

<< If BI Trigger failed (for example it is try to update a row that locked)
then what will happen? >>

If you don't trap the exception in the trigger itself, then the exception
will bubble up and cause the execution to stop.  IOW, the insert will never
occur.

<< What happened if the AI Trigger failed? Delphi TDataSet record is
created, so it is exists but possible with wrong content? >>

Yes, the row will have been inserted, but the dataset's AfterInsert event
will not get called.

<< Can I post it??? >>

Post the trigger SQL ?

<< My boss have an idea to use Trigger for incrementing or decrementing a
number (a table field - to determine the count) but I'm afraid of this
resource modification may cause row lock error, and the new element creation
failed fully... >>

Is the column in the same table as the one being inserted into ?

<< If I use transaction in the trigger can I try this resource locking
again?  >>

You don't need a transaction to implement exception trapping and handling in
the trigger.  Just use a BEGIN..EXCEPTION block and loop when there's an
exception:

http://www.elevatesoft.com/manual?action=viewtopic&id=edb2sql&topic=EXCEPTION

BEGIN
  DECLARE Complete BOOLEAN DEFAULT FALSE;
  WHILE (NOT Complete) DO
     BEGIN
        -- Update row here
        SET Complete=TRUE;
     EXCEPTION
        IF ERRORCODE() <> 1005 THEN
           RAISE;
        END IF;
     END;
  END WHILE;
END

--
Tim Young
Elevate Software
www.elevatesoft.com

Image