Begin detailed description.
This figure is a flowchart that depicts common
sequences of functions that you call in the transaction processing
task of your application. These sequences consist of two main parts:
preparing and executing an SQL statement, and processing the action
that the SQL statement performs.
You can prepare and execute a statement according
to one of the sequences of functions that the following tables present:
| Sequence A |
Description of sequence A |
| SQLAllocHandle() |
Allocates a statement. |
| SQLPrepare() |
Prepares a statement. |
| SQLBindParameter() |
Binds parameter markers (if any) in the prepared
SQL statement. |
| SQLExecute() |
Executes a statement. |
| Sequence B |
Description of sequence B |
| SQLAllocHandle() |
Allocates a statement. |
| SQLBindParameter() |
Binds parameter markers (if any) in the SQL statement
on the statement handle. |
| SQLExecDirect() |
Directly executes a statement. |
After you prepare and execute an SQL statement,
you handle the action that the statement performs. This figure presents
sequences of functions that handle the following types of SQL actions:
- Generate query results (SELECT and VALUES)
- Update data (UPDATE, DELETE, and INSERT)
- Other data definition statements (ALTER, CREATE, DROP, REVOKE,
and SET)
For SQL statements that generate query results,
you generally use the sequence of functions that the following table
presents. Each row in this table represents an optional function call
or a choice between function calls. These function calls are presented
in the order you include them in your application.
| Function call |
Usage |
Description |
| SQLNumResultCols() |
Optional |
Finds the number of columns in the result set.
If you know this number, you can eliminate this function call. |
SQLDescribeCol() or SQLColAttribute() |
Optional |
Finds the SQL data type of a column in the result
set. Call one of these functions for each column unless you know the
type of data that the column contains. |
SQLBindCol() or SQLFetch() |
Required choice |
Call SQLBindCol() for each column
in the result set if you want to retrieve the results row. Call SQLFetch() if
you want to retrieve data one value at a time. |
SQLFetch(), or SQLGetData() followed
by SQLFetch() |
Required choice |
Call SQLFetch() for each row that
you want to retrieve if you used SQLBindCol() in
the preceding step. If you did not bind columns with SQLBindCol(),
call SQLGetData() for each column value that you
want to receive in a given row. When you use SQLGetData() to
retrieve results, you call SQLFetch() to advance
the cursor. You can then retrieve values from the next row. |
SQLEndTran() or SQLExecute() |
Required choice |
At this point, you can end the transaction with SQLEndTran(),
re-execute the same SQL statement with different parameter values
with SQLExecute(), or use SQLExecute() to
execute another SQL statement within the same transaction. |
SQLFreeHandle() or SQLPrepare() |
Required choice |
After you commit the transaction, you can free
the statement with SQLFreeHandle() or prepare and
execute a new SQL statement to begin a new transaction. |
For SQL statements that update data, you generally
use the sequence of functions that the following table presents. Each
row in this table represents an optional function call or a choice
between function calls. These function calls are presented in the
order that you include them in your application.
| Function call |
Usage |
Description |
| SQLRowCount() |
Optional |
Returns the number of rows that the SQL statement
altered. |
SQLEndTran() or SQLExecute() |
Required choice |
At this point, you can end the transaction with SQLEndTran(),
use SQLExecute() to re-execute the same SQL statement
with different parameter values, or use SQLExecute() to
execute another SQL statement within the same transaction. |
SQLFreeHandle() or SQLPrepare() |
Required choice |
After you commit the transaction, you can free
the statement with SQLFreeHandle() or prepare and
execute a new SQL statement to begin a new transaction. |
For SQL data definition statements, you generally
use the sequence of functions that the following table presents. Each
row in this table represents a choice between function calls. These
function calls are presented in the order that you include them in
your application.
| Function call |
Usage |
Description |
SQLEndTran() or SQLExecute() |
Required choice |
At this point, you can end the transaction with SQLEndTran(),
re-execute the same SQL statement with different parameter values,
or execute another SQL statement within the same transaction. |
SQLFreeHandle() or SQLPrepare() |
Required choice |
After you commit the transaction, you can free
the statement with SQLFreeHandle() or prepare and
execute a new SQL statement to begin a new transaction. |
End detailed description.