PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Overview
  • Creating server triggers in the analysis
  • Prerequisite
  • Taking the server triggers into account
  • Stored procedures linked to a trigger
  • Running the test of a stored procedure called by a trigger
  • Handling the server triggers by programming
  • The WLanguage functions
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Server triggers
HFSQL Client/ServerAvailable only with this kind of connection
Overview
The server triggers are stored procedures run by the server before or after a write operation performed on a database file.
As for the standard triggers, two types of server triggers are available:
  • The "BEFORE" triggers:
    A "BEFORE" trigger is called:
    • before running a HFSQL function (HAdd, HModify, HDelete, ...).
    • before running a function for managing the browsing tables.
      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, a 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 a HFSQL function (except if the program was interrupted during the execution of this function).
    • after the execution of a function for managing the browsing tables.
      An "AFTER" trigger can be used to manage the process of errors for example.
Characteristics of server triggers:
  • Several server triggers can be associated with the same file.
  • The triggers being defined on the server, they are taken into account regardless of the client application run. Any new trigger defined on the server is automatically taken into account.
  • The server triggers are run:
Note: From version 19, HFSQL is the new name of HyperFileSQL.
Creating server triggers in the analysis

Prerequisite

To create a server trigger:
  • select "Insert .. Trigger".on the "Analysis" pane, in the "Creation" group, expand "New" and select "Trigger".
  • select "New trigger" from the popup menu of the dockable "Analysis" pane.
  • display the "HF triggers" tab of the description window of the file and click the "Create a new trigger" button.
These different options display the description window of the server trigger.
The description window of a trigger is used to specify:
  • the name of the trigger.
  • the stored WLanguage procedure that is associated with the trigger.
  • the mode for releasing the trigger (BEFORE or AFTER the execution of the HFSQL functions).
  • the HFSQL functions that will release the trigger.
  • the data files associated with the trigger.
Note: The created triggers are visible:
  • in the analysis pane.
  • in the analysis graph directly: if a server trigger is associated with a file, a specific icon is displayed: .

Taking the server triggers into account

The server triggers created in the analysis are created on the server:
The triggers installed on the server will be automatically taken into account by the client applications.

Stored procedures linked to a trigger

A "trigger" stored procedure accepts no parameter. However, some HFSQL state variables are positioned before each call:
H.FileNameCharacter string: Logical name of the file whose trigger is enabled
H.ActionCharacter initialized to "A" for a Before trigger and to "P" for an After trigger.
H.TriggerFunctionCharacter string: Name of the HFSQL function that activated the trigger
H.ToDoDuring the execution of a before trigger:
  • cancel the execution of the HFSQL function by assigning "A" to the HFSQL state variable: H.ToDo = "A". In this case, the action is not performed and the function (HAdd, HModify, ...) returns True (no error).
  • cancel the execution of the current HFSQL function by assigning "E" to the HFSQL state variable: H.ToDo = "E". In this case, the action is not performed and the function (HAdd, HModify, ...) returns False. The error message is as follows: "The action on XXX file was interrupted by the trigger".
Notes:
  • When a "BEFORE" trigger and an "AFTER" trigger are associated with a HFSQL function, if the "BEFORE" trigger cancels the execution of the HFSQL function (by setting h.ToDo to "A"), the "AFTER" trigger is not run.
  • The MyFile keyword is used to find out and handle, in the code of the stored procedure, the name of the file on which the trigger was activated.
Important: In order for a stored procedure started from a server trigger to access the data, you must use HDeclareExternal. This function allows you to declare the data sources that will be used in processes of the stored procedure.
Indeed, when a stored procedure is started from the HFSQL Control Center, there is no current analysis: the HFSQL Client/Server data is not immediately accessible.
If HDeclareExternal is not used in the code of the stored procedure, the procedure will trigger a fatal error, notified in the log of system events.

Running the test of a stored procedure called by a trigger

To run the test of a stored procedure:
  1. In the analysis pane, select the stored procedure whose test must be run.
  2. Select "Run the procedure test" from the popup menu of the stored procedure.
  3. The window for entering the parameters of the procedure is displayed. This window allows you to:
    • Enter the parameters of the procedure.
    • Run the test of the procedure.
      Note: this window can be used to restart the execution several times by modifying the parameters.
  4. When the test of the procedure is run:
    • An update of the stored procedure is proposed if necessary.
    • The procedure is started on the server.
    • The return value of the procedure is displayed if necessary.
Notes/limitations:
  • The debugging port is port 27281 by default. This port must be opened in the firewall. This port can be modified in the HFConf.ini file.
  • To run the test of a stored procedure, you must have the debugging rights on the database.
  • The traces used in the stored procedures are displayed in the "Trace of debugger" pane.
  • The code of the stored procedure can contain breakpoints: the debugger will be started.
  • The elements deployed on the server are used during the test.
  • InTestMode returns True.
Handling the server triggers by programming

The WLanguage functions

Several functions are used to handle the server triggers:
Versions 12 and later
HActivateServerTrigger
New in version 12
HActivateServerTrigger
HActivateServerTrigger
Re-enables a server trigger that was disabled by HDeactivateServerTrigger.
Versions 15 and later
HCreateServerTrigger
New in version 15
HCreateServerTrigger
HCreateServerTrigger
Adds or modifies a server trigger on the HFSQL server.
Versions 12 and later
HDeactivateServerTrigger
New in version 12
HDeactivateServerTrigger
HDeactivateServerTrigger
Disables a HFSQL Client/Server server trigger on a server.
Versions 12 and later
HDeleteServerTrigger
New in version 12
HDeleteServerTrigger
HDeleteServerTrigger
Destroys a server trigger.
Versions 12 and later
HDescribeServerTrigger
New in version 12
HDescribeServerTrigger
HDescribeServerTrigger
Adds or modifies a server trigger.
Versions 12 and later
HListServerTrigger
New in version 12
HListServerTrigger
HListServerTrigger
Lists the different triggers available on a connection or on one of the connection files.
These functions are advanced functions.
Related Examples:
WD Server trigger Training (WINDEV): WD Server trigger
[ + ] This example explains how to use the server triggers.
The server triggers are run on the server whenever adding/modifying/deleting records.
Minimum required version
  • Version 11
This page is also available for…
Comments
Click [Add] to post a comment