dbTalk Databases Forums  

stop execution at before trigger phase

sybase.public.sqlanywhere.general sybase.public.sqlanywhere.general


Discuss stop execution at before trigger phase in the sybase.public.sqlanywhere.general forum.



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

Default stop execution at before trigger phase - 01-26-2010 , 05:22 AM






Hi,

I would like to write a before update trigger that will
check the value of a column and if the value is satisfied, I
would like to stop the execution flow of the command without
error.
Is it possible? if so, how can Ido that?

Thanks,

Reply With Quote
  #2  
Old   
Clive Collie
 
Posts: n/a

Default Re: stop execution at before trigger phase - 01-26-2010 , 05:40 AM






Think the other way round: if values IS NOT satisfied then do something else
don't bother.
Use old_ and new_ row variable to get values for columns.

CREATE TRIGGER "Xxx" BEFORE UPDATE
ORDER 1 ON "TableName"
REFERENCING OLD AS old_row NEW AS new_row
FOR EACH ROW /* WHEN( search_condition ) */
BEGIN
if old_row.col_Val <> 'whatever' then
// do something here
end if;
END;

Clive

"a.sahan" wrote in message news:4b5ed07f.3882.1681692777 (AT) sybase (DOT) com...
Quote:
Hi,

I would like to write a before update trigger that will
check the value of a column and if the value is satisfied, I
would like to stop the execution flow of the command without
error.
Is it possible? if so, how can Ido that?

Thanks,

Reply With Quote
  #3  
Old   
a.sahan
 
Posts: n/a

Default Re: stop execution at before trigger phase - 01-27-2010 , 02:18 AM



Thank you for your reply. However, it can be misunderstood.
My goal is to stop execution flow, not only trigger itself.

For example,
I would like to update a record in a table but if one of the
columns is equal to zero, I would like to cancel update
command. I can't check this before command execution. The
only way is to detect it in trigger or another way.
Quote:
Think the other way round: if values IS NOT satisfied then
do something else don't bother.
Use old_ and new_ row variable to get values for columns.

CREATE TRIGGER "Xxx" BEFORE UPDATE
ORDER 1 ON "TableName"
REFERENCING OLD AS old_row NEW AS new_row
FOR EACH ROW /* WHEN( search_condition ) */
BEGIN
if old_row.col_Val <> 'whatever' then
// do something here
end if;
END;

Clive

"a.sahan" wrote in message
news:4b5ed07f.3882.1681692777 (AT) sybase (DOT) com... Hi,

I would like to write a before update trigger that will
check the value of a column and if the value is
satisfied, I would like to stop the execution flow of
the command without error.
Is it possible? if so, how can Ido that?

Thanks,

Reply With Quote
  #4  
Old   
Volker Barth
 
Posts: n/a

Default Re: stop execution at before trigger phase - 01-27-2010 , 09:21 AM



If I understand your request correctly, ROLLBACK TRIGGER might be your
friend, i.e. smething like (untested)

CREATE TRIGGER "Xxx" BEFORE UPDATE
ORDER 1 ON "TableName"
REFERENCING NEW AS new_row
FOR EACH ROW
BEGIN
if new_row.col_Val = 0
message '0 value detected: Revoke action' to log;
rollback trigger;
end if;
END;

This will undo the update itself.
Note: This might work not well if used within nested triggers - cf. the
docs (and the [ WITH raiserror-statement ] option).


HTH
Volker


Am 27.01.2010 09:18, schrieb a.sahan:
Quote:
Thank you for your reply. However, it can be misunderstood.
My goal is to stop execution flow, not only trigger itself.

For example,
I would like to update a record in a table but if one of the
columns is equal to zero, I would like to cancel update
command. I can't check this before command execution. The
only way is to detect it in trigger or another way.
Think the other way round: if values IS NOT satisfied then
do something else don't bother.
Use old_ and new_ row variable to get values for columns.

CREATE TRIGGER "Xxx" BEFORE UPDATE
ORDER 1 ON "TableName"
REFERENCING OLD AS old_row NEW AS new_row
FOR EACH ROW /* WHEN( search_condition ) */
BEGIN
if old_row.col_Val<> 'whatever' then
// do something here
end if;
END;

Clive

"a.sahan" wrote in message
news:4b5ed07f.3882.1681692777 (AT) sybase (DOT) com... Hi,

I would like to write a before update trigger that will
check the value of a column and if the value is
satisfied, I would like to stop the execution flow of
the command without error.
Is it possible? if so, how can Ido that?

Thanks,

Reply With Quote
  #5  
Old   
a.sahan
 
Posts: n/a

Default Re: stop execution at before trigger phase - 01-28-2010 , 05:41 AM



Thank you. That's what I'm looking for. and in case of
recursion, can it be resolved by moving rollbAck command
into After-Update Trigger?

Quote:
If I understand your request correctly, ROLLBACK TRIGGER
might be your friend, i.e. smething like (untested)

CREATE TRIGGER "Xxx" BEFORE UPDATE
ORDER 1 ON "TableName"
REFERENCING NEW AS new_row
FOR EACH ROW
BEGIN
if new_row.col_Val = 0
message '0 value detected: Revoke action' to log;
rollback trigger;
end if;
END;

This will undo the update itself.
Note: This might work not well if used within nested
triggers - cf. the docs (and the [ WITH
raiserror-statement ] option).


HTH
Volker


Am 27.01.2010 09:18, schrieb a.sahan:
Thank you for your reply. However, it can be
misunderstood. My goal is to stop execution flow, not
only trigger itself.
For example,
I would like to update a record in a table but if one of
the columns is equal to zero, I would like to cancel
update command. I can't check this before command
execution. The only way is to detect it in trigger or
another way. >> Think the other way round: if values IS
NOT satisfied then >> do something else don't bother.
Use old_ and new_ row variable to get values for
columns.
CREATE TRIGGER "Xxx" BEFORE UPDATE
ORDER 1 ON "TableName"
REFERENCING OLD AS old_row NEW AS new_row
FOR EACH ROW /* WHEN( search_condition ) */
BEGIN
if old_row.col_Val<> 'whatever' then
// do something here
end if;
END;

Clive

"a.sahan" wrote in message
news:4b5ed07f.3882.1681692777 (AT) sybase (DOT) com... Hi,

I would like to write a before update trigger that
will >>> check the value of a column and if the value is
satisfied, I would like to stop the execution flow of
the command without error.
Is it possible? if so, how can Ido that?

Thanks,

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.