The WhysSql Template allows users to easily print notices, warnings, and errors, as well as a trigger execution trace. This provides visibility into the workings of the code, allowing the user to identify any issues and where they occur. Additionally, an error terminates the script execution.
Code:
-- notice, warning, error.
INSERT INTO Whys_Print(Type, Message) SELECT 0, 'This is a notice.';
INSERT INTO Whys_Print(Type, Message) SELECT 1, 'This is a warning.';
INSERT INTO Whys_Print(Type, Message) SELECT -1, 'This is an error.'; -- terminates script.
Output to the print table automatically includes a timestamp, the mod, and the file from where the print occurred.
The trace output is indented according to the execution depth of the triggers, allowing the user to easily identify the source of the output and in what order the triggers were executed. In the example below, note the trigger named
WhysResoHarvCtrl_BEF_INS_WhysResoHarvCtrl_Conv. This trigger occurs
before an item is inserted into the table named WhysResoHarvCtrl_Conv. Within that trigger, six additional triggers are executed. Once complete, it is then followed by
WhysResoHarvCtrl_AFT_INS_WhysResoHarvCtrl_Conv. That trigger occurs
after the item is inserted, completing the process.
Notices and warnings can be disabled for specific triggers, both for your own mod and any other mod that uses the WhysSql Template.
Code:
-- disable in all triggers.
UPDATE Whys_Trig SET DoNotice = 0, DoWarning = 0;
-- disable in all triggers of a mod.
UPDATE Whys_Trig SET DoNotice = 0, DoWarning = 0
WHERE Mod IS 'AnyMod';
-- disable in all triggers of a file.
UPDATE Whys_Trig SET DoNotice = 0, DoWarning = 0
WHERE File IS 'AnyFile';
-- disable in named trigger.
UPDATE Whys_Trig SET DoNotice = 0, DoWarning = 0
WHERE Name IS 'AnyTrigger';
While the trace itself can not be disabled, the output of any contents of specified triggers can be truncated. Truncated triggers identify themselves as "[truncated]" in their trace output and will not display any notices, warnings, or traces from within the truncated trigger. In the following example, note the trigger
WhysResoHarvCtrl_BEF_INS_WhysResoHarvCtrl_Conv from the earlier example. The six inner triggers are now hidden.
Code:
-- truncate output.
UPDATE Whys_Trig SET DoOutput = 0
WHERE Name IS 'WhysResoHarvCtrl_BEF_INS_WhysResoHarvCtrl_Conv';
Output can also be made dependent on the current debug mode, allowing it to be hidden except when debugging.
Code:
-- notice on debug.
INSERT INTO Whys_Print(Type, Message) SELECT 0, 'This is a debugging notice.'
WHERE (SELECT Debug FROM Whys_Run) >= 1;
Top