示例#1
0
void CODBCCreate::file_click()
{
	char path[ 1024 ];
	char def[ 1024 ];
	char buffer[ 128 ];

	sprintf( def, "%s/ODBCDataSources", odbcinst_system_file_path( buffer ));

	SQLGetPrivateProfileString( "ODBC", "FileDSNPath", 
			def, path, sizeof( path ), "odbcinst.ini" );

#ifdef QT_V4LAYOUT
	QString s = Q3FileDialog::getSaveFileName(
#else
	QString s = QFileDialog::getSaveFileName(
#endif
				path,
				"ODBC File Data Sources's (*.dsn)",
				this,
				"Select file name",
				"Choose a filename to save under" );

	if ( !s.isNull() )
	{
		file_edit->setText( s );
	}
}
BOOL SQLInstallDriverManager(	LPSTR	pszPath,
								WORD	nPathMax,
								WORD	*pnPathOut )
{
    char  szIniName[ INI_MAX_OBJECT_NAME + 1 ];
	char  b1[ ODBC_FILENAME_MAX + 1 ];

    inst_logClear();

	/* SANITY CHECKS */
	if ( pszPath == NULL || nPathMax < 2 )
	{
        inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, "" );
		return 0;
	}

    sprintf( szIniName, "%s", odbcinst_system_file_path( b1 ) );

	/* DO SOMETHING */
	strncpy( pszPath, szIniName, nPathMax );
	if ( pnPathOut != NULL )
		*pnPathOut = strlen( pszPath );

	return TRUE;
}
示例#3
0
BOOL _odbcinst_FileINI( char *pszPath )
{
	char b1[ ODBC_FILENAME_MAX + 1 ];

    /* we need a viable buffer (with space for FILENAME_MAX chars)... */
    if ( !pszPath )
        return FALSE;

    /* system configured to use a special location... */
    *pszPath = '\0';
    SQLGetPrivateProfileString( "ODBC", "FileDSNPath", "", pszPath, FILENAME_MAX - 2, "odbcinst.ini" );
    if ( *pszPath )
        return TRUE;

    /* default location... */
    sprintf( pszPath, "%s/ODBCDataSources", odbcinst_system_file_path( b1 ));

    return TRUE;
}
示例#4
0
void CODBCCreate::populate()
{
  	char      	szDriverName[INI_MAX_OBJECT_NAME+1];
  	char      	szPropertyName[INI_MAX_PROPERTY_NAME+1];
  	char      	szDescription[INI_MAX_PROPERTY_VALUE+1];
  	char      	szDriver[INI_MAX_PROPERTY_VALUE+1];
  	char      	szDriver64[INI_MAX_PROPERTY_VALUE+1];
  	char      	szSetup[INI_MAX_PROPERTY_VALUE+1];
  	char      	szSetup64[INI_MAX_PROPERTY_VALUE+1];
#ifdef QT_V4LAYOUT
  	Q3ListViewItem *pListViewItem;
#else
  	QListViewItem *pListViewItem;
#endif
  	QString     qsError;
  	char        szINI[FILENAME_MAX+1];
	HINI		hIni;
	char 		buffer[ 128 ];

  	sprintf( szINI, "%s/odbcinst.ini", odbcinst_system_file_path( buffer ));

  	if ( iniOpen( &hIni, szINI, "#;", '[', ']', '=', TRUE ) != INI_ERROR )
  	{
    	iniObjectFirst( hIni );
    	while ( iniObjectEOL( hIni ) == FALSE )
    	{
      		szDriverName[0] = '\0';
      		szDescription[0]  = '\0';
      		szDriver[0]   = '\0';
      		szDriver64[0]   = '\0';
      		szSetup64[0]   = '\0';
      		szSetup[0]    = '\0';
      		iniObject( hIni, szDriverName );
      		iniPropertyFirst( hIni );
      		if ( strcmp( szDriverName, "ODBC" ) == 0 )
      		{
        		iniObjectNext( hIni );
        		continue;
      		}

      		while ( iniPropertyEOL( hIni ) == FALSE )
      		{
        		iniProperty( hIni, szPropertyName );
        		iniToUpper( szPropertyName );

        		if ( strncmp( szPropertyName, "DESCRIPTION", INI_MAX_PROPERTY_NAME ) == 0 )
          			iniValue( hIni, szDescription );
#ifdef PLATFORM64
				if ( strncmp( szPropertyName, "DRIVER64", INI_MAX_PROPERTY_NAME ) == 0 )
          			iniValue( hIni, szDriver64 );
				if ( strncmp( szPropertyName, "DRIVER", INI_MAX_PROPERTY_NAME ) == 0 )
          			iniValue( hIni, szDriver );

        		if ( strncmp( szPropertyName, "SETUP64", INI_MAX_PROPERTY_NAME ) == 0 )
          			iniValue( hIni, szSetup64 );
        		if ( strncmp( szPropertyName, "SETUP", INI_MAX_PROPERTY_NAME ) == 0 )
          			iniValue( hIni, szSetup );
#else
        		if ( strncmp( szPropertyName, "DRIVER", INI_MAX_PROPERTY_NAME ) == 0 )
          			iniValue( hIni, szDriver );

        		if ( strncmp( szPropertyName, "SETUP", INI_MAX_PROPERTY_NAME ) == 0 )
          			iniValue( hIni, szSetup );
#endif

        		iniPropertyNext( hIni );
      		}

#ifdef PLATFORM64
      		if ( szDriver64[ 0 ] != '\0' )
      		{
	      		strcpy( szDriver, szDriver64 );
      		}
      		if ( szSetup64[ 0 ] != '\0' )
      		{
	      		strcpy( szSetup, szSetup64 );
      		}
#endif

#ifdef QT_V4LAYOUT
      		pListViewItem = new Q3ListViewItem( driver_list, szDriverName, szDescription, szDriver, szSetup );
#else
      		pListViewItem = new QListViewItem( driver_list, szDriverName, szDescription, szDriver, szSetup );
#endif
      		iniObjectNext( hIni );
    	}
    	iniClose( hIni );
  	}
  	else
  	{
    	qsError.sprintf( "Could not open system file at %s", szINI );
    	QMessageBox::information( this, "Create New Data Source",  qsError );
  	}
}
BOOL SQLGetInstalledDrivers(	LPSTR	pszBuf,
								WORD	nBufMax,
								WORD	*pnBufOut )
{
	HINI	hIni;
	WORD	nBufPos		= 0;
	WORD	nToCopySize	= 0;
	char	szObjectName[INI_MAX_OBJECT_NAME+1];
    char    szIniName[ INI_MAX_OBJECT_NAME + 1 ];
	char 	b1[ 256 ], b2[ 256 ];

    inst_logClear();

#ifdef VMS
    sprintf( szIniName, "%s:%s", odbcinst_system_file_path( b1 ), odbcinst_system_file_name( b2 ) );
#else
    sprintf( szIniName, "%s/%d", odbcinst_system_file_path( b1 ), odbcinst_system_file_name( b2 ) );
#endif

#ifdef __OS2__
	if ( iniOpen( &hIni, szIniName, "#;", '[', ']', '=', TRUE, 1L ) != INI_SUCCESS )
#else
	if ( iniOpen( &hIni, szIniName, "#;", '[', ']', '=', TRUE ) != INI_SUCCESS )
#endif
	{
        inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_COMPONENT_NOT_FOUND, "" );
		return FALSE;
	}
	
	memset( pszBuf, '\0', nBufMax );

	iniObjectFirst( hIni );
	while ( iniObjectEOL( hIni ) == FALSE )
	{
		iniObject( hIni, szObjectName );
		if ( strcmp( szObjectName, "ODBC" ) == 0 )
		{
		    iniObjectNext( hIni );
		    continue;
		}

		if ( (strlen( szObjectName )+1) > (nBufMax - nBufPos) )
		{
			nToCopySize = nBufMax - nBufPos;
			strncpy( &(pszBuf[nBufPos]), szObjectName, nToCopySize );
			nBufPos = nBufMax;
			break;
		}
		else
		{
			strcpy( &(pszBuf[nBufPos]), szObjectName );
			nBufPos += strlen( szObjectName )+1;
		}
		iniObjectNext( hIni );
	}
	iniClose( hIni );

	if ( pnBufOut )
		*pnBufOut = nBufPos-1;
	
	return TRUE;
}
示例#6
0
BOOL SQLRemoveDriver(			LPCSTR	pszDriver,
								BOOL	nRemoveDSN,
								LPDWORD	pnUsageCount )
{
	HINI	hODBCInstIni;
	char	szValue[INI_MAX_PROPERTY_VALUE+1];
    char    szIniName[ INI_MAX_OBJECT_NAME + 1 ];
	char	b1[ 256 ], b2[ 256 ];

    inst_logClear();

	/* SANITY CHECKS */
	if ( pszDriver == NULL )
	{
        inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_INVALID_NAME, "" );
		return FALSE;
	}
	if ( pszDriver[0] == '\0' )
	{
        inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_INVALID_NAME, "" );
		return FALSE;
	}
	if ( nRemoveDSN != TRUE && nRemoveDSN != FALSE )
	{
        inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, "" );
		return FALSE;
	}

	(*pnUsageCount) = 0;

