Binding parameter markers in CLI applications
This topic describes how to bind
parameter markers to application variables before executing SQL statements.
Parameter
markers in SQL statements can be bound to single values or to arrays
of values. Binding each parameter marker individually requires a network
flow to the server for each set of values. Using arrays, however,
allows several sets of parameter values to be bound and sent at once
to the server.
Before you begin
Procedure
To bind parameter markers, perform either of the following
steps:
- To bind parameter markers one at a time to application variables,
call
SQLBindParameter()
for each application variable you want to bind. Ensure you specify the correct parameter type: SQL_PARAM_INPUT, SQL_PARAM_OUTPUT, or SQL_PARAM_INPUT_OUTPUT. The following example shows how two parameter markers are bound with two application variables:SQLCHAR *stmt = (SQLCHAR *)"DELETE FROM org WHERE deptnumb = ? AND division = ? "; SQLSMALLINT parameter1 = 0; char parameter2[20]; /* bind parameter1 to the statement */ cliRC = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_SHORT, SQL_SMALLINT, 0, 0, ¶meter1, 0, NULL); /* bind parameter2 to the statement */ cliRC = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 20, 0, parameter2, 20, NULL);
- To bind at once many values to parameter markers, perform either of the following tasks which use arrays of values: