[unixODBC-dev] (no subject)

Nick Gorham nick at lurcher.org
Wed Nov 16 13:20:23 GMT 2005


Igor Korot wrote:
> Nick, Stefan and others,
> When I earlier said that I have more work to, I meant that I need to find a function that will give me a list of DSN names for specified driver.
> On Windows I could easily do it as:

To try and bring this to a close, the following does exactly what you 
describe you want, with unixODBC and Windows. But it will only do this 
if your ini files are configured as unixODBC expects, if not then its 
not a fault in unixODBC, but in the ini files.

#include <stdio.h>
#include <sql.h>
#include <sqlext.h>

main()
{
     SQLHANDLE env;
     SQLRETURN ret;
     int result;
     unsigned char driverDesc[ 512 ];
     unsigned char attrib[ 512 ];
     unsigned char server[ 512 ];
     unsigned char desc[ 512 ];
     short slen, dlen;
     short descrLength = 512, attrLength = 512;

     ret = SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env );
     ret = SQLSetEnvAttr( env, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) 3, 0 );

     result = SQLDrivers( env, SQL_FETCH_NEXT, driverDesc,
              sizeof( driverDesc ), &descrLength, attrib, sizeof( attrib 
), &attrLength );
     while( result != SQL_NO_DATA_FOUND )
     {
         printf( "Driver: %s\n", driverDesc );
         result = SQLDataSources( env, SQL_FETCH_FIRST, server,
                 sizeof( server ), &slen, desc, sizeof( desc ), &dlen );
         while( result != SQL_NO_DATA_FOUND )
         {
             if ( strcmp( desc, driverDesc ) == 0 ) {
                 printf( "\tDSN: %s\n", server );
             }
             result = SQLDataSources( env, SQL_FETCH_NEXT, server,
                     sizeof( server ), &slen, desc, sizeof( desc ), &dlen );
         }
         result = SQLDrivers( env, SQL_FETCH_NEXT, driverDesc,
                     sizeof( server ), &descrLength, attrib, sizeof( 
attrib ), &attrLength );
     }
     ret = SQLFreeHandle( SQL_HANDLE_ENV, env );
}



More information about the unixODBC-dev mailing list