Subject | CASE Statement annidation |
---|---|
Author | achiadodespammed |
Post date | 2004-06-11T11:40:48Z |
Hi all,
I'm trying to write a trigger that log to a table all user operations.
So I write someting like this:
CREATE TRIGGER table1_log FOR table1
ACTIVE AFTER INSERT OR UPDATE OR DELETE POSITION 0
AS
BEGIN
IF (USER <> 'REPL') THEN BEGIN
INSERT INTO table_log(utente, tipo, tabella, istruzione)
VALUES (USER,
case
when (inserting) then 'I'
when (updating) then 'U'
when (deleting) then 'D'
end,
'TABLE1',
case
when (inserting) then
'INSERT INTO table1 (
fieldkey,
field1,
field2)
VALUES
('||new.fieldkey||','||new.field1||','||new.field2||')'
when (updating) then
'UPDATE table1 SET fieldkey='||new.fieldkey
|| case when (new.field1#old.field1) then
',field1='||new.field1|| end
|| case when (new.field2#old.field2) then
',field2='||new.field2|| end
|| ' WHERE fieldkey=old.fieldkey'
when (deleting) then
'DELETE FROM table1 WHERE fieldkey=old.fieldkey'
end);END
end
but in the (updating) CASE, when I try to insert another CASE IBExpert
return a precompiler error.
My question is:
It is possible to annidiate CASE statement? If not how can I write my
trigger to obtain same result?
Thank you
Ciao
Andrea Chiado' Piat
I'm trying to write a trigger that log to a table all user operations.
So I write someting like this:
CREATE TRIGGER table1_log FOR table1
ACTIVE AFTER INSERT OR UPDATE OR DELETE POSITION 0
AS
BEGIN
IF (USER <> 'REPL') THEN BEGIN
INSERT INTO table_log(utente, tipo, tabella, istruzione)
VALUES (USER,
case
when (inserting) then 'I'
when (updating) then 'U'
when (deleting) then 'D'
end,
'TABLE1',
case
when (inserting) then
'INSERT INTO table1 (
fieldkey,
field1,
field2)
VALUES
('||new.fieldkey||','||new.field1||','||new.field2||')'
when (updating) then
'UPDATE table1 SET fieldkey='||new.fieldkey
|| case when (new.field1#old.field1) then
',field1='||new.field1|| end
|| case when (new.field2#old.field2) then
',field2='||new.field2|| end
|| ' WHERE fieldkey=old.fieldkey'
when (deleting) then
'DELETE FROM table1 WHERE fieldkey=old.fieldkey'
end);END
end
but in the (updating) CASE, when I try to insert another CASE IBExpert
return a precompiler error.
My question is:
It is possible to annidiate CASE statement? If not how can I write my
trigger to obtain same result?
Thank you
Ciao
Andrea Chiado' Piat