Issue Details (XML | Word | Printable)

Key: DERBY-115
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Unassigned
Reporter: Daniel John Debrunner
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Derby

BEFORE triggers missing from CREATE TRIGGER documentation

Created: 05/Jan/05 05:34 AM   Updated: 25/Jun/05 09:30 AM
Return to search
Component/s: Documentation
Affects Version/s: 10.0.2.1
Fix Version/s: 10.1.1.0

Time Tracking:
Not Specified

File Attachments:
  Size
Zip Archive Licensed for inclusion in ASF works derby115final2.zip 2005-06-25 09:02 AM Jeff Levitt 7 kB

Resolution Date: 25/Jun/05 09:30 AM


 Description  « Hide
Derby does support before triggers, syntax is the same as after triggers,
but replace AFTER with NO CASCADE BEFORE. Eg.

create trigger t1
NO CASCADE BEFORE insert on x
referencing new_table as newrowtab
for each statement mode db2sql
insert into y select x from newrowtab;


 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Jeff Levitt added a comment - 17/Jun/05 02:37 AM
Hi Dan, I'd be happy to make this change. However, it seems to me that the CREATE TRIGGERS syntax has another mistake that I'd like to fix at the same time. See:

http://incubator.apache.org/derby/docs/ref/rrefsqlj43125.html

On that page, the syntax seems to be missing a closing curly brace "}" to the one that is opened after the "AFTER".
  
CREATE TRIGGER TriggerName
AFTER
{ INSERT | DELETE | UPDATE [ OF column-Name [, column-Name]* ]
ON table-Name
[ ReferencingClause ]
FOR EACH { ROW | STATEMENT } MODE DB2SQL
Triggered-SQL-statement

Where should the closing curly brace go?

Also, for NO CASCADE BEFORE, should I just modify this syntax to look like this?:

CREATE TRIGGER TriggerName
NO CASCADE BEFORE | AFTER
{ INSERT | DELETE | UPDATE [ OF column-Name [, column-Name]* ]
ON table-Name
[ ReferencingClause ]
FOR EACH { ROW | STATEMENT } MODE DB2SQL
Triggered-SQL-statement

Daniel John Debrunner added a comment - 18/Jun/05 04:20 AM
I think this is correct:

- braces around the NO CASCADE BEFORE | AFTER
- missing brace put back in after the UPDATE


CREATE TRIGGER TriggerName
{ NO CASCADE BEFORE | AFTER }
{ INSERT | DELETE | UPDATE } [ OF column-Name [, column-Name]* ]
ON table-Name
[ ReferencingClause ]
FOR EACH { ROW | STATEMENT } MODE DB2SQL
Triggered-SQL-statement

Jeff Levitt added a comment - 18/Jun/05 08:12 AM
Attached patch fixes the syntax, adds NO CASCADE BEFORE, and mentions Before triggers in two additional places in the topic where it used to just mention After triggers. Please see attached output in html for review, and provide either feedback or a thumbs up so we can get the changes commited. Thanks!

Jeff Levitt made changes - 18/Jun/05 08:12 AM
Field Original Value New Value
Attachment derby115.zip [ 12310833 ]
Repository Revision Date User Message
ASF #201702 Sat Jun 25 00:30:07 UTC 2005 jta DERBY-115 Committed Jeff Levitt's patch that documents BEFORE triggers.
Files Changed
MODIFY /incubator/derby/docs/trunk/src/ref/rrefsqlj43125.dita

Jean T. Anderson added a comment - 25/Jun/05 07:12 AM
The NO CASCADE BEFORE example in the patch won't work because BEFORE triggers don't allow INSERTs. A BEFORE trigger can execute a SQL function, so here's a suggestion:
 
CREATE TRIGGER t1 NO CASCADE BEFORE UPDATE ON x
FOR EACH ROW MODE DB2SQL
  values app.notifyEmail('Jerry', 'Table x is about to be updated');


Jeff Levitt added a comment - 25/Jun/05 08:41 AM
Attached patch uses Jean's example instead of the one previously there. Please review! Thanks!

Jeff Levitt made changes - 25/Jun/05 08:41 AM
Attachment derby115final.zip [ 12310950 ]
Daniel John Debrunner added a comment - 25/Jun/05 08:54 AM
In the Triggered-SQL-statement section, an additiona limitation is that before triggers can not have INSERT, UPDATE or DELETE statements as their action.

Jeff Levitt added a comment - 25/Jun/05 09:02 AM
Attached patch adds the line Dan requested...please review!

Jeff Levitt made changes - 25/Jun/05 09:02 AM
Attachment derby115final2.zip [ 12310951 ]
Daniel John Debrunner added a comment - 25/Jun/05 09:26 AM
looks good!

Jean T. Anderson added a comment - 25/Jun/05 09:30 AM
Committed, revision 201702, Jeff Levitt's patch that documents BEFORE triggers. Changed files:
$ svn status
M src/ref/rrefsqlj43125.dita

Jean T. Anderson made changes - 25/Jun/05 09:30 AM
Resolution Fixed [ 1 ]
Status Open [ 1 ] Closed [ 6 ]
Fix Version/s 10.1.1.0 [ 10993 ]