Databases Reference
In-Depth Information
would be unnecessarily used. If fewer SQLVARs are defined, there will not be
enough SQLVAR elements to describe all the columns being returned.
4.4 Building a C/C++ application using CLI
In this section, we show you the fundamentals of building a C/C++ application
using CLI. We discuss first some basic concepts and the environment setup. We
then guide you step-by-step to build an application starting from a simple code
template.
4.4.1 CLI handles
A Call Level Interface (CLI) application needs to initially set up data structures
and variables to manage work such as connecting to the database, running SQL
statements, and disconnecting from the database. Luckily, data objects called
handles exist to make things easier. Handles can be allocated, used for
processing, and then freed. The possible CLI handles are:
Environment (SQL_HANDLE_ENV)
This object is the base handle, which holds iholds information and provides a
context for all connections. Typically, only a single environment handle exists
for an application.
Connection (SQL_HANDLE_DBC)
This object holds information about a connection to a single database and
provides a context for all statements executed against that database. A CLI
application can connect to multiple databases. This means that there can be
multiple connection handles associated with a single environment handle.
Statement (SQL_HANDLE_STMT)
This object contains information about the processing of an SQL statement.
This must be associated with a connection handle.
Descriptor (SQL_HANDLE_DESC)
This handle holds information about either parameter markers or columns in a
resultset. It can be associated with either a statement or connection handle.
Figure 4-1 on page 178 illustrates the relationship of the handles. Connection
handles can only be defined under the context of an environment handle, and
statement handles can only be defined under the context of a connection handle.
Descriptor handles can be optionally allocated to associate with a connection or
statement handle. Handle allocation is done in sequence. The environment
handle must be declared first, then the connection handle is declared under the
environment handle, and then the statement handle is declared under the
Search WWH ::




Custom Search