#ifdef VMS
    sprintf( szIniName, "%s:%s", odbcinst_system_file_path( b1 ), odbcinst_system_file_name( b2 ) );
#else
    sprintf( szIniName, "%s/%s", odbcinst_system_file_path( b1 ), odbcinst_system_file_name( b2 ) );
#endif

	/* PROCESS ODBC INST INI FILE */
#ifdef __OS2__	
	if ( iniOpen( &hODBCInstIni, szIniName, "#;", '[', ']', '=', TRUE, 1L ) != INI_SUCCESS )
#else
	if ( iniOpen( &hODBCInstIni, szIniName, "#;", '[', ']', '=', TRUE ) != INI_SUCCESS )
#endif
	{
        inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_COMPONENT_NOT_FOUND, "" );
		return FALSE;
	}

	/* LETS GET ITS FILE USAGE VALUE (if any) */
	if ( iniPropertySeek( hODBCInstIni, (char *)pszDriver, "UsageCount", "" ) == INI_SUCCESS )
	{
		iniValue( hODBCInstIni, szValue );
        (*pnUsageCount) = atoi( szValue );
	}

	/* DOES THE OBJECT ALREADY EXIST? (also ensures that we have correct current object) */	
	if ( iniObjectSeek( hODBCInstIni, (char *)pszDriver ) == INI_SUCCESS )
	{
        if ( (*pnUsageCount) == 0 )
			(*pnUsageCount) = 1;

		(*pnUsageCount)--;
		if ( (*pnUsageCount) == 0 )
		{
			iniObjectDelete( hODBCInstIni );
			if ( nRemoveDSN )
			{
				/***********************************
				 * TO DO
				 ***********************************/
			}
		}
		else
		{
			if ( iniPropertySeek( hODBCInstIni, (char *)pszDriver, "UsageCount", "" ) == INI_SUCCESS )
			{
				sprintf( szValue, "%ld", (long int)(*pnUsageCount) );
				iniPropertyUpdate( hODBCInstIni, "UsageCount", szValue );
			}
			else
			{
				iniPropertyInsert( hODBCInstIni, "UsageCount", szValue );
			}
		}
		if ( iniCommit( hODBCInstIni ) != INI_SUCCESS )
		{
			inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, "" );
			iniClose( hODBCInstIni );
			return FALSE;
		}
	}


	iniClose( hODBCInstIni );

	return TRUE;
}
int _SQLGetInstalledDrivers(    LPCSTR  pszSection,
                                LPCSTR  pszEntry,
                                LPCSTR  pszDefault,
                                LPCSTR  pRetBuffer,
                                int     nRetBuffer )
{
    HINI    hIni;
    int     nBufPos         = 0;
    int     nStrToCopy;
    char    szObjectName[INI_MAX_OBJECT_NAME+1];
    char    szPropertyName[INI_MAX_PROPERTY_NAME+1];
    char    szValue[INI_MAX_PROPERTY_VALUE+1];
    char    szIniName[ INI_MAX_OBJECT_NAME + 1 ];
    char    *ptr;
    char    b1[ 256 ], b2[ 256 ];

    /* SANITY CHECKS */
    if ( pRetBuffer == NULL || nRetBuffer < 2 )
    {
        inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, "" );
        return -1;
    }

    /*
     * first try in the system odbcinst.ini
     */

