version 11.2 (Modified)
With 4D Server, you now have three situations in which you can execute 4D code on the server machine:
Triggers
Stored procedures
Project methods with the "Execute on Server" attribute
Database methods
Triggers
A Trigger is a method attached to a table. Triggers can prevent "illegal" operations on your database records. They are a very powerful tool to restrict operations on a table, as well as to preventaccidental data loss or tampering. For example, in an invoicing system, you can prevent anyone from adding an invoice without specifying the customer to whom the invoice is billed.
Triggers are executed on the machine where the database engine is actually located.
With 4D Server, triggers are executed within the context of processes running on the server machine, and not on the client machine. More specifically, they are executed in the context of the "twinned" processes of the user processes that call the database operation. These twinned processes share the database context with the user process on the client machine (in particular, the state of transactions and the locking of records) but do not share the language context (variables, processes, sets, current selections). Note however that the current record of the table of the trigger is the same in all contexts.
For more information about triggers, see the section Triggers of the 4D Language Reference manual.
Stored Procedures
A 4D stored procedure is project method executing a process method in a process running on the server machine (or on any client machine), instead of on the client machine which has launched the method. See the Stored Procedures section.
Methods with the "Execute on Server" attribute
Project methods that have the "Execute on Server" attribute are also executed on the server. However, unlike stored procedures, they are executed in the "twinned" process of the client process and thus benefit from its database context, like with triggers. For more information, please refer to the Execute on Server attribute section.
Database Methods
Four database methods are executed only on the server machine:
On Server Startup Database Method
On Server Shutdown Database Method
On Server Open Connection Database Method
On Server Close Connection Database Method
Five other database methods can be executed either on the server machine or a client machine depending on the context:
On Web Authentication Database Method
On Web Connection Database Method
On SQL Authentication Database Method
On Backup Startup Database Method
On Backup Shutdown Database Method
Three database methods can only be executed on a client machine:
See the corresponding sections in this manual and in the 4D Language Reference manual for more information on the database methods.
4D Server and Variables
4D Server maintains one table of interprocess variables. The scope of these variables is the server machine. When running a compiled database, the interprocess variable table definition is common between the server and all the clients machines, each machine having its own instance.
Like all processes, each stored procedure, database method and trigger has its own table of process variables. These process variables can be created and used dynamically during each phase of execution.
4D Server, Sets and Named Selections
With 4D Server, the visibility of sets and named selections depends on where they were created (server process or client process) and the type of these objects (local, process or interprocess objects). For more information, see the 4D Server, Sets and Named Selections section.