Setting ODBC version and environment attributes

 

After an environment space has been requested, and before any connections are established, the application has the opportunity to set some attributes that control the behavior of the ODBC environment. At least one of these attributes (the application ODBC version) must be set explicitly by the application. This is done by setting the environment attribute SQL_ATTR_ ODBC_VERSION. This attribute states whether the application will follow the ODBC 2.x or ODBC 3.5 specification when using the following items:

 

 

This manual always uses the ODBC ver. 3.5. You may want to review the documentation in the ODBC-SDK if your applications will make use of both versions.

 

To set the attribute SQL_ATTR_ ODBC_VERSION, you use the subroutine f90SQLSetEnvAttr. A typical call to f90SQLSetEnvAttr takes this form:

 

call f90SQLSetEnvAttr (EnvHndl, Attribute, AttributeValue, iRet)

 

Where EnvHndl is an environment handle, Attribute is an integer identifying the attribute being set. f90SQL offers several constants that identify the different attributes. For example, constant SQL_ATTR_ODBC_VERSION identifies the attribute which contains the ODBC version of the application. AttributeValue is the new value for the attribute (it may be a variable). The type of AttributeValue depends on the attribute being set. If the attribute contains an integer, the AttributeValue must be an integer. If Attribute is being stored as a string, then AttributeValue must be an string.

 

For example the following call sets the application ODBC version to 3.5:

 

call f90SQLSetEnvAttr (EnvHndl, SQL_ATTR_ODBC_VERSION, SQL_OV_ODBC3, iRet)

 

An important point to keep in mind is setting the application ODBC version does not change the functionality offered by a driver. When working with ODBC 2.x drivers, applications that follow the ODBC 3.5 specification must use conditional code to avoid using functionality new to ODBC 3.5. ODBC 2.x drivers will not support functionality new to ODBC 3.5 just because the application declares that it follows the ODBC 3.5 specification. Furthermore, ODBC 3.5 drivers will not cease to support functionality new to ODBC 3.5 just because the application declares that it follows the ODBC 2.x specification.

 

You can call f90SQLSetEnvAttr to set other environment attributes also: