Hi All,
Just wanted to know if this is an expected behaviour of create statement,
when i am writing it after create statement. it does not execute, instead if i am writing it before create statement it did work.
Below is the code which does not work.
/*trigger does not execute*/
define variable x as int init 1.
create table1.
assign table1.field1 = x.
on create of table1
do:
x = 10.
end.
below is the code which works.
/*trigger executes here*/
define variable x as int init 1.
on create of table1
do:
x = 10.
end.
create table1.
assign table1.field1 = x.
I agree it is not intuitive, but Brian is correct. The AVM doesn't really know the ON Trigger exists until it has run across the ON statement in the execution stream. When we get to it, we don't run the contents of the block, but we set the trigger up so that when the CREATE happens we then know to run it. This is counter intuitive because it is not like anything else in the language - like internal procedures or methods. Those do not have to occur above the point where we run them. But ON triggers do.
yes, I agree it executed at run time. but ON statement should get exceuted as soon as AVM finds create staement. isn't it?
then why does it matter if on staement written before or after create statement.
>> but ON statement should get exceuted as soon as AVM finds create staement. isn't it?
I have defined the triggers in database itself, so there is no issues withg that.
Above query just for my understanding that why it really matters where i am writing on statement in the code. I know when I am writing on create trigger it will behave like session level trigger so i can override my schema trigger.
My assumption was it should get executed whereever i write as long as it is in same program.
ohh then when exactly on create get called, i thought create behaves like event.
I agree it is not intuitive, but Brian is correct. The AVM doesn't really know the ON Trigger exists until it has run across the ON statement in the execution stream. When we get to it, we don't run the contents of the block, but we set the trigger up so that when the CREATE happens we then know to run it. This is counter intuitive because it is not like anything else in the language - like internal procedures or methods. Those do not have to occur above the point where we run them. But ON triggers do.
Thanks Brian and Laura!
Just to be more clear on this point, if this is the case as Brian and Laura explained then wouldn't it be same for ON write statement as well?
But ON write statement is getting executed even i am writing it after create + assign statements.
define variable x as int init 1.
create table1.
assign table1.field1 = x.
on write of table1
do:
table1.field2 = 8.
end.
Yes, it should be the same. And for me it is! I put a message statement in the Write trigger. I am not seeing it unless i move the ON WRITE trigger up to the top.
Thank you so much Brian and Laura, got your point now :)