dbTalk Databases Forums  

Trigger Unlimited Recursion Error

comp.databases.sybase comp.databases.sybase


Discuss Trigger Unlimited Recursion Error in the comp.databases.sybase forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Damjan
 
Posts: n/a

Default Trigger Unlimited Recursion Error - 06-27-2003 , 06:17 AM






WOW!
I am in owe. Thanks a lot. Maybe I can send you my project

Anyway, I've got few comments (if you have time):

1. I've learned many things from your code.

2. What I've noticed is that you (and I assume on purpose) repeat yourself,
so for the update trigger you say:
a) if no inserted row then exit
[if 0 = (select count(*) from inserted) then return end if;]
b) then you say:Are there any rows that have not already been
processed by the trigger
[if 0 = (select count(*) from inserted where not exists (select
1 from FooFum_sync_state where FooFum_sync_state.ThePk=
inserted.ThePk) )then return end if;]
But you already verified in a) that the inserted row exists,
so why not do just this:
if ((select count(*) from FooFum_sync_state
where FooFum_sync_state.ThePk=inserted.ThePk) > 0) then return
end if;
to verify that that there are now rows in state table?
c) then again in the insert you verify everything again
[insert into FooFum_sync_state (TriggerTs, ThePk) select @TriggerTs,
ThePk from inserted where not exists (select 1 from
FooFum_sync_state where FooFum_sync_state.ThePk= inserted.ThePk );]
Where I would do insert into FooFum_sync_state (TriggerTs, ThePk)
VALUES (@TriggerTs, inserted.ThePk)
d) even in update you do it with the FROM clause
Are you just extra hugely safe? I've got to re-write a lot of sql
queries to keep up with your standard!

3. The GLOBAL TEMPORARY TABLE is a good idea. I added a boolean column
to both FUM and FOO. In trigger I check if there is a true(or any)
value for that colum.
- If yes it means it is called from trigger, so I do not do an update.
- If no, then it is called from application so an update with a true (or
any) value for the boolean column.


Thanks a lot once more,

Damjan

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.