#ifdef VMS
    sprintf( szIniName, "%s:%s", odbcinst_system_file_path( b1 ), odbcinst_system_file_name( b2 ));
#else
    sprintf( szIniName, "%s/%s", odbcinst_system_file_path( b1 ), odbcinst_system_file_name( b2 ));
#endif

    /* PROCESS ODBC INI FILE */
#ifdef __OS2__
    if ( iniOpen( &hIni, szIniName, "#;", '[', ']', '=', 1, 1L ) != INI_SUCCESS )
#else
    if ( iniOpen( &hIni, szIniName, "#;", '[', ']', '=', 1 ) != INI_SUCCESS )
#endif
    {
        inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_COMPONENT_NOT_FOUND, "" );
        return -1;
    }

    /*
     * now try the user odbcinst.ini if it exists
     */

#ifdef VMS
    sprintf( szIniName, "%s:%s", odbcinst_user_file_path( b1 ), odbcinst_user_file_name( b2 ));
#else
    sprintf( szIniName, "%s/%s", odbcinst_user_file_path( b1 ), odbcinst_user_file_name( b2 ));
#endif

    /* PROCESS .ODBCINST INI FILE */
    iniAppend( hIni, szIniName );

    nBufPos = 0;
    if ( pszSection == NULL )
    {
        ptr = (char*) pRetBuffer;
        *ptr = '\0';

        /* JUST COLLECT SECTION NAMES */

        for( iniObjectFirst( hIni ); iniObjectEOL( hIni ) != TRUE; iniObjectNext( hIni ))
        {
            iniObject( hIni, szObjectName );

            if ( strcasecmp( szObjectName, "ODBC" ) == 0 )
            {
                continue;
            }
            else if ( nBufPos + 1 + strlen( szObjectName ) >= nRetBuffer )
            {
                break;
            }
            else
            {
                strcpy( ptr, szObjectName );
                ptr += strlen( ptr ) + 1;
                nBufPos += strlen( szObjectName ) + 1;
            }
        }

        /*
         * Add final NULL
         */

        if ( nBufPos == 0 )
        {
            ptr ++;
        }

        *ptr = '\0';
    }
    else if ( pszEntry == NULL )
    {
        ptr = (char*) pRetBuffer;
        *ptr = '\0';

        iniObjectSeek( hIni, (char *)pszSection );

        /* COLLECT ALL ENTRIES FOR THE GIVEN SECTION */

        for( iniPropertyFirst( hIni ); iniPropertyEOL( hIni ) != TRUE; iniPropertyNext( hIni ))
        {
            iniProperty( hIni, szPropertyName );

            if ( nBufPos + 1 + strlen( szPropertyName ) >= nRetBuffer )
            {
                break;
            }
            else
            {
                strcpy( ptr, szPropertyName );
                ptr += strlen( ptr ) + 1;
                nBufPos += strlen( szPropertyName ) + 1;
            }
        }

        /*
         * Add final NULL
         */

        if ( nBufPos == 0 )
        {
            ptr ++;
        }
    }
    else
    {
        /* TRY TO GET THE ONE ITEM MATCHING Section & Entry */
        if ( iniPropertySeek( hIni, (char *)pszSection, (char *)pszEntry, "" ) != INI_SUCCESS )
        {
            /* try to use any default provided */
            if ( pRetBuffer && nRetBuffer > 0 )
            {
                if ( pszDefault )
                {
                    strncpy( (char *)pRetBuffer, pszDefault, nRetBuffer );
                    ((char*)pRetBuffer)[ nRetBuffer - 1 ] = '\0';
                }
            }
        }
        else
        {
            iniValue( hIni, szValue );
            nStrToCopy = strlen( szValue ) + 1;                 /* factor NULL terminator for string */
            if ( nBufPos + nStrToCopy + 1 > nRetBuffer )        /* factor NULL terminator for buffer */
                nStrToCopy = nRetBuffer - nBufPos - 2;
            strncpy( (char *)&(pRetBuffer[nBufPos]), szValue, nStrToCopy );
            nBufPos += nStrToCopy;
			/*
			 * length doesn't include NULL
			 */
			nBufPos--;
        }
    }

    /* CLOSE */
    iniClose( hIni );

    return nBufPos;
}