SQLBindParam - Bind a buffer to a parameter marker
SQLBindParam() has been deprecated and replaced by SQLBindParameter(). Although this version of DB2® for i CLI continues to support SQLBindParam(), it is recommended that you begin using SQLBindParameter() in your DB2 for i CLI programs so that they conform to the latest standards.
SQLBindParam() binds an application variable to a parameter marker in an SQL statement. This function can also be used to bind an application variable to a parameter of a stored procedure CALL statement where the parameter can be input or output.
Syntax
SQLRETURN SQLBindParam (SQLHSTMT hstmt,
SQLSMALLINT ipar,
SQLSMALLINT fCType,
SQLSMALLINT fSqlType,
SQLINTEGER cbParamDef,
SQLSMALLINT ibScale,
SQLPOINTER rgbValue,
SQLINTEGER *pcbValue);
Function arguments
Data type | Argument | Use | Description |
---|---|---|---|
SQLHSTMT | hstmt | Input | Statement handle. |
SQLSMALLINT | ipar | Input | Parameter marker number, ordered sequentially left to right, starting at 1. |
SQLSMALLINT | fCType | Input | Application data type of the parameter. The
following types are supported:
Specifying SQL_DEFAULT causes data to be transferred from its default application data type to the type indicated in fSqlType. |
SQLSMALLINT | fSqlType | Input | SQL data
type of the parameter. The supported
types are:
|
SQLINTEGER | cbParamDef | Input | Precision
of the corresponding parameter marker.
|
SQLSMALLINT | ibScale | Input | Scale of the corresponding parameter if fSqlType is
SQL_DECIMAL or SQL_NUMERIC. If fSqlType is SQL_TIMESTAMP,
this is the number of digits to the right of the decimal point in
the character representation of a timestamp (for example, the scale
of yyyy-mm-dd hh:mm:ss.fff is 3). Other than for the fSqlType values mentioned here, ibScale is unused. |
SQLPOINTER | rgbValue | Input (deferred) |
At processing
time, if pcbValue does
not contain SQL_NULL_DATA or SQL_DATA_AT_EXEC, then rgbValue points
to a buffer that contains the actual data for the parameter. If pcbValue contains SQL_DATA_AT_EXEC, then rgbValue is an application-defined 32-bit value that is associated with this parameter. This 32-bit value is returned to the application through a later SQLParamData() call. |
SQLINTEGER * | pcbValue | Input (deferred), or output (deferred), or both | A variable whose
value is interpreted
when the statement is processed:
|
Usage
When SQLBindParam() is used to bind an application variable to an output parameter for a stored procedure, DB2 for i CLI provides some performance enhancement if the rgbValue buffer is placed consecutively in memory after the pcbValue buffer.
For decimal floating point data types, a precision of 32, 64, or 128 can be specified by using the default symbolic C data type constants. For example, to specify a decimal floating point data type with a precision of 128 bytes, fCType can be set to SQL_C_DECIMAL128.
Return codes
- SQL_SUCCESS
- SQL_SUCCESS_WITH_INFO
- SQL_ERROR
- SQL_INVALID_HANDLE
Diagnostics
SQLSTATE | Description | Explanation |
---|---|---|
07006 | Restricted data type attribute violation | Same as SQLSetParam(). |
40003 * | Statement completion unknown | The communication link between the CLI and the data source fails before the function completes processing. |
58004 | System error | Unrecoverable system error. |
HY001 | Memory allocation failure | The driver is unable to allocate memory required to support the processing or completion of the function. |
HY003 | Program type out of range | Same as SQLSetParam(). |
HY004 | SQL data type out of range | Same as SQLSetParam(). |
HY009 | Argument value that is not valid | Both rgbValue and pcbValue are null pointers, or ipar is less than one. |
HY010 | Function sequence error | Function is called after SQLExecute() or SQLExecDirect() has returned SQL_NEED_DATA, but data has not been sent for all data-at-execution parameters. |
HY013 * | Memory management problem | The driver is unable to access memory required to support the processing or completion of the function. |
HY014 | Too many handles | The maximum number of handles has been allocated. |
HY021 | Internal descriptor that is not valid | The internal descriptor cannot be addressed or allocated, or it contains a value that is not valid. |