4D v14

Execute on Server attribute

Home

 
4D v14
Execute on Server attribute

Execute on Server attribute  


 

 

The "Execute on Server" project method attribute can be set using the batch setting of attributes dialog box as well as the Method Properties dialog box:

When this option is checked, the project method is always executed on the server, regardless of how it is called.

Note: This attribute is only taken into account for a 4D application in client/server mode.

When this attribute is checked, the execution context of the project method is comparable to that of triggers (see 4D Server and the 4D Language): the method on the server shares the same database context as the corresponding context on the client side for locking records and for transactions, but not the same language context (process variables, sets, current selections). However, unlike a trigger, a method executed on the server does not share the current record with the client context.
All the parameters of the method ($1, $2, etc.) are sent to the server and the value of parameter $0, if used, is returned to the client.

Unlike the Execute on server command, this option does not create a process on the server. 4D Server uses the "twin" process of the client process that requested the execution.
Moreover, this option simplifies the principle of delegating the execution of a method on the server since the transfer of parameters is automatically carried out in both directions, as with a "normal" method call.
The Execute on server command functions asynchronously, therefore it requires more programming and makes use of semaphores for reading the results.

Methods that have the "Execute on Server" attribute are subject to the same rules as the stored procedures as far as the use of 4D language commands is concerned. Executing certain commands is not allowed on the server, executing others is not recommended. For more information, please refer to the "What a stored procedure does not do (executed on the server)?" paragraph in the Stored Procedures section.

If you pass a pointer to a variable (simple variable, array or array element), the pointed value is also sent to the server. If the pointed value is modified on the server by the method, the modified value is returned to the client in order to update the corresponding variable on the client side.
Pointers to a table or field are sent as references (table number, field number). The current record value is not automatically exchanged.

Note: This option works the same way in interpreted mode as in compiled mode.

Example  

Here is the code for the Myappli project method which has the "Execute on Server" attribute:

 C_POINTER($1`Pointer to table
 C_POINTER($2`Pointer to field
 C_POINTER($3`Pointer to array
 C_TEXT($4`Value to be searched for
 C_LONGINT($0`Result
 
  `Search and send back values for each record
 QUERY($1->;$2->=$4)
 While(Not(End selection($1->)))
    APPEND TO ARRAY($3->;myFormula($1))
    NEXT RECORD($1->)
 End while
 UNLOAD RECORD($1->)
 $0:=Records in selection($1->)

On the client side, the method is called as follows:

 ARRAY TEXT(myArray;0)
 $vlnum :=MyAppli(->[Table_1] ;->[Table_1]Field_1 ;->myArray;"to find")

 
PROPERTIES 

Product: 4D
Theme: 4D Server and the 4D Language

 
ARTICLE USAGE

4D Server Reference ( 4D v13)
4D Server Reference ( 4D Server v12)
4D Server Reference ( 4D v14 R2)
4D Server Reference ( 4D v14)
4D Server Reference ( 4D v14 R3)
4D Server Reference ( 4D Server v14 R4)

Parent of : Execute on Server attribute ( 4D Server v11 SQL Release 6)