Subject | Auditing updates |
---|---|
Author | David K. Trudgett |
Post date | 2002-02-11T04:58:06Z |
I've just put the following code into a before update trigger, for the
purpose of recording updates to a column value:
IF (OLD.mast_Column_Name IS NULL OR
NEW.mast_Column_Name IS NULL) THEN
BEGIN
IF ((OLD.mast_Column_Name IS NULL AND
NEW.mast_Column_Name IS NOT NULL) OR
(OLD.mast_Column_Name IS NOT NULL AND
NEW.mast_Column_Name IS NULL)) THEN
EXECUTE PROCEDURE Audit_The_Change(parameters, ...);
END
ELSE IF (OLD.mast_Column_Name <> NEW.mast_Column_Name) THEN
EXECUTE PROCEDURE Audit_The_Change(parameters, ...);
This seems a bit long-winded to me, especially if similar code needs
to be repeated for thirty columns. I originally just wanted to write:
IF (OLD.mast_Column_Name <> NEW.mast_Column_Name) THEN
EXECUTE PROCEDURE Audit_The_Change(parameters, ...);
but then I remembered the problem of comparison with NULL.
Does anyone know a better way?
David Trudgett
purpose of recording updates to a column value:
IF (OLD.mast_Column_Name IS NULL OR
NEW.mast_Column_Name IS NULL) THEN
BEGIN
IF ((OLD.mast_Column_Name IS NULL AND
NEW.mast_Column_Name IS NOT NULL) OR
(OLD.mast_Column_Name IS NOT NULL AND
NEW.mast_Column_Name IS NULL)) THEN
EXECUTE PROCEDURE Audit_The_Change(parameters, ...);
END
ELSE IF (OLD.mast_Column_Name <> NEW.mast_Column_Name) THEN
EXECUTE PROCEDURE Audit_The_Change(parameters, ...);
This seems a bit long-winded to me, especially if similar code needs
to be repeated for thirty columns. I originally just wanted to write:
IF (OLD.mast_Column_Name <> NEW.mast_Column_Name) THEN
EXECUTE PROCEDURE Audit_The_Change(parameters, ...);
but then I remembered the problem of comparison with NULL.
Does anyone know a better way?
David Trudgett