Consultor Eletrônico



Kbase 20589: How to Programmatically Disable 4GL Schema Triggers before doing bulk maintenance to data?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   4/1/2008
Status: Unverified

GOAL:

How to Programmatically Disable 4GL Schema Triggers before doing bulk maintenance to data?

GOAL:

Disabling Database triggers before bulk programmatically

FACT(s) (Environment):

Progress 8.x
Progress 9.x

FIX:

To override or disable all 4GL database schema triggers, even if you do not know their directory locations, you must first find the triggers of interest, rename them, and replace them with " empty " triggers that do nothing.

After you finish your data messaging task, you might need to restore the original genuine triggers and, optionally, delete their " empty " copies that are generated during this process.

The following example assumes that you need to disable all the 4GL DELETE triggers for all the tables in your database. Follow these steps:

1) Disable the delete triggers.

Before starting to message your data, run the DisableAllDeleteTriggers.p procedure that locates and renames all the DELETE schema triggers, and creates empty ones to replace them under the original names in the original directories:

/*****************Procedure DisableAllDeleteTriggers.p**********/

DEFINE VARIABLE GenuineTriggerName AS CHARACTER NO-UNDO FORMAT "X(60)".
DEFINE VARIABLE GenuineTriggerReNamed AS CHARACTER NO-UNDO FORMAT "X(60)".

FOR EACH _File NO-LOCK,
EACH _File-trig OF _File WHERE _File-trig._Event = "DELETE" NO-LOCK:

/*** Rename all the genuine original triggers ***/
FILE-INFO:FILE-NAME = _proc-name.
ASSIGN GenuineTriggerName = FILE-INFO:FULL-PATHNAME
GenuineTriggerReNamed = GenuineTriggerName + "x".
OS-RENAME VALUE(GenuineTriggerName) VALUE(GenuineTriggerReNamed).

/*** Replace original triggers with empty ones ***/
OUTPUT TO VALUE(GenuineTriggerName).
PUT "TRIGGER PROCEDURE FOR Delete OF " + _File._File-Name + "." FORMAT "X(80)".
OUTPUT CLOSE.
END.

/**************End of Procedure DisableAllDeleteTriggers.p********/
NOTE: After overwriting the original triggers, make sure to overwrite their original R-Code by compiling the new empty triggers.
2) Restore the original delete triggers.

When you are satisfied that your data massaging task is complete and satisfactory, run the RestoreAllDeleteTriggers.p procedure that restores all the genuine DELETE schema triggers to original state:

/*****************Procedure RestoreAllDeleteTriggers.p**********/

DEFINE VARIABLE GenuineTriggerName AS CHARACTER NO-UNDO FORMAT "X(60)".
DEFINE VARIABLE GenuineTriggerReNamed AS CHARACTER NO-UNDO FORMAT "X(60)".
DEFINE VARIABLE TheEmptyTriggerName AS CHARACTER NO-UNDO FORMAT "X(60)".

FOR EACH _File NO-LOCK,
EACH _File-trig OF _File WHERE _File-trig._Event = "DELETE" NO-LOCK:

ASSIGN FILE-INFO:FILE-NAME = _proc-name
GenuineTriggerName = FILE-INFO:FULL-PATHNAME
GenuineTriggerReNamed = GenuineTriggerName + "x".
OS-COPY VALUE(GenuineTriggerReNamed) VALUE(GenuineTriggerName).
END.

/***************End of Procedure RstoreAllDeleteTriggers.p********/
NOTE: After restoring the original triggers, make sure to restore their original R-Code by recompiling the original triggers.
3) Restore the original delete triggers and remove their copies.

If you are sure that you do not need the extra copies of the original DELETE triggers that were generated in Step 1, you can optionally run the RestoreAllDeleteTriggersAndClean.p procedure that not only restores the genuine DELETE procedures to their original. state, but deletes all their copies that were generated by the DisableAllDeleteTriggers.p procedure above:

/*********Procedure RestoreAllDeleteTriggersAndClean.p**********/

DEFINE VARIABLE GenuineTriggerName AS CHARACTER NO-UNDO FORMAT "X(60)".
DEFINE VARIABLE GenuineTriggerReNamed AS CHARACTER NO-UNDO FORMAT "X(60)".
DEFINE VARIABLE TheEmptyTriggerName AS CHARACTER NO-UNDO FORMAT "X(60)".

FOR EACH _File NO-LOCK,
EACH _File-trig OF _File WHERE _File-trig._Event = "DELETE" NO-LOCK:

ASSIGN FILE-INFO:FILE-NAME = _proc-name
GenuineTriggerName = FILE-INFO:FULL-PATHNAME
GenuineTriggerReNamed = GenuineTriggerName + "x".
OS-COPY VALUE(GenuineTriggerReNamed) VALUE(GenuineTriggerName).
OS-DELETE VALUE(GenuineTriggerReNamed).
END.

/*******End of Procedure RestoreAllDeleteTriggersAndClean********/
.