Firebird create a context variable

For DELETE and UPDATE i use the context variable "old", and for INSERT i have to use the "new" context variable.

I want to use only ONE trigger for INSERT, UPDATE and DELETE because its easier to mantain it later, and my problem ist that i look for a way to use only one variable for acessing the values from "old" and "new" context variable. Also, if INSERT then i have to use the values from "new" else from "old". But i dondt want to use the both on the same procedure.

Hou can i create a variable and assing the "new" if INSERTING and otherwise the "old" context variable?

CREATE TRIGGER TEST_ FOR TEST ACTIVE AFTER INSERT OR UPDATE OR DELETE POSITION 0 AS
DECLARE VARIABLE CONTEXTVAR VARCHAR(10);
begin
IF (INSERTING) THEN
CONTEXTVAR = NEW.LINK; <-------
ELSE IF (UPDATING) THEN
CONTEXTVAR = OLD.LINK; could be either, depending upon which you want to use
ELSE // (DELETING)
CONTEXTVAR = OLD.LINK;
// REST OF CODE
end

I don't think firebird 2 will allow references to invalid context variables for the trigger defn, If I'm right the above will not be allowed in any trigger as eg, a delete trigger doesn't allow code that refers to a new.field

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

I understand what you are trying to do but since there are no object or array datatypes available to declare in PSQL it isn't possible. Nickupsons last suggestion is the only alternative and it will work but I'm not sure it will achieve your goal of writing simpler code.

Featured Post

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!

Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…