/**********************************************************************
* FILENAME : ListEnvironmentAttribute.c
*
* DESCRIPTION :
* Example uses SQLGetEnvAttr() to obtain and display environment
* attributes
*
* ODBC USAGE :
* SQLGetEnvAttr() - to obtain values for attributes:
*
* SQL_ATTR_CONNECTION_POOLING
* - reports whether connection pooling is on or off and and
* whether a pool is available per driver or per environment.
* Values - SQL_CP_OFF, SQL_CP_ONE_PER_DRIVER or
* SQL_CP_ONE_PER_HENV
* SQL_ATTR_CP_MATCH
* - reports how a connection is chosen from a pool.
* Values - SQL_CP_STRICT_MATCH or SQL_CP_RELAXED_MATCH
* SQL_ATTR_ODBC_VERSION
* - reports whether application exhibits ODBC 2.x or ODBC 3.x
* behaviour.
* Values - SQL_OV_ODBC3_80, SQL_OV_ODBC3 or SQL_OV_ODBC2
* SQL_ATTR_OUTPUT_NTS
* - reports whether string returned by the driver are null
* terminated
* Values - SQL_TRUE or SQL_FALSE
*/
#include <stdio.h>
#include <stdlib.h>
#include <sql.h>
#include <sqlext.h>
#include <string.h>
#include "util.c"
main () {
// Environment handle
SQLHENV henv = SQL_NULL_HENV;
// For SQL_ATTR_CONNECTION_POOLING, SQL_ATTR_CP_MATCH
SQLUINTEGER uIntVal;
// For SQL_ATTR_ODBC_VERSION, SQL_ATTR_OUTPUT_NTS
SQLINTEGER sIntVal;
SQLRETURN retcode; // Return status
// Allocate an environment handle
retcode=SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
CHECK_ERROR(retcode, "SQLAllocHandle(SQL_HANDLE_ENV)",
henv, SQL_HANDLE_ENV);
// Notify ODBC that this is an ODBC 3.0 app
retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER) SQL_OV_ODBC3, 0);
CHECK_ERROR(retcode, "SQLSetEnvAttr(SQL_HANDLE_ENV)",
henv, SQL_HANDLE_ENV);
printf ("\nEnvironment Attributes : \n");
// Get Env attributes
retcode = SQLGetEnvAttr (henv, SQL_ATTR_CONNECTION_POOLING,
(SQLPOINTER) &uIntVal,
(SQLINTEGER) sizeof(uIntVal), NULL);
CHECK_ERROR(retcode, "SQLGetEnvAttr(SQL_ATTR_CONNECTION_POOLING)",
henv, SQL_HANDLE_ENV);
printf ("\nSQL_ATTR_CONNECTION_POOLING : ");
if (uIntVal==SQL_CP_OFF) printf ("SQL_CP_OFF");
if (uIntVal==SQL_CP_ONE_PER_DRIVER) printf ("SQL_CP_ONE_PER_DRIVER");
if (uIntVal==SQL_CP_ONE_PER_HENV) printf ("SQL_CP_ONE_PER_HENV");
// Caution: SQL_CP_DRIVER_AWARE may be undefined
if (uIntVal==SQL_CP_DRIVER_AWARE)
printf ("SQL_CP_DRIVER_AWARE");
retcode = SQLGetEnvAttr (henv, SQL_ATTR_CP_MATCH,
(SQLPOINTER) &uIntVal,
(SQLINTEGER) sizeof(uIntVal), NULL);
CHECK_ERROR(retcode, "SQLGetEnvAttr(SQL_ATTR_CP_MATCH)",
henv, SQL_HANDLE_ENV);
printf ("\nSQL_ATTR_CP_MATCH : ");
if (uIntVal==SQL_CP_STRICT_MATCH) printf ("SQL_CP_STRICT_MATCH");
if (uIntVal==SQL_CP_RELAXED_MATCH) printf ("SQL_CP_RELAXED_MATCH");
retcode = SQLGetEnvAttr (henv, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER) &sIntVal,
(SQLINTEGER) sizeof(sIntVal), NULL);
CHECK_ERROR(retcode, "SQLGetEnvAttr(SQL_ATTR_ODBC_VERSION)",
henv, SQL_HANDLE_ENV);
printf ("\nSQL_ATTR_ODBC_VERSION : ");
if (sIntVal==SQL_OV_ODBC3_80) printf ("SQL_OV_ODBC3_80");
if (sIntVal==SQL_OV_ODBC3) printf ("SQL_OV_ODBC3");
if (sIntVal==SQL_OV_ODBC2) printf ("SQL_OV_ODBC2");
retcode = SQLGetEnvAttr (henv, SQL_ATTR_OUTPUT_NTS,
(SQLPOINTER) &sIntVal,
(SQLINTEGER) sizeof(sIntVal), NULL);
CHECK_ERROR(retcode, "SQLGetEnvAttr(SQL_ATTR_OUTPUT_NTS)",
henv, SQL_HANDLE_ENV);
printf ("\nSQL_ATTR_OUTPUT_NTS : ");
if (sIntVal==SQL_TRUE) printf ("SQL_TRUE");
if (sIntVal==SQL_FALSE) printf ("SQL_FALSE");
exit:
printf ("\nComplete.\n");
// Free Environment
if (henv != SQL_NULL_HENV)
SQLFreeHandle(SQL_HANDLE_ENV, henv);
return 0;
}
Further information