BOOL INSTAPI SQLWriteFileDSNW(LPCWSTR lpszFileName, LPCWSTR lpszAppName, LPCWSTR lpszKeyName, LPCWSTR lpszString) { BOOL ret; char *file; char *app; char *key; char *str; file = lpszFileName ? _single_string_alloc_and_copy( lpszFileName ) : (char*)NULL; app = lpszAppName ? _single_string_alloc_and_copy( lpszAppName ) : (char*)NULL; key = lpszKeyName ? _single_string_alloc_and_copy( lpszKeyName ) : (char*)NULL; str = lpszString ? _single_string_alloc_and_copy( lpszString ) : (char*)NULL; ret = SQLWriteFileDSN( file, app, key, str ); if ( file ) free( file ); if ( app ) free( app ); if ( key ) free( key ); if ( str ) free( str ); return ret; }
void TKVList::WriteFileDSN (LPCTSTR filename, LPCTSTR names) { LPCTSTR key; for (key = names; *key; key += _tcslen (key) + 1) SQLWriteFileDSN (filename, _T("ODBC"), key, Value (key)); }
BOOL INSTAPI SQLWriteFileDSNW (LPCWSTR lpszFileName, LPCWSTR lpszAppName, LPCWSTR lpszKeyName, LPWSTR lpszString) { char *_filename_u8 = NULL; char *_appname_u8 = NULL; char *_keyname_u8 = NULL; char *_string_u8 = NULL; BOOL retcode = FALSE; _filename_u8 = (char *) dm_SQL_WtoU8 ((SQLWCHAR *) lpszFileName, SQL_NTS); if (_filename_u8 == NULL && lpszFileName) { PUSH_ERROR (ODBC_ERROR_OUT_OF_MEM); goto done; } _appname_u8 = (char *) dm_SQL_WtoU8 ((SQLWCHAR *) lpszAppName, SQL_NTS); if (_appname_u8 == NULL && lpszAppName) { PUSH_ERROR (ODBC_ERROR_OUT_OF_MEM); goto done; } _keyname_u8 = (char *) dm_SQL_WtoU8 ((SQLWCHAR *) lpszKeyName, SQL_NTS); if (_keyname_u8 == NULL && lpszKeyName) { PUSH_ERROR (ODBC_ERROR_OUT_OF_MEM); goto done; } _string_u8 = (char *) dm_SQL_WtoU8 ((SQLWCHAR *) lpszString, SQL_NTS); if (_string_u8 == NULL && lpszString) { PUSH_ERROR (ODBC_ERROR_OUT_OF_MEM); goto done; } retcode = SQLWriteFileDSN (_filename_u8, _appname_u8, _keyname_u8, _string_u8); done: MEM_FREE (_filename_u8); MEM_FREE (_appname_u8); MEM_FREE (_keyname_u8); MEM_FREE (_string_u8); return retcode; }
bool CODBCCreate::createDsn() { BOOL ret; QString fname = file_edit->text(); // Make sure it ends with .dsn if ( fname.right( 4 ).lower().compare( ".dsn" )) { fname.append( ".dsn" ); } if ( access( fname, F_OK ) == 0 ) { int replace = QMessageBox::information( NULL, "Save File DSN", "Data source file exists. Overwrite?", QMessageBox::Yes, QMessageBox::No ); if ( replace == QMessageBox::No ) { inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_CREATE_DSN_FAILED, "" ); return false; } } if ( unlink( fname )) { inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_CREATE_DSN_FAILED, "" ); return false; } ret = SQLWriteFileDSN((const char*) fname, "ODBC", "DRIVER", (const char *)current_driver ); if ( !ret ) { return false; } if ( extra_keywords.length() > 0 ) { int start = 0; int end = 0; int eq; QString str; while( start < extra_keywords.length() ) { end = extra_keywords.find( '\n', start ); if ( end == -1 ) { end = extra_keywords.length(); } str = extra_keywords.mid( start, end-start ) + ";"; eq = str.find( '=', 0 ); if ( eq > 0 ) { ret = SQLWriteFileDSN((const char*) fname, "ODBC", (const char *) str.left( eq ), (const char *) str.right( str.length() - eq - 1 )); if ( !ret ) { return false; } } start = end + 1; } } return true; }
/*! * \brief Save Data Source Name. * * Call this to save User, System and File DSN's based upon a property list. * * \param pwidgetParent Input. Widget to use as parent for messages. Null is ok. * \param hFirstProperty Input. First property in NULL terminated property list. * \param nType Input. Type of DSN. * \param stringIni Input. Default is QString::null. * * \li User and System DSN. This can be a QString::null to use * default location or it can be a fully qualified path and name. * \li File DSN. This can be a QString::null to use default * location or it can be an abs directory. In either case the file * name itself will be derived from the Name property. * * \return bool * \retval true Hey - it worked :) * \retval false Call failed for some reason. Error message(s) is shown in message dialog. */ bool CODBCInst::saveDataSourceName( QWidget *pwidgetParent, HODBCINSTPROPERTY hFirstProperty, CDSNWizardData::Type nType, const QString &stringIni ) { // sanity checks... if ( !hFirstProperty ) { QMessageBox::critical( pwidgetParent, QObject::tr( "ODBC Administrator" ), QObject::tr( "Programmer error: Uninitialized property list." ) ); return false; } if ( (QString( hFirstProperty->szValue )).simplified().isEmpty() ) { QMessageBox::critical( pwidgetParent, QObject::tr( "ODBC Administrator" ), QObject::tr( "Missing 'Name' property value." ) ); return false; } // init UWORD nConfigMode = ODBC_BOTH_DSN; bool bReturn = false; QString stringFileName = stringIni; switch ( nType ) { case CDSNWizardData::TypeUser: SQLGetConfigMode( &nConfigMode ); SQLSetConfigMode( ODBC_USER_DSN ); if ( stringFileName.isEmpty() ) stringFileName = "odbc.ini"; break; case CDSNWizardData::TypeSystem: SQLGetConfigMode( &nConfigMode ); SQLSetConfigMode( ODBC_SYSTEM_DSN ); if ( stringFileName.isEmpty() ) stringFileName = "odbc.ini"; break; case CDSNWizardData::TypeFile: // should we calc the dir and file name (do not allow the special purpose names)... if ( stringFileName.isEmpty() || stringFileName.at( 0 ) != QChar( '/' ) ) { char szDirectory[FILENAME_MAX]; szDirectory[0] = '\0'; _odbcinst_FileINI( szDirectory ); stringFileName = QString( "%1/%2.dsn" ).arg( szDirectory ).arg( hFirstProperty->szValue ); } else if ( stringFileName.at( 0 ) == QChar( '/' ) ) stringFileName = QString( "%1/%2.dsn" ).arg( stringFileName ).arg( hFirstProperty->szValue ); else { QMessageBox::critical( pwidgetParent, QObject::tr( "ODBC Administrator" ), QObject::tr( "File DSN directory expected but seems to be a name or file name." ) ); return false; } break; default: QMessageBox::critical( pwidgetParent, QObject::tr( "ODBC Administrator" ), QObject::tr( "Unhandled Data Source Name Type" ) ); return false; } // save... if ( nType == CDSNWizardData::TypeFile ) { // create the file with a section called "ODBC"... if ( !SQLWriteFileDSN( stringFileName.toAscii().data(), "ODBC", NULL, NULL ) ) { showErrors( 0, QString( "Could not write to (%1)" ).arg( stringFileName ) ); goto CODBCInstExit1; } // add all of the properties... for ( HODBCINSTPROPERTY hCurProperty = hFirstProperty->pNext; hCurProperty != NULL; hCurProperty = hCurProperty->pNext ) { if ( !SQLWriteFileDSN( stringFileName.toAscii().data(), "ODBC", hCurProperty->szName, hCurProperty->szValue ) ) { showErrors( 0, QString( "Could not write to (%1)" ).arg( stringFileName ) ); goto CODBCInstExit1; } } } else { // create a section called using Name property (always 1st property)... if ( SQLWritePrivateProfileString( hFirstProperty->szValue, NULL, NULL, stringFileName.toAscii().data() ) == FALSE ) { showErrors( pwidgetParent, QString( QObject::tr( "Could not write to (%1). You may need additional system privileges." ) ).arg( stringFileName ) ); goto CODBCInstExit1; } // add all of the properties... for ( HODBCINSTPROPERTY hCurProperty = hFirstProperty->pNext; hCurProperty != NULL; hCurProperty = hCurProperty->pNext ) { SQLWritePrivateProfileString( hFirstProperty->szValue, hCurProperty->szName, hCurProperty->szValue, stringFileName.toAscii().data() ); } } bReturn = true; // fini CODBCInstExit1: if ( nType != CDSNWizardData::TypeFile ) SQLSetConfigMode( nConfigMode ); return bReturn; }
bool CPropSheet::UpdateDSN( void ) { char* lpszDSN; char szBuf[ _MAX_PATH]; lpszDSN = aAttr[ KEY_DSN].szAttr; // if the data source name has changed, remove the old name if( !bNewDSN && strcmp( szDSN, lpszDSN) != 0) { SQLRemoveDSNFromIni( szDSN); // remove File Data Source Name DeleteFileDSN( szDSN ); } if(strcmp( szDSN, lpszDSN )!=0) { WritePrivateProfileString( lpszDSN, INI_KDESC, aAttr[ KEY_DESC].szAttr, ODBC_INI); WritePrivateProfileString( lpszDSN, INI_KSN, aAttr[ KEY_SERVICE_NAME].szAttr, ODBC_INI); // update File DSN lstrcpy(szBuf, lpszDSN ); lstrcat(szBuf, " (not sharable)"); SQLWriteFileDSN( szBuf, "ODBC", "DSN", lpszDSN ); SQLWritePrivateProfileString( lpszDSN, INI_KDESC, aAttr[ KEY_DESC].szAttr, ODBC_INI); SQLWritePrivateProfileString( lpszDSN, INI_KSN, aAttr[ KEY_SERVICE_NAME].szAttr, ODBC_INI); } // write data source name if( !SQLWriteDSNToIni( lpszDSN, lpszDrvr)) { char szMsg[ MAXPATHLEN]; CString szBuf; szBuf.LoadString(IDS_BADDSN); wsprintf( szMsg, szBuf, lpszDSN); AfxMessageBox( szMsg); return FALSE; } // update ODBC.INI // save the value if the data source is new, edited, or explicitly supplied WritePrivateProfileString( lpszDSN, INI_KDESC, aAttr[ KEY_DESC].szAttr, ODBC_INI); WritePrivateProfileString( lpszDSN, INI_KSN, aAttr[ KEY_SERVICE_NAME].szAttr, ODBC_INI); // update File DSN lstrcpy(szBuf, lpszDSN ); lstrcat(szBuf, " (not sharable)"); SQLWriteFileDSN( szBuf, "ODBC", "DSN", lpszDSN ); SQLWritePrivateProfileString( lpszDSN, INI_KDESC, aAttr[ KEY_DESC].szAttr, ODBC_INI); SQLWritePrivateProfileString( lpszDSN, INI_KSN, aAttr[ KEY_SERVICE_NAME].szAttr, ODBC_INI); // the following are the localization (internationalization) attributes WritePrivateProfileString( lpszDSN, INI_ERRORLANG, aAttr[ KEY_ERRORLANG].szAttr, ODBC_INI); SQLWritePrivateProfileString( lpszDSN, INI_ERRORLANG, aAttr[ KEY_ERRORLANG].szAttr, ODBC_INI); WritePrivateProfileString( lpszDSN, INI_DATALANG, aAttr[ KEY_DATALANG].szAttr, ODBC_INI); SQLWritePrivateProfileString( lpszDSN, INI_DATALANG, aAttr[ KEY_DATALANG].szAttr, ODBC_INI); // Association Service (IP Address and Port Number) wsprintf(szBuf, "%s%s/%s", TCP_STR, aAttr[ KEY_IPADDRESS].szAttr, aAttr[ KEY_PORTNUM].szAttr); WritePrivateProfileString( lpszDSN, INI_NETWORK, szBuf, ODBC_INI); SQLWritePrivateProfileString( lpszDSN, INI_NETWORK, szBuf, ODBC_INI); WritePrivateProfileString( lpszDSN, INI_LOGIN, aAttr[ KEY_LOGIN].szAttr, ODBC_INI); SQLWritePrivateProfileString( lpszDSN, INI_LOGIN, aAttr[ KEY_LOGIN].szAttr, ODBC_INI); WritePrivateProfileString( lpszDSN, INI_CONNECTION, aAttr[ KEY_CONNECTION].szAttr, ODBC_INI); SQLWritePrivateProfileString( lpszDSN, INI_CONNECTION, aAttr[ KEY_CONNECTION].szAttr, ODBC_INI); WritePrivateProfileString( lpszDSN, INI_QUERY, aAttr[ KEY_QUERY].szAttr, ODBC_INI); SQLWritePrivateProfileString( lpszDSN, INI_QUERY, aAttr[ KEY_QUERY].szAttr, ODBC_INI); WritePrivateProfileString( lpszDSN, INI_CATALOG, aAttr[ KEY_CATALOG].szAttr, ODBC_INI); SQLWritePrivateProfileString( lpszDSN, INI_CATALOG, aAttr[ KEY_CATALOG].szAttr, ODBC_INI); WritePrivateProfileString( lpszDSN, INI_SCHEMA, aAttr[ KEY_SCHEMA].szAttr, ODBC_INI); SQLWritePrivateProfileString( lpszDSN, INI_SCHEMA, aAttr[ KEY_SCHEMA].szAttr, ODBC_INI); WritePrivateProfileString( lpszDSN, INI_TRANSLATION_DLL, aAttr[ KEY_TRANSLATION_DLL].szAttr, ODBC_INI); SQLWritePrivateProfileString( lpszDSN, INI_TRANSLATION_DLL, aAttr[ KEY_TRANSLATION_DLL].szAttr, ODBC_INI); WritePrivateProfileString( lpszDSN, INI_TRANSLATION_OPTION, aAttr[ KEY_TRANSLATION_OPTION].szAttr, ODBC_INI); SQLWritePrivateProfileString( lpszDSN, INI_TRANSLATION_OPTION, aAttr[ KEY_TRANSLATION_OPTION].szAttr, ODBC_INI); WritePrivateProfileString( lpszDSN, INI_FETCH_BUFFER_SIZE, aAttr[ KEY_FETCH_BUFFER_SIZE].szAttr, ODBC_INI); SQLWritePrivateProfileString( lpszDSN, INI_FETCH_BUFFER_SIZE, aAttr[ KEY_FETCH_BUFFER_SIZE].szAttr, ODBC_INI); WritePrivateProfileString( lpszDSN, INI_REPLACEMENT_CHAR, aAttr[ KEY_REPLACEMENT_CHAR].szAttr, ODBC_INI); SQLWritePrivateProfileString( lpszDSN, INI_REPLACEMENT_CHAR, aAttr[ KEY_REPLACEMENT_CHAR].szAttr, ODBC_INI); WritePrivateProfileString( lpszDSN, INI_COMPRESSION, aAttr[ KEY_COMPRESSION].szAttr, ODBC_INI); SQLWritePrivateProfileString( lpszDSN, INI_COMPRESSION, aAttr[ KEY_COMPRESSION].szAttr, ODBC_INI); WriteTraceRegistry( INI_TRACE_FILE,aAttr[ KEY_TRACE_FILE].szAttr); WriteTraceRegistry( INI_TRACE_FLAGS,aAttr[ KEY_TRACE_FLAGS].szAttr); return TRUE; }
void CFileList::Edit() { // odbc.ini INFO QString qsDataSourceName = ""; QString qsDataSourceDescription = ""; QString qsDataSourceDriver = ""; // odbcinst.ini INFO QString qsDriverFile = ""; QString qsSetupFile = ""; QString qsError = ""; CPropertiesFrame *pProperties; HODBCINSTPROPERTY hFirstProperty = NULL; HODBCINSTPROPERTY hCurProperty = NULL; #ifdef QT_V4LAYOUT Q3ListViewItem *pListViewItem; #else QListViewItem *pListViewItem; #endif char szEntryNames[4096]; char szProperty[INI_MAX_PROPERTY_NAME+1]; char szValue[INI_MAX_PROPERTY_VALUE+1]; DWORD nErrorCode; char szErrorMsg[101]; char szINI[FILENAME_MAX+1]; int nElement; char dir[ 256 ]; char szDriver[ 256 ]; QString qsFileName; // HAS THE USER SELECTED SOMETHING pListViewItem = currentItem(); if ( pListViewItem ) { qsFileName = pListViewItem->text( 0 ); /* qsDataSourceDescription = pListViewItem->text( 1 ); qsDataSourceDriver = pListViewItem->text( 2 ); */ } else { QMessageBox::information( this, "ODBC Config", "Please select a Data Source from the list first" ); return; } sprintf( dir, "%s/%s", cwd.ascii(), qsFileName.ascii()); szDriver[ 0 ] = '\0'; if ( !SQLReadFileDSN( dir, "ODBC", "DRIVER", szDriver, sizeof( szDriver ), NULL ) || strlen( szDriver ) < 1 ) { char szDsn[ 256 ]; szDsn[ 0 ] = '\0'; if ( SQLReadFileDSN( dir, "ODBC", "DSN", szDsn, sizeof( szDsn ), NULL ) && strlen( szDsn ) >= 1 ) { SQLSetConfigMode( ODBC_BOTH_DSN ); SQLGetPrivateProfileString( szDsn, "Driver", "", szDriver, sizeof( szDriver ), "odbc.ini" ); if ( strlen( szDriver ) < 1 ) { QMessageBox::information( this, "ODBC Config", "Unable to extract driver from FILE DSN" ); return; } } else { QMessageBox::information( this, "ODBC Config", "Unable to extract driver from FILE DSN" ); return; } } // // can we call SQLDriverConnect // // GET PROPERTY LIST FROM DRIVER if ( ODBCINSTConstructProperties( szDriver, &hFirstProperty ) != ODBCINST_SUCCESS ) { qsError.sprintf( "Could not construct a property list for (%s)", szDriver ); QMessageBox::information( this, "ODBC Config", qsError ); int i = 1; while ( SQLInstallerError( i ++, &nErrorCode, szErrorMsg, 100, NULL ) == SQL_SUCCESS ) QMessageBox::information( this, "ODBC Config", szErrorMsg ); return; } ODBCINSTSetProperty( hFirstProperty, "Name", (char*)qsFileName.ascii()); for ( hCurProperty = hFirstProperty->pNext; hCurProperty != NULL; hCurProperty = hCurProperty->pNext ) { char szAttr[ 256 ]; szAttr[ 0 ] = '\0'; if ( SQLReadFileDSN( dir, "ODBC", hCurProperty->szName, szAttr, sizeof( szAttr ), NULL )) { ODBCINSTSetProperty( hFirstProperty, hCurProperty->szName, szAttr ); } } // ALLOW USER TO EDIT pProperties = new CPropertiesFrame( this, "Properties", hFirstProperty ); pProperties->setCaption( "Data Source Properties (edit)" ); if ( pProperties->exec() ) { int ret; ret = SQLWriteFileDSN( dir, "ODBC", NULL, NULL ); if ( !ret ) { qsError.sprintf( "Could not write to (%s)", dir ); QMessageBox::information( this, "ODBC Config", qsError ); int i = 1; while ( SQLInstallerError( i++, &nErrorCode, szErrorMsg, 100, NULL ) == SQL_SUCCESS ) QMessageBox::information( this, "ODBC Config", szErrorMsg ); return; } for ( hCurProperty = hFirstProperty->pNext; hCurProperty != NULL; hCurProperty = hCurProperty->pNext ) { if ( !SQLWriteFileDSN( dir, "ODBC", hCurProperty->szName, hCurProperty->szValue )) { qsError.sprintf( "Could not write to file dsn (%s)", dir ); QMessageBox::information( this, "ODBC Config", qsError ); int i = 1; while ( SQLInstallerError( i ++, &nErrorCode, szErrorMsg, 100, NULL ) == SQL_SUCCESS ) QMessageBox::information( this, "ODBC Config", szErrorMsg ); return; } } } delete pProperties; ODBCINSTDestructProperties( &hFirstProperty ); // RELOAD (slow but safe) Load(); }
void CFileList::Add() { // odbc.ini INFO /* QString qsDataSourceName = ""; QString qsDataSourceDescription = ""; */ QString qsDataSourceDriver = ""; QString qsDriverName = ""; CDriverPrompt *pDriverPrompt; CPropertiesFrame *pProperties; HODBCINSTPROPERTY hFirstProperty = NULL; HODBCINSTPROPERTY hCurProperty = NULL; DWORD nErrorCode; char szErrorMsg[101]; QString qsError = ""; int ret; pDriverPrompt = new CDriverPrompt( this ); if ( pDriverPrompt->exec() ) { qsDriverName = pDriverPrompt->qsDriverName; qsDataSourceDriver = qsDriverName; delete pDriverPrompt; // // can we call SQLDriverConnect // // GET PROPERTY LIST FROM DRIVER if ( ODBCINSTConstructProperties( (char*)qsDataSourceDriver.ascii(), &hFirstProperty ) != ODBCINST_SUCCESS ) { qsError.sprintf( "Could not construct a property list for (%s)", qsDataSourceDriver.ascii() ); QMessageBox::information( this, "ODBC Config", qsError ); return; } // ALLOW USER TO EDIT pProperties = new CPropertiesFrame( this, "Properties", hFirstProperty ); pProperties->setCaption( "Data Source Properties (new)" ); if ( pProperties->exec() ) { char dir[ 256 ]; sprintf( dir, "%s/%s", cwd.ascii(), hFirstProperty->szValue ); ret = SQLWriteFileDSN( dir, "ODBC", NULL, NULL ); if ( !ret ) { qsError.sprintf( "Could not write to (%s)", dir ); QMessageBox::information( this, "ODBC Config", qsError ); int i = 1; while ( SQLInstallerError( i++, &nErrorCode, szErrorMsg, 100, NULL ) == SQL_SUCCESS ) QMessageBox::information( this, "ODBC Config", szErrorMsg ); return; } /* ADD ENTRIES; SECTION CREATED ON FIRST CALL */ for ( hCurProperty = hFirstProperty->pNext; hCurProperty != NULL; hCurProperty = hCurProperty->pNext ) { ret = SQLWriteFileDSN( dir, "ODBC", hCurProperty->szName, hCurProperty->szValue ); if ( !ret ) { qsError.sprintf( "Could not write to (%s)", dir ); QMessageBox::information( this, "ODBC Config", qsError ); int i = 1; while ( SQLInstallerError( i++, &nErrorCode, szErrorMsg, 100, NULL ) == SQL_SUCCESS ) QMessageBox::information( this, "ODBC Config", szErrorMsg ); return; } } } delete pProperties; ODBCINSTDestructProperties( &hFirstProperty ); } else delete pDriverPrompt; // RELOAD (slow but safe) Load(); }
static void filedsn_configure (TDSNCHOOSER *choose_t, char *drv, char *dsn, char *in_attrs, BOOL b_add, BOOL verify_conn) { char *connstr = NULL; size_t len; /* current connstr len */ size_t add_len; /* len of appended string */ LPSTR attrs = NULL, curr, tmp, attr_lst = NULL; BOOL b_Save = TRUE; attrs = in_attrs; if (!b_add && !_CheckDriverLoginDlg(drv + STRLEN("DRIVER="))) { /* Get DSN name and additional attributes */ attr_lst = create_gensetup (choose_t->mainwnd, dsn, in_attrs, b_add, &verify_conn); attrs = attr_lst; } if (!attrs) { create_error (choose_t->mainwnd, NULL, "Error adding File DSN:", strerror (ENOMEM)); return; } if (attrs == (LPSTR) - 1L) return; /* Build the connection string */ connstr = strdup (drv); len = strlen (connstr); for (curr = attrs; *curr; curr += (STRLEN (curr) + 1)) { if (!strncasecmp (curr, "DSN=", STRLEN ("DSN="))) { if (dsn == NULL) { /* got dsn name */ dsn = curr + STRLEN ("DSN="); } continue; } /* append attr */ add_len = 1 + strlen (curr); /* +1 for ';' */ tmp = realloc (connstr, len + add_len + 1); /* +1 for NUL */ if (tmp == NULL) { create_error (choose_t->mainwnd, NULL, "Error adding File DSN:", strerror (errno)); goto done; } connstr = tmp; snprintf (connstr + len, add_len + 1, ";%s", curr); len += add_len; } /* Nothing to do if no DSN */ if (!dsn || STRLEN (dsn) == 0) goto done; if (verify_conn) { BOOL ret; /* Append SAVEFILE */ add_len = strlen (";SAVEFILE=") + strlen (dsn); tmp = realloc (connstr, len + add_len + 1); /* +1 for NUL */ if (tmp == NULL) { create_error (choose_t->mainwnd, NULL, "Error adding file DSN:", strerror (errno)); goto done; } connstr = tmp; snprintf (connstr + len, add_len + 1, ";SAVEFILE=%s", dsn); len += add_len; /* Connect to data source */ ret = test_driver_connect (choose_t, connstr); if (!ret && b_add) { if (create_confirm (choose_t->mainwnd, dsn, "Can't check the connection. Do you want to store the FileDSN without verification ?")) b_Save = TRUE; else b_Save = FALSE; } else b_Save = FALSE; } if (b_Save) { char key[512]; char *p; size_t sz; if (drv) { p = strchr(drv, '='); if (!SQLWriteFileDSN (dsn, "ODBC", "DRIVER", p + 1)) { create_error (choose_t->mainwnd, NULL, "Error adding File DSN:", strerror (errno)); goto done; } } for (curr = attrs; *curr; curr += (STRLEN (curr) + 1)) { if (!strncasecmp (curr, "DSN=", STRLEN ("DSN="))) continue; else if (!strncasecmp (curr, "PWD=", STRLEN ("PWD="))) continue; else if (!strncasecmp (curr, "SAVEFILE=", STRLEN ("SAVEFILE="))) continue; else if (!strncasecmp (curr, "FILEDSN=", STRLEN ("FILEDSN="))) continue; p = strchr(curr, '='); sz = p - curr < sizeof(key) ? p - curr : sizeof(key); memset(key, 0, sizeof(key)); strncpy(key, curr, sz); if (!SQLWriteFileDSN (dsn, "ODBC", key, p + 1)) { create_error (choose_t->mainwnd, NULL, "Error adding File DSN:", strerror (errno)); goto done; } } } done: if (attr_lst != NULL) free (attr_lst); if (connstr != NULL) free (connstr); }