base.SqlHandle.setParameter

Sets the value of an SQL parameter for this SQL handle.

Syntax

setParameter(
   index INTEGER,
   value primitive-type )
  1. index is the ordinal position of the ? SQL parameter (starts at 1).
  2. value is the variable containing the parameter value.
  3. primitive-type is any of the primitive types that can be used in SQL statements.

Usage

Call the setParameter() method to define the value of an SQL parameter specified with a ? place holder in the string passed to the prepare() method.

The SQL statement must have been prepared with a prepare() call.

The method will raise error -8131, if the index passed as parameter is lower than 1 or greater than the number of ? parameter placeholders in the prepared SQL statement.

The type of an SQL parameter is important and must match the type of the target SQL column. After prepare(), if setParameterType() is not used, the type of the SQL parameter is defined by the expression passed to any setParameter() call. However, it is also possible to pre-define the type of an SQL parameter with the setParameterType() method. When calling setParameter() with strings representing the actual values, it is mandatory to define the real type with setParameterType(), to avoid any SQL type conversion issues. Once the type is defined by setParameterType(), the same type conversion rules apply as with a LET variable = string instruction.

Example

DEFINE sh base.SqlHandle
DEFINE v_pk INT, v_crea DATETIME YEAR TO SECOND
...
CALL sh.setParameter(1,v_pk)
CALL sh.setParameter(2,v_crea)

For a complete example, see Example 1: SqlHandle with simple SQL.