Use a Statement (ODBC)
To use a statement
Call SQLAllocHandle with a HandleType of SQL_HANDLE_STMT to allocate a statement handle.
To use server cursors, you must set cursor attributes to values other than their defaults.
Optionally, if the statement will be executed several times, prepare the statement for execution with SQLPrepare Function.
Optionally, if the statement has bound parameter markers, bind the parameter markers to program variables by using SQLBindParameter. If the statement was prepared, you can call SQLNumParams and SQLDescribeParam to find the number and characteristics of the parameters.
Execute a statement directly by using SQLExecDirect.
- or -
If the statement was prepared, execute it multiple times by using SQLExecute.
- or -
Call a catalog function, which returns results.
Process the results by binding the result set columns to program variables, by moving data from the result set columns to program variables by using SQLGetData, or a combination of the two methods.
Fetch through the result set of a statement one row at a time.
- or -
Fetch through the result set several rows at a time by using a block cursor.
- or -
Call SQLRowCount to determine the number of rows affected by an INSERT, UPDATE, or DELETE statement.
If the SQL statement can have multiple result sets, call SQLMoreResults at the end of each result set to see if there are additional result sets to process.
After results are processed, the following actions may be necessary to make the statement handle available to execute a new statement:
If you bound parameter markers to program variables, call SQLFreeStmt with Option set to SQL_RESET_PARAMS to free the bound parameters.
If you bound result set columns to program variables, call SQLFreeStmt with Option set to SQL_UNBIND to free the bound columns.
To reuse the statement handle, go to Step 2.
Call SQLFreeHandle with a HandleType of SQL_HANDLE_STMT to free the statement handle.