To perform a SQL command in an ODBC application, the following sequence of ODBC operations must be executed:
- Connect to the data source (ODBC functions SQLAllocEnv,SQLAllocConnect, SQLConnect)
- Allocate a cursor/statement handle (ODBC function SQLAllocStmt)
- Prepare the SQL command (ODBC function SQLPrepare, orSQLExecDirect for direct prepare and execute)
- Bind program data to SQL data (ODBC functions SQLBindParameter for binding parameter markers to program data and SQLBindCol for binding selected columns to program data)
- Execute the SQL command (ODBC function SQLExecute orSQLExecDirect for direct prepare and execute)
- Fetch rows if the SQL command is a select (ODBC function SQLFetch or SQLExtendedFetch for scrollable cursors)
- Commit or roll back the transaction (ODBC function SQLTransact)
- Free the cursor/statement handle (ODBC function SQLFreeStmt)
- Disconnect from the database (ODBC functions SQLDisconnect, SQLFreeConnect, SQLFreeEnv)
The main steps in performing a SQL command are: connect to the database, prepare the SQL command, execute the SQL command,
fetch the results if it is a SQL select command, and disconnect from the database.
To perform a SQL command repeatedly or to perform multiple SQL commands, it is not necessary (and not appropriate) to execute
all operations listed above every time you want to perform a SQL command. The sequence of the ODBC functions for performing
SQL commands repeatedly is called the access cycle of ODBC functions.