|
|
|
|
|
- What is a trigger?
- Definition
- Available types of triggers
- Handling the triggers programmatically
- The WLanguage functions
- Creating a trigger
- Creating a procedure run by a trigger
- Automated tests and triggers
- Triggers and data file aliases
Definition A trigger is a WLanguage procedure called automatically by the HFSQL engine each time a record in a data file is modified (added, deleted, edited, etc.).s A trigger can be used to associate a WLanguage processing operation with one or more HFSQL functions ( HAdd, HModify, HDelete, etc.) without having to worry about the location of these functions in the source code. The triggers associated with the HFSQL functions used are run even if it is a window or a code created by a wizard. Using a trigger allows you to: - Reduce the code size. For example, processing associated with one or more HFSQL functions (duplicate check, data consistency test, etc.) can be grouped together using a trigger.r
- Make the code easier to read.
- Simplify the future evolutions of the application.
The triggers can be applied to all types of data files: - HFSQL
- Native Access (Oracle, AS/400, etc.)
- ODBC
- OLE DB
Remarks: - With an HFSQL Client/Server database, you also have the ability to define server triggers. For more details, see Server triggers.
- When data files are modified via a query, server triggers, simple triggers or client triggers are fired.
Available types of triggers Two types of triggers are available: - The "BEFORE" triggers:
A "BEFORE" trigger is called: - before execution of an HFSQL function (HAdd, HModify, HDelete, etc.)..
- before running a function for managing the Table controls based on a data file.
A "BEFORE" trigger can be used for example to check the consistency of data for the items of a record. With this type of trigger, an HFSQL variable can be initialized in order to cancel the execution of the associated HFSQL function.
- The "AFTER" triggers:
An "AFTER" trigger is called: - after running an HFSQL function (except if the program was interrupted during the execution of this function).
- after running a function for managing the Table controls based on a data file.
An "AFTER" trigger can be used to manage the process of errors for example.
Handling the triggers programmatically The WLanguage functions Several WLanguage functions are used to handle the triggers:
Creating a trigger To create a "BEFORE" trigger or an "AFTER" trigger, use HDescribeTrigger in the initialization process of the project. The trigger can be created: The associated WLanguage procedure is run whenever a trigger is run. Note A trigger is global to the project.t Creating a procedure run by a trigger In the procedure code, the MyFile keyword gets and handles the name of the file on which the trigger was fired. For an "AFTER" trigger, if the HFSQL command was not run properly, the procedure associated with the trigger is not run. Automated tests and triggers If automation tests trigger triggers using dialog boxes (functions YesNo, Confirm, etc.), it is necessary to disable these dialog boxes during test execution using function InAutomaticTestMode. Triggers and data file aliases Triggers can be defined on data file aliases.
Related Examples:
|
Training (WINDEV): WD Trigger
[ + ] This example explains how to use the triggers with WINDEV. A trigger is a WLanguage procedure automatically called by the HFSQL engine whenever a HFSQL function is run. The following topics are presented in this example: 1/ how to branch a trigger on a HFSQL function 2/ the code that must be used in the function called by trigger. Summary of the example supplied with WINDEV: This application is used to enter the expenses for the contributors of a company. Two modes can be used: - the mode with read/write rights - the mode with read-only rights. The triggers will be used to control the access to the files according to the current mode. In this example, the triggers are also used to write the different events into a log file. This log file can be directly consulted in the application.
|
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|