16.20 - Example - ODBC Driver for Teradata

ODBC Driver for Teradata® User Guide

ODBC Driver for Teradata
October 2018
User Guide

The following example describes the usage of the stored procedure CALL statement in an ODBC application when the OutputAsResultSet option is set to N:

Assume a stored procedure spODBC has three parameters: p1 of type OUT, p2 of type INOUT, and p3 of type IN.

The“?” character acts as a placeholder for IN, OUT, and INOUT arguments. The “?” character placeholder arguments need to be bound with the application local variables using the SQLBindParameter ODBC SDK API call.

char *request = "CALL spODBC(?, ?, ?)";
SQLBindParameter(..., 1, SQL_PARAM_OUTPUT, ..., SQLINTEGER,
..., ..., AppVar1, sizeof(AppVar1), ...);
..., ..., AppVar2, sizeof(AppVar2), ...);
SQLBindParameter(..., 3, SQL_PARAM_INPUT,..,SQLINTEGER, ...,...,AppVar3,
SQLExecDirect(hstmt, request);

where the following is true:

AppVar1, AppVar2, and AppVar3 are the ODBC application-specific local variables of INTEGER data type and these contain certain values such as input data while sending the request and output data while retrieving the results.

The second argument in the SQLBindParameter() is the “?” number ordered sequentially from left to right, starting at 1.

Retrieving output parameter value:

The values of INOUT and OUT parameters need to be retrieved from the response by directly printing the local variables (that were bound using SQLBindParameter) after a SQLFetch API call, or by using the SQLBindCol ODBC SDK API followed by SQLFetch API call.

SQLBindCol(..., 1, ..., AppVar1, ..., ...);
SQLBindCol(..., 2, ..., AppVar2, ..., ...);

where the following is true:

the second argument in the SQLBindCol() is the parameter number of result data, ordered sequentially from left to right, starting at 1.

The values of INOUT and OUT parameters also can be retrieved using SQLFetch ODBC SDK API followed by SQLGetdata API.