solidDB Help : Programming : solidDB ODBC API : Getting started with solidDB ODBC : ODBC API basic application steps
  
ODBC API basic application steps
A client database application calls the solidDB ODBC API directly (or by using 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 that uses the 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 can request multiple connections for one or more data sources. Each connection is considered a separate transaction space. In other words, a COMMIT or ROLLBACK operation on one connection does not commit or rollback any statements that are executed by 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 statement, the result columns must be bound to variables in the application so that the application can see the returned data. The SQLBindCol() function binds the application 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 result set is done.
If the statement was an UPDATE, DELETE, or INSERT statement, then the application checks 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) can be done repeatedly, depending upon how many SQL statements need to be executed.
For more information about using these API calls, see solidDB ODBC API.
Go up to
Getting started with solidDB ODBC