#1  
Old 4th October 2007, 07:09 PM
Wolfgang
 
Posts: n/a
Default Triggers

I just started playing around with Triggers and am not certain, whether I am
missing something or not.

It seems, that the UPDATE Trigger only kicks in, if the changed column is
"not null", but has a value already?

Kind Regards
Wolfgang

Here's the Code:

DROP TRIGGER IF EXISTS "DebtorLog";
DROP TABLE IF EXISTS "DebtorLog";
CREATE TABLE "DebtorLog"(
"Action" VARCHAR(15),
"Occurred" DATETIME,
"CurrentUser" VARCHAR(45),
"Account" VARCHAR(8),
"Category" VARCHAR(1),
"Contact" VARCHAR(25),
"CreditLimit" REAL
);
CREATE INDEX "AccountIx" ON "DebtorLog"("Account" IGNORE CASE);
CREATE INDEX "CategoryIx" ON "DebtorLog"("Category" IGNORE CASE);
CREATE INDEX "ContactIx" ON "DebtorLog"("Contact" IGNORE CASE);
CREATE TRIGGER "DebtorLog"
AFTER INSERT,DELETE,UPDATE ON "Debtor"
REFERENCING OLD AS o NEW AS n
BEGIN
IF INSERTING THEN
INSERT INTO "DebtorLog"("Action", "Occurred", "CurrentUser",
"Account",
"Category",
"Contact",
"CreditLimit")
VALUES('Insert',CURRENT_TIMESTAMP, CURRENT_USER,
n."Account",
n."Category",
n."Contact",
n."CreditLimit");
END IF;
IF DELETING THEN
INSERT INTO "DebtorLog"("Action", "Occurred", "CurrentUser",
"Account",
"Category",
"Contact",
"CreditLimit")
VALUES('Delete',CURRENT_TIMESTAMP, CURRENT_USER,
o."Account",
o."Category",
o."Contact",
o."CreditLimit");
END IF;
IF UPDATING
and (
(coalesce(o.Dormant, False) = False)
)
and ((o."Account" <> n."Account")
or (o."Category" <> n."Category")
or (o."Contact" <> n."Contact")
or (o."CreditLimit" <> n."CreditLimit"))
THEN
INSERT INTO "DebtorLog"("Action", "Occurred", "CurrentUser",
"Account",
"Category",
"Contact",
"CreditLimit")
VALUES('Before',CURRENT_TIMESTAMP, CURRENT_USER,
o."Account",
o."Category",
o."Contact",
o."CreditLimit"),
('After',CURRENT_TIMESTAMP, CURRENT_USER,
n."Account",
n."Category",
n."Contact",
n."CreditLimit");
END IF;
END


  #2  
Old 5th October 2007, 01:10 AM
Brian Evans [NDX]
 
Posts: n/a
Default Re: Triggers

Wolfgang wrote:
> I just started playing around with Triggers and am not certain,
> whether I am missing something or not.
>
> It seems, that the UPDATE Trigger only kicks in, if the changed
> column is "not null", but has a value already?
>
> Kind Regards Wolfgang


Nulls won't play well with your conditions.
Use NOT EQUIVALENT(A,B) instead of A <> B.

--
Brian Evans [NDX]
Ottawa, ON, CANADA
GMT-5
  #3  
Old 5th October 2007, 01:31 AM
Wolfgang
 
Posts: n/a
Default Re: Triggers

Thanks Brian,

works perfectly now.

Kind Regards
Wolfgang

"Brian Evans [NDX]" <bevanson@rogers.com> wrote in message
news:4704f3ec$1@nexus-vkpb9bih5.Nexus.local...
> Wolfgang wrote:
>> I just started playing around with Triggers and am not certain,
>> whether I am missing something or not.
>>
>> It seems, that the UPDATE Trigger only kicks in, if the changed
>> column is "not null", but has a value already?
>>
>> Kind Regards Wolfgang

>
> Nulls won't play well with your conditions.
> Use NOT EQUIVALENT(A,B) instead of A <> B.
>
> --
> Brian Evans [NDX]
> Ottawa, ON, CANADA
> GMT-5





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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Performance of Triggers Jesper Østergaard nexusdb.public.support.sql 0 5th December 2006 02:27 AM
Triggers Ken Randall nexusdb.public.support.sql 6 2nd August 2006 12:46 AM
Triggers Revisited Ken Randall nexusdb.public.support.sql 2 23rd October 2005 01:41 AM
Triggers Ken Randall nexusdb.public.support.sql 4 20th October 2005 04:57 AM
Procedures and Triggers Mark Clark nexusdb.public.support.sql 2 13th October 2005 04:38 PM


All times are GMT +11. The time now is 02:51 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.