4D v13.4SQL EXECUTE |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v13.4
SQL EXECUTE
SQL EXECUTE
The SQL EXECUTE command executes an SQL command and binds the result to 4D objects (arrays, variables or fields). A valid connection must be specified in the current process in order to execute this command. The sqlStatement parameter contains the SQL command to execute. boundObj receives the results. Variables are bound in the column sequence order, which means that any remaining remote columns are discarded. If 4D fields are passed as parameters in boundObj, the command will create records and save them automatically. 4D fields must come from the same table (a field from table 1 and a field from table 2 cannot be passed in the same call). If fields from more than one table are passed, an error is generated. Warning: When you pass 4D fields in the boundObj parameter(s) and execute the SELECT command, it is always the data of the remote 4D source that is modified. If you want to retrieve data from the remote source locally, you must use intermediary local arrays and call the INSERT command (see example 6). If you pass 4D arrays in the boundObj parameter(s), it is advisable to declare them before calling the command in order to check the type of data processed. Arrays are automatically resized when necessary. With a 4D variable, one record is fetched at a time. The other results are ignored. Note: For more information about referencing 4D expressions in SQL queries, refer to the Overview of SQL Commands section. In this example, we will get the ename column of the emp table of the data source. The result is stored in the [Employee]Name 4D field. 4D records will be created automatically: SQLStmt:="SELECT ename FROM emp" To check the creation of records, it is possible to include code within a transaction and to validate it only if the operation proves to be satisfactory: SQL LOGIN("mysql";"root";"") In this example, we want to get the ename column of the emp table of the data source. The result will be stored in an aName array. We fetch records 10 at a time. ARRAY STRING(30;aName;20) In this example, we want to get the ename and job of the emp table for a specific ID (WHERE clause) of the data source. The result will be stored in the vName and vJob 4D variables. Only the first record is fetched. SQLStmt:="SELECT ename, job FROM emp WHERE id = 3" In this example, we want to get the Blob_Field column of the Test table in the data source. The result will be stored in a BLOB variable whose value is updated each time a record is loaded. C_BLOB(MyBlob) You want to retrieve data locally from a remote 4D Server database where it is stored. To do this, you must use intermediary arrays: // Log in to the remote database If the command has been executed correctly, the system variable OK returns 1. Otherwise, it returns 0. |
PROPERTIES
Product: 4D
INDEX HISTORY
Created: 4D 2004 SEE ALSO |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||