A client database application calls the solidDB® ODBC API directly (or through the ODBC Driver Manager) to perform all interactions with a database. For example, to insert, delete, update, or select records, you make a series of calls to functions in the ODBC API.
An application using ODBC API performs the following tasks:.
1 The application allocates memory and creates handles, and establishes a connection to the database.
a The application allocates memory for an environment handle (henv) and a connection handle (hdbc); both are required to establish a database connection.
An application may request multiple connections for one or more data sources. Each connection is considered a separate transaction space. In other words, a COMMIT or ROLLBACK on one connection will not commit or rollback any statements executed through any other connection.
b The SQLConnect() call establishes the database connection, specifying the server name (a connect string or a data source name), user id, and password.
c The application then allocates memory for a statement handle.
2 The application executes the statement. This requires a series of function calls.
a The application calls either SQLExecDirect(), which both prepares and executes an SQL statement, or SQLPrepare() and SQLExecute(), which allows statements to be executed multiple times.
b If the statement was a SELECT, the result columns must be bound to variables in the application so that the application can see the returned data. The SQLBindCol() function will bind the application's variables to the columns of the result set. The rows can then be fetched using SQLFetch() repeatedly. SELECT statements must be committed as soon as processing of the resultset is done.
If the statement was an UPDATE, DELETE, or INSERT, then the application needs to check if the execution succeeded and call SQLEndTran() to commit the transaction.
3 Finally the application closes the connection and frees any handles.
a The application frees the statement handle.
b The application closes the connection.
c The application frees the connection and environment handles (hdbc and henv).
Note that step 2 (executing SQL statements) may be done repeatedly, depending upon how many SQL statements need to be executed.
Read solidDB® ODBC API for more information about using these API calls.