/**********************************************************************
* FILENAME : ListDrivers.c
*
* DESCRIPTION :
* Example to list the ODBC Drivers available
*
* ODBC USAGE :
* Loop until no more data
* SQLDrivers - with direction = SQL_FETCH_FIRST first
* time and with direction = SQL_FETCH_NEXT
* subsequently prints driver name
*/
#include <stdio.h>
#include <stdlib.h>
#include <sql.h>
#include <sqlext.h>
#include <string.h>
#include "util.c"
int main () {
SQLHENV henv = SQL_NULL_HENV; // Environment
SQLRETURN retcode; // Return status
char driver[256];
char attr[256];
SQLSMALLINT driver_ret;
SQLSMALLINT attr_ret;
SQLUSMALLINT direction;
// Allocate environment handle
retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
CHECK_ERROR(retcode, "SQL_HANDLE_ENV(SQL_NULL_HANDLE)",
henv, SQL_HANDLE_ENV);
// Set ODBC version
retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION,
(void *) SQL_OV_ODBC3, 0);
CHECK_ERROR(retcode, "SQLSetEnvAttr(SQL_ATTR_ODBC_VERSION)",
henv, SQL_NULL_HANDLE);
// Call SQLDrivers to return ODBC Drivers
direction = SQL_FETCH_FIRST;
while(SQL_SUCCEEDED(retcode = SQLDrivers(henv, direction,
driver, sizeof(driver),
&driver_ret, attr,
sizeof(attr), &attr_ret))) {
direction = SQL_FETCH_NEXT;
printf("%s - %s\n", driver, attr);
CHECK_ERROR(retcode, "SQLDrivers()", henv, SQL_NULL_HANDLE);
}
exit:
printf ("\nComplete.\n");
if (henv!=SQL_NULL_HENV) SQLFreeHandle(SQL_HANDLE_ENV, henv);
return 0 ;
}
Further information