Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » ElevateDB Technical Support » Support Forums » ElevateDB SQL » View Thread |
Messages 1 to 10 of 10 total |
How to code a condition for a trigger |
Sat, Mar 19 2011 5:09 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | I have a simple change log trigger on a number of tables eg for Companies the trigger is:
----------------------------------------------------------------------------------------------------------------- CREATE TRIGGER "ChangeLog" BEFORE ALL ON "Companies" BEGIN DECLARE ExistingChangeLog VARCHAR DEFAULT ''; IF OPERATION <> 'Delete' THEN IF OPERATION() <> 'Insert' THEN SET NEWROW._ModDate = CURRENT_DATE; IF OLDROW._ChangeLog IS NOT NULL THEN SET ExistingChangeLog = OLDROW._ChangeLog + #13; END IF; END IF; SET NEWROW._ChangeLog = ExistingChangeLog + CAST(CURRENT_TIMESTAMP AS VARCHAR(24) DATE FORMAT 'dd/mm/yyyy' TIME FORMAT 'hh:mm:ss') + '¬' + CURRENT_USER; END IF; END ---------------------------------------------------------------------------------------------------------------- I want to add a condition which says "if only these columns have changed don't bother" and I'm trying, and failing, to think of a way of setting the condition which avoids having 20+ if oldcolumn<>newcolumn type statements. I wouldn't mind doing this for just one table but there are several with upto 60 columns Roy Lambert |
Mon, Mar 21 2011 5:00 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Roy,
<< I want to add a condition which says "if only these columns have changed don't bother" and I'm trying, and failing, to think of a way of setting the condition which avoids having 20+ if oldcolumn<>newcolumn type statements. I wouldn't mind doing this for just one table but there are several with upto 60 columns >> Are you wanting this to only happen on updates, or on inserts and updates ? -- Tim Young Elevate Software www.elevatesoft.com |
Tue, Mar 22 2011 3:43 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Tim
Updates only. Roy Lambert |
Wed, Mar 23 2011 5:49 AM | Permanent Link |
John Hay | Roy
> I have a simple change log trigger on a number of tables eg for Companies the trigger is: I thought change logs were the work of the devil <bg> John |
Wed, Mar 23 2011 8:22 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | John
>> I have a simple change log trigger on a number of tables eg for Companies the trigger is: > >I thought change logs were the work of the devil <bg> Nah - they're not evil enough for that - it was one of his imps that designed them. Anyway mine is almost saintly - all it does is say something was changed not give a full audit trail or journal. Roy Lambert |
Wed, Mar 30 2011 11:59 AM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Roy,
<< Updates only. >> A condition is any valid Boolean expression that references any of the columns in the current table, the OLDROW/NEWROW values, or any function/UDF that is present in the database. -- Tim Young Elevate Software www.elevatesoft.com |
Wed, Mar 30 2011 1:48 PM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Tim
But what I want is to be able to say If only these columns have changed forget it but if any of the others have changed go ahead without having to put in 60 tests. Is there a way? Roy Lambert |
Mon, Apr 4 2011 2:43 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Roy,
<< But what I want is to be able to say If only these columns have changed forget it but if any of the others have changed go ahead without having to put in 60 tests. Is there a way? >> Not currently, no. You can specify the set of columns to fire the trigger on when they're updated, but not the opposite. -- Tim Young Elevate Software www.elevatesoft.com |
Tue, Apr 5 2011 3:41 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Tim
>Not currently, no. You can specify the set of columns to fire the trigger >on when they're updated, but not the opposite. Sigh I'll have to see what impact 60 tests make on a post versus disabling & re-enabling the trigger Roy Lambert |
Mon, Apr 18 2011 9:17 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Tim
I solved it! Moved the code back into Delphi and linked it through the various tables OnBeforePost events. Part of my problem was that if the system was updating it I didn't want a record but if a user did I wanted the record. Roy Lambert |
This web page was last updated on Tuesday, April 30, 2024 at 03:55 PM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |