version 2004
ODBC SET PARAMETER (object; paramType)
Parameter | Type | Description | |
object | 4D object | 4D object to be used (variable, array or field) | |
paramType | Longint | Type of parameter |
Description
The ODBC SET PARAMETER command allows the use of a 4D variable, array or field value in ODBC requests.
Note: It is also possible to directly insert the name of a 4D object to be used (variable, array or field) between the << and >> characters in the text of the request (see example 1). For more information about this, please refer to the External Data Source Commands section.
- In the object parameter, pass the 4D object (variable, array or field) to be used in the request.
- In the paramType parameter, pass the SQL type of the parameter. You can pass a value or use one of the following constants, located in the "External Data Source" theme:
Constant | Type | Value |
OBDC Param In | Longint | 1 |
OBDC Param In Out | Longint | 2 |
OBDC Param Out | Longint | 4 |
The value of the 4D object replaces the ? character in the SQL request (standard syntax).
If the request contains more than one ? character, several calls to ODBC SET PARAMETER will be necessary. The values of the 4D objects will be assigned sequentially in the request, in accordance with the execution order of the commands.
Examples
1. This example is used to execute an ODBC request which calls the associated 4D variables directly:
C_TEXT(MyText) C_LONGINT(MyLongint) ODBC LOGIN("mysql";"root";"") SQLStmt:="insert into app_testTable (alpha_field, longint_field) VALUES (<<MyText>>, <<MyLongint>>)" For (vCounter;1;10) MyText:="Text"+String(vCounter) MyLongint:=vCounter ODBC EXECUTE(SQLStmt) End for
2. Same example as the previous one, but using the ODBC SET PARAMETER command:
C_TEXT(MyText) C_LONGINT(MyLongint) ODBC LOGIN("mysql";"root";"") SQLStmt:="insert into app_testTable (alpha_field, longint_field) VALUES (?,?)" For (vCounter;1;10) MyText:="Text"+String(vCounter) MyLongint:=vCounter ODBC SET PARAMETER(MyText;ODBC Param In) ODBC SET PARAMETER(MyLongint;ODBC Param In) ODBC EXECUTE(SQLStmt) End for
3. This example is used to execute an ODBC request which uses the associated 4D arrays directly:
ARRAY TEXT(MyTextArray;10) ARRAY LONGINT(MyLongintArray;10) For (vCounter;1;Size of array(MyTextArray)) MyTextArray{vCounter}:="Text"+String(vCounter) MyLongintArray{vCounter}:=vCounter End for ODBC LOGIN("mysql";"root";"") SQLStmt:="insert into app_testTable (alpha_field, longint_field) VALUES (<<MyTextArray>>, <<MyLongintArray>>)" ODBC EXECUTE(SQLStmt)
4. This example is used to execute an ODBC request which uses the associated 4D fields directly:
ALL RECORDS([Table 2]) ODBC LOGIN("mysql";"root";"") SQLStmt:="insert into app_testTable (alpha_field, longint_field) VALUES (<<[Table 2]Field1>"+">, <<[Table 2]Field2>>)" ODBC EXECUTE(SQLStmt)
System Variables or Sets
If the command has been executed correctly, the system variable OK returns 1. Otherwise, it returns 0.