pascal OSStatus filedsn_add_clicked (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData) { TDSNCHOOSER *choose_t = (TDSNCHOOSER *) inUserData; DataBrowserItemID first, last; OSStatus err; SQLCHAR drv[1024] = { 0 }; LPSTR s, attrs; TFDRIVERCHOOSER drvchoose_t; if (!choose_t) return noErr; /* Try first to get the driver name */ SQLSetConfigMode (ODBC_USER_DSN); drvchoose_t.attrs = NULL; drvchoose_t.dsn = NULL; drvchoose_t.driver = NULL; drvchoose_t.curr_dir = choose_t->curr_dir; create_fdriverchooser (choose_t->mainwnd, &drvchoose_t); /* Check output parameters */ if (drvchoose_t.ok) { if (sizeof(drv) > WCSLEN(drvchoose_t.driver) + strlen("DRIVER=")) { s = strcpy(drv, "DRIVER="); s += strlen("DRIVER="); dm_strcpy_W2A(s, drvchoose_t.driver); attrs = drvchoose_t.attrs; filedsn_configure(choose_t, drv, drvchoose_t.dsn, attrs ? attrs :"\0\0", TRUE, drvchoose_t.verify_conn); addfdsns_to_list (choose_t, choose_t->curr_dir, true); } } if (drvchoose_t.driver) free (drvchoose_t.driver); if (drvchoose_t.attrs) free (drvchoose_t.attrs); if (drvchoose_t.dsn) free (drvchoose_t.dsn); if ((err = GetDataBrowserSelectionAnchor (choose_t->fdsnlist, &first, &last)) == noErr) { if (!first && !last) { DeactivateControl (choose_t->fremove); DeactivateControl (choose_t->fconfigure); DeactivateControl (choose_t->ftest); } } return noErr; }
static BOOL test_driver_connect (TDSNCHOOSER *choose_t, char *connstr) { HENV henv; HDBC hdbc; #if (ODBCVER < 0x300) if (SQLAllocEnv (&henv) != SQL_SUCCESS) #else if (SQLAllocHandle (SQL_HANDLE_ENV, NULL, &henv) != SQL_SUCCESS) #endif { _iodbcdm_nativeerrorbox (choose_t->mainwnd, henv, SQL_NULL_HDBC, SQL_NULL_HSTMT); return FALSE; } #if (ODBCVER < 0x300) if (SQLAllocConnect (henv, &hdbc) != SQL_SUCCESS) #else SQLSetEnvAttr (henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER); if (SQLAllocHandle (SQL_HANDLE_DBC, henv, &hdbc) != SQL_SUCCESS) #endif { _iodbcdm_nativeerrorbox (choose_t->mainwnd, henv, hdbc, SQL_NULL_HSTMT); SQLFreeEnv (henv); return FALSE; } SQLSetConfigMode (ODBC_BOTH_DSN); if (SQLDriverConnect (hdbc, choose_t->mainwnd, connstr, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_PROMPT) != SQL_SUCCESS) { _iodbcdm_nativeerrorbox (choose_t->mainwnd, henv, hdbc, SQL_NULL_HSTMT); SQLFreeEnv (henv); return FALSE; } else { SQLDisconnect (hdbc); } #if (ODBCVER < 0x300) SQLFreeConnect (hdbc); SQLFreeEnv (henv); #else SQLFreeHandle (SQL_HANDLE_DBC, hdbc); SQLFreeHandle (SQL_HANDLE_ENV, henv); #endif return TRUE; }
void COdbcDS::RetrieveMxDSInfo(int iType, CDSList& DSList) { TCHAR Buff[255]; char* DSName = NULL; int count = DSList.getCount(); int length = sizeof(PRIV_PROFILE) / MAXKEYLEN; // Set the config mode to the desired type. UWORD oldMode, newMode; if (iType == COdbcDS::DS_TYPE_SYS) { newMode = ODBC_SYSTEM_DSN; } else { newMode = ODBC_USER_DSN; } SQLGetConfigMode(&oldMode); SQLSetConfigMode(newMode); for (int i = 0; i < count; i++) { DSName = DSList.getAt(i); for(int index = 0; index < length; index++) { // Retrieve the private profile strings. SQLGetPrivateProfileString(DSName, PRIV_PROFILE[index], "", Buff, sizeof(Buff), ODBC_INI); DSList.addAttrib(i, PRIV_PROFILE[index], Buff); } delete [] DSName; } // Restore old config mode. SQLSetConfigMode(oldMode); }
void classDataSources::setOpen( bool bOpen ) { int nElement; char szResults[9600]; char szObjectName[INI_MAX_OBJECT_NAME+1]; memset( szResults, 0, sizeof(szResults) ); // Results buffer must be cleared classDataSource *pLastDataSource = NULL; if ( bOpen ) { memset( szResults, 0, sizeof(szResults) ); if ( nDataSourceType == User ) SQLSetConfigMode( ODBC_USER_DSN ); else SQLSetConfigMode( ODBC_SYSTEM_DSN ); if ( SQLGetPrivateProfileString( 0, 0, 0, szResults, 9600, 0 ) > 0 ) { for ( nElement = 0; iniElement( szResults, '\0', '\0', nElement, szObjectName, INI_MAX_OBJECT_NAME ) == INI_SUCCESS; nElement++ ) { listDataSources.append( pLastDataSource = new classDataSource( this, pLastDataSource, pCanvas, nDataSourceType, szObjectName, hEnv ) ); } } else { //SQLInstallerError( 1, &nError, szError, FILENAME_MAX, 0 ); //if ( cVerbose == 0 ) printf( "[odbcinst] SQLGetPrivateProfileString failed with %s.\n", szError ); //return; } SQLSetConfigMode( ODBC_BOTH_DSN ); } else { listDataSources.clear(); } QListViewItem::setOpen( bOpen ); }
void InitializeTrace() { //Read Trace Flag and TraceDLL char szTraceFlags[100]; char szTraceDll[_MAX_PATH+1]; UWORD wConfigMode; if (g_hTraceDLL != NULL && GetModuleHandle(TRACE_DLL_NAME) == g_hTraceDLL){ if(fpTraceProcessEntry) pdwGlobalTraceVariable = fpTraceProcessEntry(); return; } SQLGetConfigMode( &wConfigMode); SQLSetConfigMode( ODBC_USER_DSN); SQLGetPrivateProfileString(szODBC, szTraceDllKey, szDefaultTraceDll, szTraceDll, sizeof(szTraceDll), szODBCIni); // // ODBC DM 3.52 works only with HKEY_CURRENT_USER // /* if ((g_hTraceDLL = GetModuleHandle(szTraceDll)) == NULL) { SQLSetConfigMode( ODBC_SYSTEM_DSN); SQLGetPrivateProfileString(szODBC, szTraceDllKey, szDefaultTraceDll, szTraceDll, sizeof(szTraceDll), szODBCIni); if ((g_hTraceDLL = GetModuleHandle(szTraceDll)) == NULL) { SQLSetConfigMode( wConfigMode); return; } } */ SQLGetPrivateProfileString(szODBC, szTraceFlagsKey, szDefaultTraceFlags, szTraceFlags, sizeof(szTraceFlags), szODBCIni); SQLSetConfigMode( wConfigMode); gTraceFlags = atol(szTraceFlags); if ((g_hTraceDLL = GetModuleHandle(TRACE_DLL_NAME)) != NULL) { fpTraceProcessEntry = (FPTraceProcessEntry) GetProcAddress(g_hTraceDLL, "TraceProcessEntry"); fpTraceDebugOut = (FPTraceDebugOut) GetProcAddress(g_hTraceDLL, "TraceDebugOut"); fpTracePrintMarker = (FPTracePrintMarker) GetProcAddress(g_hTraceDLL, "TracePrintMarker"); fpTraceFirstEntry = (FPTraceFirstEntry) GetProcAddress(g_hTraceDLL, "TraceFirstEntry"); fpTraceReturn = (FPTraceReturn) GetProcAddress(g_hTraceDLL, "TraceReturn"); fpTraceSQLAllocHandle = (FPTraceSQLAllocHandle) GetProcAddress(g_hTraceDLL, "TraceSQLAllocHandle"); fpTraceSQLBindCol = (FPTraceSQLBindCol) GetProcAddress(g_hTraceDLL, "TraceSQLBindCol"); fpTraceSQLBindParameter = (FPTraceSQLBindParameter) GetProcAddress(g_hTraceDLL, "TraceSQLBindParameter"); fpTraceSQLCancel = (FPTraceSQLCancel) GetProcAddress(g_hTraceDLL, "TraceSQLCancel"); fpTraceSQLCloseCursor = (FPTraceSQLCloseCursor) GetProcAddress(g_hTraceDLL, "TraceSQLCloseCursor"); fpTraceSQLCopyDesc = (FPTraceSQLCopyDesc) GetProcAddress(g_hTraceDLL, "TraceSQLCopyDesc"); fpTraceSQLDescribeParam = (FPTraceSQLDescribeParam) GetProcAddress(g_hTraceDLL, "TraceSQLDescribeParam"); fpTraceSQLDisconnect = (FPTraceSQLDisconnect) GetProcAddress(g_hTraceDLL, "TraceSQLDisconnect"); fpTraceSQLEndTran = (FPTraceSQLEndTran) GetProcAddress(g_hTraceDLL, "TraceSQLEndTran"); fpTraceSQLExecute = (FPTraceSQLExecute) GetProcAddress(g_hTraceDLL, "TraceSQLExecute"); fpTraceSQLExtendedFetch = (FPTraceSQLExtendedFetch) GetProcAddress(g_hTraceDLL, "TraceSQLExtendedFetch"); fpTraceSQLFetch = (FPTraceSQLFetch) GetProcAddress(g_hTraceDLL, "TraceSQLFetch"); fpTraceSQLFetchScroll = (FPTraceSQLFetchScroll) GetProcAddress(g_hTraceDLL, "TraceSQLFetchScroll"); fpTraceSQLFreeHandle = (FPTraceSQLFreeHandle) GetProcAddress(g_hTraceDLL, "TraceSQLFreeHandle"); fpTraceSQLFreeStmt = (FPTraceSQLFreeStmt) GetProcAddress(g_hTraceDLL, "TraceSQLFreeStmt"); fpTraceSQLGetData = (FPTraceSQLGetData) GetProcAddress(g_hTraceDLL, "TraceSQLGetData"); fpTraceSQLGetEnvAttr = (FPTraceSQLGetEnvAttr) GetProcAddress(g_hTraceDLL, "TraceSQLGetEnvAttr"); fpTraceSQLGetTypeInfo = (FPTraceSQLGetTypeInfo) GetProcAddress(g_hTraceDLL, "TraceSQLGetTypeInfo"); fpTraceSQLMoreResults = (FPTraceSQLMoreResults) GetProcAddress(g_hTraceDLL, "TraceSQLMoreResults"); fpTraceSQLNumParams = (FPTraceSQLNumParams) GetProcAddress(g_hTraceDLL, "TraceSQLNumParams"); fpTraceSQLNumResultCols = (FPTraceSQLNumResultCols) GetProcAddress(g_hTraceDLL, "TraceSQLNumResultCols"); fpTraceSQLParamData = (FPTraceSQLParamData) GetProcAddress(g_hTraceDLL, "TraceSQLParamData"); fpTraceSQLPutData = (FPTraceSQLPutData) GetProcAddress(g_hTraceDLL, "TraceSQLPutData"); fpTraceSQLRowCount = (FPTraceSQLRowCount) GetProcAddress(g_hTraceDLL, "TraceSQLRowCount"); fpTraceSQLSetEnvAttr = (FPTraceSQLSetEnvAttr) GetProcAddress(g_hTraceDLL, "TraceSQLSetEnvAttr"); fpTraceSQLSetPos = (FPTraceSQLSetPos) GetProcAddress(g_hTraceDLL, "TraceSQLSetPos"); fpTraceASVersion = (VERSION_def**) GetProcAddress(g_hTraceDLL, "ASVersion"); fpTraceSrvrVersion = (VERSION_def**) GetProcAddress(g_hTraceDLL, "SrvrVersion"); fpTraceSqlVersion = (VERSION_def**) GetProcAddress(g_hTraceDLL, "SqlVersion"); fpTraceTransportIn = (FPTraceTransportIn) GetProcAddress(g_hTraceDLL, "TraceTransportIn"); fpTraceTransportOut = (FPTraceTransportOut) GetProcAddress(g_hTraceDLL, "TraceTransportOut"); fpTraceSQLSetDescRec = (FPTraceSQLSetDescRec) GetProcAddress(g_hTraceDLL, "TraceSQLSetDescRec"); //Unicode functions fpTraceSQLGetDiagRecW = (FPTraceSQLGetDiagRecW) GetProcAddress(g_hTraceDLL, "TraceSQLGetDiagRecW"); fpTraceSQLGetDiagFieldW = (FPTraceSQLGetDiagFieldW) GetProcAddress(g_hTraceDLL, "TraceSQLGetDiagFieldW"); fpTraceSQLConnectW = (FPTraceSQLConnectW) GetProcAddress(g_hTraceDLL, "TraceSQLConnectW"); fpTraceSQLSetConnectAttrW = (FPTraceSQLSetConnectAttrW) GetProcAddress(g_hTraceDLL, "TraceSQLSetConnectAttrW"); fpTraceSQLGetConnectAttrW = (FPTraceSQLGetConnectAttrW) GetProcAddress(g_hTraceDLL, "TraceSQLGetConnectAttrW"); fpTraceSQLSetStmtAttrW = (FPTraceSQLSetStmtAttrW) GetProcAddress(g_hTraceDLL, "TraceSQLSetStmtAttrW"); fpTraceSQLGetStmtAttrW = (FPTraceSQLGetStmtAttrW) GetProcAddress(g_hTraceDLL, "TraceSQLGetStmtAttrW"); fpTraceSQLGetInfoW = (FPTraceSQLGetInfoW) GetProcAddress(g_hTraceDLL, "TraceSQLGetInfoW"); fpTraceSQLSetDescFieldW = (FPTraceSQLSetDescFieldW) GetProcAddress(g_hTraceDLL, "TraceSQLSetDescFieldW"); fpTraceSQLGetDescFieldW = (FPTraceSQLGetDescFieldW) GetProcAddress(g_hTraceDLL, "TraceSQLGetDescFieldW"); fpTraceSQLGetDescRecW = (FPTraceSQLGetDescRecW) GetProcAddress(g_hTraceDLL, "TraceSQLGetDescRecW"); fpTraceSQLBrowseConnectW = (FPTraceSQLBrowseConnectW) GetProcAddress(g_hTraceDLL, "TraceSQLBrowseConnectW"); fpTraceSQLDriverConnectW = (FPTraceSQLDriverConnectW) GetProcAddress(g_hTraceDLL, "TraceSQLDriverConnectW"); fpTraceSQLPrepareW = (FPTraceSQLPrepareW) GetProcAddress(g_hTraceDLL, "TraceSQLPrepareW"); fpTraceSQLExecDirectW = (FPTraceSQLExecDirectW) GetProcAddress(g_hTraceDLL, "TraceSQLExecDirectW"); fpTraceSQLDescribeColW = (FPTraceSQLDescribeColW) GetProcAddress(g_hTraceDLL, "TraceSQLDescribeColW"); fpTraceSQLTablesW = (FPTraceSQLTablesW) GetProcAddress(g_hTraceDLL, "TraceSQLTablesW"); fpTraceSQLColumnsW = (FPTraceSQLColumnsW) GetProcAddress(g_hTraceDLL, "TraceSQLColumnsW"); fpTraceSQLSpecialColumnsW = (FPTraceSQLSpecialColumnsW) GetProcAddress(g_hTraceDLL, "TraceSQLSpecialColumnsW"); fpTraceSQLPrimaryKeysW = (FPTraceSQLPrimaryKeysW) GetProcAddress(g_hTraceDLL, "TraceSQLPrimaryKeysW"); fpTraceSQLStatisticsW = (FPTraceSQLStatisticsW) GetProcAddress(g_hTraceDLL, "TraceSQLStatisticsW"); fpTraceSQLGetCursorNameW = (FPTraceSQLGetCursorNameW) GetProcAddress(g_hTraceDLL, "TraceSQLGetCursorNameW"); fpTraceSQLSetCursorNameW = (FPTraceSQLSetCursorNameW) GetProcAddress(g_hTraceDLL, "TraceSQLSetCursorNameW"); fpTraceSQLNativeSqlW = (FPTraceSQLNativeSqlW) GetProcAddress(g_hTraceDLL, "TraceSQLNativeSqlW"); fpTraceSQLColAttributeW = (FPTraceSQLColAttributeW) GetProcAddress(g_hTraceDLL, "TraceSQLColAttributeW"); fpTraceSQLProceduresW = (FPTraceSQLProceduresW) GetProcAddress(g_hTraceDLL, "TraceSQLProceduresW"); fpTraceSQLProcedureColumnsW = (FPTraceSQLProcedureColumnsW) GetProcAddress(g_hTraceDLL, "TraceSQLProcedureColumnsW"); fpTraceSQLColumnPrivilegesW = (FPTraceSQLColumnPrivilegesW) GetProcAddress(g_hTraceDLL, "TraceSQLColumnPrivilegesW"); fpTraceSQLTablePrivilegesW = (FPTraceSQLTablePrivilegesW) GetProcAddress(g_hTraceDLL, "TraceSQLTablePrivilegesW"); fpTraceSQLForeignKeysW = (FPTraceSQLForeignKeysW) GetProcAddress(g_hTraceDLL, "TraceSQLForeignKeysW"); } if(fpTraceProcessEntry) pdwGlobalTraceVariable = fpTraceProcessEntry(); }
BOOL INSTAPI ConfigDSN ( HWND hwndParent, WORD fRequest, LPCSTR lpszDriver, LPCSTR lpszAttributes) { char *dsn = NULL, *connstr = NULL, *curr, *cour = NULL; char dsnread[4096] = { 0 }; char prov[4096] = { 0 }; int driver_type = -1, flags = 0; BOOL retcode = FALSE; UWORD confMode = ODBC_USER_DSN; /* Map the request User/System */ if (fRequest < ODBC_ADD_DSN || fRequest > ODBC_REMOVE_DSN) { SQLPostInstallerError (ODBC_ERROR_INVALID_REQUEST_TYPE, NULL); goto done; } if (!lpszDriver || !STRLEN (lpszDriver)) { SQLPostInstallerError (ODBC_ERROR_INVALID_NAME, NULL); goto done; } /* Retrieve the config mode */ SQLGetConfigMode (&confMode); /* Retrieve the DSN if one exist */ for (curr = (LPSTR) lpszAttributes; curr && *curr; curr += (STRLEN (curr) + 1)) { if (!strncmp (curr, "DSN=", STRLEN ("DSN="))) { dsn = curr + STRLEN ("DSN="); break; } } /* Retrieve the corresponding driver */ if (strstr (lpszDriver, "OpenLink") || strstr (lpszDriver, "Openlink") || strstr (lpszDriver, "oplodbc")) { driver_type = 0; for (curr = (LPSTR) lpszAttributes, cour = prov; curr && *curr; curr += (STRLEN (curr) + 1), cour += (STRLEN (cour) + 1)) { if (!strncasecmp (curr, "Host=", STRLEN ("Host=")) && STRLEN (curr + STRLEN ("Host="))) { STRCPY (cour, curr); flags |= 0x1; continue; } if (!strncasecmp (curr, "ServerType=", STRLEN ("ServerType=")) && STRLEN (curr + STRLEN ("ServerType="))) { STRCPY (cour, curr); flags |= 0x2; continue; } STRCPY (cour, curr); } if (cour && !(flags & 1)) { STRCPY (cour, "Host=localhost\0"); cour += (STRLEN (cour) + 1); } if (cour && !(flags & 2)) { STRCPY (cour, "ServerType=Proxy\0"); cour += (STRLEN (cour) + 1); } if (cour) *cour = 0; } else if ((strstr (lpszDriver, "Virtuoso") || strstr (lpszDriver, "virtodbc"))) driver_type = 1; /* For each request */ switch (fRequest) { case ODBC_ADD_DSN: /* Check if the DSN with this name already exists */ SQLSetConfigMode (confMode); #ifdef WIN32 if (hwndParent && dsn && SQLGetPrivateProfileString ("ODBC 32 bit Data Sources", dsn, "", dsnread, sizeof (dsnread), NULL) && !create_confirm (hwndParent, dsn, "Are you sure you want to overwrite this DSN ?")) #else if (hwndParent && dsn && SQLGetPrivateProfileString ("ODBC Data Sources", dsn, "", dsnread, sizeof (dsnread), NULL) && !create_confirm (hwndParent, dsn, "Are you sure you want to overwrite this DSN ?")) #endif goto done; /* Call the right setup function */ connstr = create_gensetup (hwndParent, dsn, STRLEN (prov) ? prov : lpszAttributes, TRUE); /* Check output parameters */ if (!connstr) { SQLPostInstallerError (ODBC_ERROR_OUT_OF_MEM, NULL); goto done; } if (connstr == (LPSTR) - 1L) goto done; /* Add the DSN to the ODBC Data Sources */ SQLSetConfigMode (confMode); if (!SQLWriteDSNToIni (dsn = connstr + STRLEN ("DSN="), lpszDriver)) goto done; /* Add each keyword and values */ for (curr = connstr; *curr; curr += (STRLEN (curr) + 1)) { if (strncmp (curr, "DSN=", STRLEN ("DSN="))) { STRCPY (dsnread, curr); cour = strchr (dsnread, '='); if (cour) *cour = 0; SQLSetConfigMode (confMode); if (!SQLWritePrivateProfileString (dsn, dsnread, (cour && STRLEN (cour + 1)) ? cour + 1 : NULL, NULL)) goto done; } } break; case ODBC_CONFIG_DSN: if (!dsn || !STRLEN (dsn)) { SQLPostInstallerError (ODBC_ERROR_INVALID_KEYWORD_VALUE, NULL); goto done; } /* Call the right setup function */ connstr = create_gensetup (hwndParent, dsn, STRLEN (prov) ? prov : lpszAttributes, FALSE); /* Check output parameters */ if (!connstr) { SQLPostInstallerError (ODBC_ERROR_OUT_OF_MEM, NULL); goto done; } if (connstr == (LPSTR) - 1L) goto done; /* Compare if the DSN changed */ if (strcmp (connstr + STRLEN ("DSN="), dsn)) { /* Remove the previous DSN */ SQLSetConfigMode (confMode); if (!SQLRemoveDSNFromIni (dsn)) goto done; /* Add the new DSN section */ SQLSetConfigMode (confMode); if (!SQLWriteDSNToIni (dsn = connstr + STRLEN ("DSN="), lpszDriver)) goto done; } /* Add each keyword and values */ for (curr = connstr; *curr; curr += (STRLEN (curr) + 1)) { if (strncmp (curr, "DSN=", STRLEN ("DSN="))) { STRCPY (dsnread, curr); cour = strchr (dsnread, '='); if (cour) *cour = 0; SQLSetConfigMode (confMode); if (!SQLWritePrivateProfileString (dsn, dsnread, (cour && STRLEN (cour + 1)) ? cour + 1 : NULL, NULL)) goto done; } } break; case ODBC_REMOVE_DSN: if (!dsn || !STRLEN (dsn)) { SQLPostInstallerError (ODBC_ERROR_INVALID_KEYWORD_VALUE, NULL); goto done; } /* Just remove the DSN */ SQLSetConfigMode (confMode); if (!SQLRemoveDSNFromIni (dsn)) goto done; break; }; quit: retcode = TRUE; done: if (connstr && connstr != (LPSTR) - 1L && connstr != lpszAttributes && connstr != prov) free (connstr); return retcode; }
void addtranslators_to_list (GtkWidget *widget, GtkWidget *dlg) { char *curr, *buffer = (char *) malloc (sizeof (char) * 65536), *szDriver; char driver[1024], _date[1024], _size[1024]; char *data[4]; int len, i; BOOL careabout; UWORD confMode = ODBC_USER_DSN; struct stat _stat; if (!buffer || !GTK_IS_CLIST (widget)) return; gtk_clist_clear (GTK_CLIST (widget)); /* Get the current config mode */ while (confMode != ODBC_SYSTEM_DSN + 1) { /* Get the list of drivers in the user context */ SQLSetConfigMode (confMode); #ifdef WIN32 len = SQLGetPrivateProfileString ("ODBC 32 bit Translators", NULL, "", buffer, 65535, "odbcinst.ini"); #else len = SQLGetPrivateProfileString ("ODBC Translators", NULL, "", buffer, 65535, "odbcinst.ini"); #endif if (len) goto process; goto end; process: for (curr = buffer; *curr; curr += (STRLEN (curr) + 1)) { /* Shadowing system odbcinst.ini */ for (i = 0, careabout = TRUE; i < GTK_CLIST (widget)->rows; i++) { gtk_clist_get_text (GTK_CLIST (widget), i, 0, &szDriver); if (!strcmp (szDriver, curr)) { careabout = FALSE; break; } } if (!careabout) continue; SQLSetConfigMode (confMode); #ifdef WIN32 SQLGetPrivateProfileString ("ODBC 32 bit Translators", curr, "", driver, sizeof (driver), "odbcinst.ini"); #else SQLGetPrivateProfileString ("ODBC Translators", curr, "", driver, sizeof (driver), "odbcinst.ini"); #endif /* Check if the driver is installed */ if (strcasecmp (driver, "Installed")) goto end; /* Get the driver library name */ SQLSetConfigMode (confMode); if (!SQLGetPrivateProfileString (curr, "Translator", "", driver, sizeof (driver), "odbcinst.ini")) { SQLSetConfigMode (confMode); SQLGetPrivateProfileString ("Default", "Translator", "", driver, sizeof (driver), "odbcinst.ini"); } if (STRLEN (curr) && STRLEN (driver)) { data[0] = curr; data[1] = driver; /* Get some information about the driver */ if (!stat (driver, &_stat)) { sprintf (_size, "%lu Kb", (unsigned long) _stat.st_size / 1024L); sprintf (_date, "%s", ctime (&_stat.st_mtime)); data[2] = _date; data[3] = _size; gtk_clist_append (GTK_CLIST (widget), data); } } } end: if (confMode == ODBC_USER_DSN) confMode = ODBC_SYSTEM_DSN; else confMode = ODBC_SYSTEM_DSN + 1; } if (GTK_CLIST (widget)->rows > 0) { gtk_clist_columns_autosize (GTK_CLIST (widget)); gtk_clist_sort (GTK_CLIST (widget)); } /* Make the clean up */ free (buffer); }
OPL_LoginDialog::OPL_LoginDialog(CFStringRef resname, CFStringRef title): OPL_Dialog(resname), cur_dir(NULL), tab_number(-1) { OSStatus err; OPL_LoginDialog *dlg = this; SQLSetConfigMode (ODBC_BOTH_DSN); if (!SQLGetPrivateProfileString("ODBC", "FileDSNPath", "", def_path, sizeof(def_path), "odbcinst.ini")) #if defined(DEFAULT_FILEDSNPATH) strcpy(def_path, DEFAULT_FILEDSNPATH); #else strcpy(def_path, "/etc/ODBCDataSources"); #endif setTitle(title); getControl(kLoginTABS, &tab_panel); getControl(kLoginDSN_TAB, &tabs[0]); getControl(kLoginFDSN_TAB, &tabs[1]); getControl(kLoginDSNL, &dsnView); getControl(kLoginFDSNL, &fdsnView); // create instance data and associate it with the control dsnlist = new OPL_DSNList(dsnView); err = SetControlProperty(dsnView, kPropertyCreator, kPropertyTag, sizeof(dsnlist), &dsnlist); require_noerr(err, error); fdsnlist = new OPL_DSNList(fdsnView); err = SetControlProperty(fdsnView, kPropertyCreator, kPropertyTag, sizeof(fdsnlist), &fdsnlist); require_noerr(err, error); // set DSN browser callbacks DataBrowserCallbacks dsnViewCallbacks; dsnViewCallbacks.version = kDataBrowserLatestCallbacks; err = InitDataBrowserCallbacks(&dsnViewCallbacks); require_noerr(err, error); static DataBrowserItemDataUPP g_dsnItemDataUPP = NULL; if (!g_dsnItemDataUPP) { g_dsnItemDataUPP = NewDataBrowserItemDataUPP( OPL_DSNItemViewItemDataCallback); } dsnViewCallbacks.u.v1.itemDataCallback = g_dsnItemDataUPP; err = SetDataBrowserCallbacks(dsnView, &dsnViewCallbacks); require_noerr(err, error); // set FDSN browser callbacks DataBrowserCallbacks fdsnViewCallbacks; fdsnViewCallbacks.version = kDataBrowserLatestCallbacks; err = InitDataBrowserCallbacks(&fdsnViewCallbacks); require_noerr(err, error); static DataBrowserItemDataUPP g_fdsnItemDataUPP = NULL; if (!g_fdsnItemDataUPP) { g_fdsnItemDataUPP = NewDataBrowserItemDataUPP( OPL_DSNItemViewItemDataCallback); } static DataBrowserItemNotificationUPP g_fdsnItemNotificationUPP = NULL; if (!g_fdsnItemNotificationUPP) { g_fdsnItemNotificationUPP = NewDataBrowserItemNotificationUPP( OPL_DSN_notification_item); } fdsnViewCallbacks.u.v1.itemNotificationCallback = g_fdsnItemNotificationUPP; fdsnViewCallbacks.u.v1.itemDataCallback = g_fdsnItemDataUPP; err = SetDataBrowserCallbacks(fdsnView, &fdsnViewCallbacks); require_noerr(err, error); SetWindowProperty(getWindow(), kPropertyCreator, kPropertyTag, sizeof(dlg), &dlg); DisplayTabControl (0, tab_panel, 2, tabs); loadDSNList(); loadFDSNList(def_path); error: return; }
bool COdbcDS::GetMxDSList(const char* pDriverName, int iType, CDSList& DSList) { SQLCHAR DSNName[SQL_MAX_DSN_LENGTH + 1]; SQLCHAR Description[100]; SQLSMALLINT nameLen, descLen; SQLUSMALLINT direction; SQLRETURN retVal = SQL_SUCCESS; bool bFound = FALSE; // Set the config mode to the desired type. UWORD oldMode, newMode; if (iType == COdbcDS::DS_TYPE_SYS) { newMode = ODBC_SYSTEM_DSN; direction = SQL_FETCH_FIRST_SYSTEM; } else { newMode = ODBC_USER_DSN; direction = SQL_FETCH_FIRST_USER; } SQLGetConfigMode(&oldMode); SQLSetConfigMode(newMode); // Get the type of data source we're interested in. retVal = SQLDataSources(m_henv, direction, DSNName, sizeof(DSNName), &nameLen, Description, sizeof(Description), &descLen); if (retVal == SQL_ERROR) { SQLSetConfigMode(oldMode); throw 4; } // Loop through all of the data sources until the one we're looking for // is found. while (retVal == SQL_SUCCESS || retVal == SQL_SUCCESS_WITH_INFO) { if (strcmp(pDriverName, (const char*)Description) == 0) { DSList.append((const char*)DSNName, pDriverName); bFound = true; } retVal = SQLDataSources(m_henv, SQL_FETCH_NEXT, DSNName, sizeof(DSNName), &nameLen, Description, sizeof(Description), &descLen); if (retVal == SQL_ERROR) { SQLSetConfigMode(oldMode); throw 4; } } // Restore old config mode. SQLSetConfigMode(oldMode); return bFound; }
void adddrivers_to_list (GtkWidget *widget, GtkWidget *dlg) { SQLCHAR drvdesc[1024], drvattrs[1024], driver[1024], size[64]; SQLCHAR *data[4]; void *handle; struct stat _stat; SQLSMALLINT len, len1; SQLRETURN ret; HENV henv, drv_henv; HDBC drv_hdbc; pSQLGetInfoFunc funcHdl; pSQLAllocHandle allocHdl; pSQLAllocEnv allocEnvHdl = NULL; pSQLAllocConnect allocConnectHdl = NULL; pSQLFreeHandle freeHdl; pSQLFreeEnv freeEnvHdl; pSQLFreeConnect freeConnectHdl; if (!GTK_IS_CLIST (widget)) return; gtk_clist_clear (GTK_CLIST (widget)); /* Create a HENV to get the list of drivers then */ ret = SQLAllocHandle (SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv); if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) { _iodbcdm_nativeerrorbox (dlg, henv, SQL_NULL_HANDLE, SQL_NULL_HANDLE); goto end; } /* Set the version ODBC API to use */ SQLSetEnvAttr (henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_INTEGER); /* Get the list of drivers */ ret = SQLDrivers (henv, SQL_FETCH_FIRST, drvdesc, sizeof (drvdesc) / sizeof (SQLTCHAR), &len, drvattrs, sizeof (drvattrs) / sizeof (SQLTCHAR), &len1); if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO && ret != SQL_NO_DATA) { _iodbcdm_nativeerrorbox (dlg, henv, SQL_NULL_HANDLE, SQL_NULL_HANDLE); goto error; } while (ret != SQL_NO_DATA) { data[0] = drvdesc; /* Get the driver library name */ SQLSetConfigMode (ODBC_BOTH_DSN); SQLGetPrivateProfileString (drvdesc, "Driver", "", driver, sizeof (driver) / sizeof (SQLTCHAR), "odbcinst.ini"); if (driver[0] == '\0') SQLGetPrivateProfileString ("Default", "Driver", "", driver, sizeof (driver) / sizeof (SQLTCHAR), "odbcinst.ini"); if (driver[0] == '\0') { data[0] = NULL; goto skip; } data[1] = driver; drv_hdbc = NULL; drv_henv = NULL; if ((handle = (void *) DLL_OPEN (driver)) != NULL) { if ((allocHdl = (pSQLAllocHandle) DLL_PROC (handle, "SQLAllocHandle")) != NULL) { ret = allocHdl (SQL_HANDLE_ENV, SQL_NULL_HANDLE, &drv_henv); if (ret == SQL_ERROR) goto nodriverver; ret = allocHdl (SQL_HANDLE_DBC, drv_henv, &drv_hdbc); if (ret == SQL_ERROR) goto nodriverver; } else { if ((allocEnvHdl = (pSQLAllocEnv) DLL_PROC (handle, "SQLAllocEnv")) != NULL) { ret = allocEnvHdl (&drv_henv); if (ret == SQL_ERROR) goto nodriverver; } else goto nodriverver; if ((allocConnectHdl = (pSQLAllocConnect) DLL_PROC (handle, "SQLAllocConnect")) != NULL) { ret = allocConnectHdl (drv_henv, &drv_hdbc); if (ret == SQL_ERROR) goto nodriverver; } else goto nodriverver; } if ((funcHdl = (pSQLGetInfoFunc) DLL_PROC (handle, "SQLGetInfo")) != NULL) { /* Retrieve some information */ ret = funcHdl (drv_hdbc, SQL_DRIVER_VER, drvattrs, sizeof (drvattrs), &len); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { unsigned int z; /* Drop the description if one provided */ for (z = 0; ((char *) drvattrs)[z]; z++) if (((char *) drvattrs)[z] == ' ') ((char *) drvattrs)[z] = '\0'; data[2] = drvattrs; } else goto nodriverver; } else goto nodriverver; } else { nodriverver: data[2] = "##.##"; } if (drv_hdbc || drv_henv) { if (allocConnectHdl && (freeConnectHdl = (pSQLFreeConnect) DLL_PROC (handle, "SQLFreeConnect")) != NULL) { freeConnectHdl (drv_hdbc); drv_hdbc = NULL; } if (allocEnvHdl && (freeEnvHdl = (pSQLFreeEnv) DLL_PROC (handle, "SQLFreeEnv")) != NULL) { freeEnvHdl (drv_henv); drv_henv = NULL; } } if ((drv_hdbc || drv_henv) && (freeHdl = (pSQLFreeHandle) DLL_PROC (handle, "SQLFreeHandle")) != NULL) { if (drv_hdbc) freeHdl (SQL_HANDLE_DBC, drv_hdbc); if (drv_henv) freeHdl (SQL_HANDLE_ENV, drv_henv); } if (handle) DLL_CLOSE (handle); /* Get the size of the driver */ if (!stat (driver, &_stat)) { sprintf (size, "%d Kb", (int) (_stat.st_size / 1024)); data[3] = size; } else data[3] = "-"; gtk_clist_append (GTK_CLIST (widget), data); skip: ret = SQLDrivers (henv, SQL_FETCH_NEXT, drvdesc, sizeof (drvdesc) / sizeof (SQLTCHAR), &len, drvattrs, sizeof (drvattrs) / sizeof (SQLTCHAR), &len1); if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO && ret != SQL_NO_DATA) { _iodbcdm_nativeerrorbox (dlg, henv, SQL_NULL_HANDLE, SQL_NULL_HANDLE); goto error; } } error: /* Clean all that */ SQLFreeHandle (SQL_HANDLE_ENV, henv); end: if (GTK_CLIST (widget)->rows > 0) { gtk_clist_columns_autosize (GTK_CLIST (widget)); gtk_clist_sort (GTK_CLIST (widget)); } }
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(); }
int odbc_read_login_info(void) { static const char *PWD = "../../../PWD"; FILE *in = NULL; char line[512]; char *s1, *s2; const char *const *search_p; char path[1024]; int len; #ifdef _WIN32 UWORD old_config_mode; #endif setbuf(stdout, NULL); setbuf(stderr, NULL); s1 = getenv("TDSPWDFILE"); if (s1 && s1[0]) in = fopen(s1, "r"); if (!in) in = fopen(PWD, "r"); if (!in) in = fopen("PWD", "r"); if (!in) { fprintf(stderr, "Can not open PWD file\n\n"); return 1; } while (fgets(line, 512, in)) { s1 = strtok(line, "="); s2 = strtok(NULL, "\n"); if (!s1 || !s2) continue; if (!strcmp(s1, "UID")) { strcpy(odbc_user, s2); } else if (!strcmp(s1, "SRV")) { strcpy(odbc_server, s2); } else if (!strcmp(s1, "PWD")) { strcpy(odbc_password, s2); } else if (!strcmp(s1, "DB")) { strcpy(odbc_database, s2); } } fclose(in); /* find our driver */ #ifndef _WIN32 if (!getcwd(path, sizeof(path))) #else if (!_getcwd(path, sizeof(path))) #endif return 0; #ifdef __VMS { /* A hard-coded driver path has to be in unix syntax to be recognized as such. */ const char *unixspec = decc$translate_vms(path); if ( (int)unixspec != 0 && (int)unixspec != -1 ) strcpy(path, unixspec); } #endif len = strlen(path); if (len < 10 || (strcasecmp(path + len - 10, "/unittests") != 0 #ifdef _WIN32 && strcasecmp(path + len - 10, "\\unittests") != 0 #endif )) return 0; path[len - 9] = 0; for (search_p = search_driver; *search_p; ++search_p) { if (check_lib(path, *search_p)) break; } if (!*search_p) return 0; strcpy(odbc_driver, path); #ifndef _WIN32 /* craft out odbc.ini, avoid to read wrong one */ snprintf(path, sizeof(path), "odbc.ini.%d", (int) getpid()); in = fopen(path, "w"); if (in) { fprintf(in, "[%s]\nDriver = %s\nDatabase = %s\nServername = %s\n", odbc_server, odbc_driver, odbc_database, odbc_server); fclose(in); setenv("ODBCINI", "./odbc.ini", 1); setenv("SYSODBCINI", "./odbc.ini", 1); rename(path, "odbc.ini"); unlink(path); } #else if (SQLGetConfigMode(&old_config_mode)) { SQLSetConfigMode(ODBC_USER_DSN); SQLWritePrivateProfileString(odbc_server, "Driver", odbc_driver, "odbc.ini"); SQLWritePrivateProfileString(odbc_server, "Database", odbc_database, "odbc.ini"); SQLWritePrivateProfileString(odbc_server, "Servername", odbc_server, "odbc.ini"); SQLSetConfigMode(old_config_mode); } #endif return 0; }
SQLRETURN SQL_API SQLDrivers_Internal ( SQLHENV henv, SQLUSMALLINT fDir, SQLPOINTER szDrvDesc, SQLSMALLINT cbDrvDescMax, SQLSMALLINT * pcbDrvDesc, SQLPOINTER szDrvAttr, SQLSMALLINT cbDrvAttrMax, SQLSMALLINT * pcbDrvAttr, SQLCHAR waMode) { GENV (genv, henv); char buffer[4096], desc[1024], *ptr; int i, j, usernum = 0; static int cur_entry = -1; static int num_entries = 0; static void **sect = NULL; SQLUSMALLINT fDirOld = fDir; waMode = waMode; /*UNUSED*/ /* check argument */ if (cbDrvDescMax < 0 || cbDrvAttrMax < 0) { PUSHSQLERR (genv->herr, en_S1090); return SQL_ERROR; } if (fDir != SQL_FETCH_FIRST && fDir != SQL_FETCH_NEXT) { PUSHSQLERR (genv->herr, en_S1103); return SQL_ERROR; } if (cur_entry < 0 || fDir == SQL_FETCH_FIRST) { cur_entry = 0; num_entries = 0; /* * Free old section list */ if (sect) { for (i = 0; i < MAX_ENTRIES; i++) if (sect[i]) free (sect[i]); free (sect); } if ((sect = (void **) calloc (MAX_ENTRIES, sizeof (void *))) == NULL) { PUSHSQLERR (genv->herr, en_S1011); return SQL_ERROR; } if (fDirOld == SQL_FETCH_FIRST) fDir = SQL_FETCH_FIRST_USER; do { SQLSetConfigMode (fDir == SQL_FETCH_FIRST_SYSTEM ? ODBC_SYSTEM_DSN : ODBC_USER_DSN); SQLGetPrivateProfileString (SECT2, NULL, "", buffer, sizeof(buffer) / sizeof(SQLTCHAR), "odbcinst.ini"); /* For each datasources */ for(ptr = buffer, i = 1 ; *ptr && i ; ptr += STRLEN(ptr) + 1) { /* Add this section to the datasources list */ if (fDirOld == SQL_FETCH_FIRST && fDir == SQL_FETCH_FIRST_SYSTEM) { for(j = 0 ; j<usernum ; j++) { if(STREQ(sect[j<<1], ptr)) j = usernum; } if(j == usernum + 1) continue; } if ((num_entries << 1) >= MAX_ENTRIES) { i = 0; break; } /* Skip the rest */ /* ... and its description */ SQLSetConfigMode (fDir == SQL_FETCH_FIRST_SYSTEM ? ODBC_SYSTEM_DSN : ODBC_USER_DSN); SQLGetPrivateProfileString (SECT2, ptr, "", desc, sizeof(desc) / sizeof(SQLTCHAR), "odbcinst.ini"); /* Check if the driver is installed */ if(!STRCASEEQ(desc, "Installed")) continue; /* Copy the driver name */ sect[num_entries<<1] = STRDUP (ptr); sect[(num_entries++<<1) + 1] = STRDUP (desc); } switch(fDir) { case SQL_FETCH_FIRST_USER: fDir = SQL_FETCH_FIRST_SYSTEM; usernum = num_entries; break; case SQL_FETCH_FIRST_SYSTEM: fDir = SQL_FETCH_FIRST; break; }; } while (fDir!=SQL_FETCH_FIRST && fDirOld==SQL_FETCH_FIRST); fDir = fDirOld; /* * Sort all entries so we can present a nice list */ if (num_entries > 1) { qsort (sect, num_entries, sizeof (char **) + sizeof (char **), SectSorter); } } /* * Try to get to the next item */ if (cur_entry >= num_entries) { cur_entry = 0; /* Next time, start all over again */ return SQL_NO_DATA_FOUND; } /* * Copy Driver information */ STRNCPY (szDrvDesc, sect[cur_entry << 1], cbDrvDescMax); if (pcbDrvDesc) *pcbDrvDesc = STRLEN (szDrvDesc); /* * And find the description that goes with this entry */ STRNCPY (szDrvAttr, sect[(cur_entry << 1) + 1], cbDrvAttrMax); if (pcbDrvAttr) *pcbDrvAttr = STRLEN (szDrvAttr); /* * Next record */ cur_entry++; return SQL_SUCCESS; }
BOOL INSTAPI ConfigDriver ( HWND hwndParent, WORD fRequest, LPCSTR lpszDriver, LPCSTR lpszArgs, LPSTR lpszMsg, WORD cbMsgMax, WORD * pcbMsgOut) { char *curr, *cour; char driverread[4096] = { 0 }; BOOL retcode = FALSE; UWORD confMode = ODBC_USER_DSN; /* Map the request User/System */ if (fRequest < ODBC_INSTALL_DRIVER || fRequest > ODBC_CONFIG_DRIVER_MAX) { SQLPostInstallerError (ODBC_ERROR_INVALID_REQUEST_TYPE, NULL); goto done; } if (!lpszDriver || !STRLEN (lpszDriver)) { SQLPostInstallerError (ODBC_ERROR_INVALID_NAME, NULL); goto done; } /* Retrieve the config mode */ SQLGetConfigMode (&confMode); /* Treat corresponding to the request */ switch (fRequest) { case ODBC_INSTALL_DRIVER: /* Check if the DRIVER with this name already exists */ SQLSetConfigMode (confMode); #ifdef WIN32 if (hwndParent && SQLGetPrivateProfileString ("ODBC 32 bit Drivers", lpszDriver, "", driverread, sizeof (driverread), "odbcinst.ini") && !create_confirm (hwndParent, NULL, "Are you sure you want to overwrite this driver ?")) #else # ifdef _MACX if (hwndParent && SQLGetPrivateProfileString ("ODBC Drivers", lpszDriver, "", driverread, sizeof (driverread), "odbcinst.ini") && !create_confirm (hwndParent, NULL, "Are you sure you want to overwrite this driver ?")) # else if (hwndParent && SQLGetPrivateProfileString ("ODBC Drivers", lpszDriver, "", driverread, sizeof (driverread), "odbcinst.ini") && !create_confirm (hwndParent, NULL, "Are you sure you want to overwrite this driver ?")) # endif #endif { SQLPostInstallerError (ODBC_ERROR_DRIVER_SPECIFIC, "Driver already installed previously."); goto done; } /* Add the Driver to the ODBC Drivers */ SQLSetConfigMode (confMode); if (!SQLInstallDriverEx (lpszArgs, NULL, driverread, sizeof (driverread), NULL, ODBC_INSTALL_COMPLETE, NULL)) { SQLPostInstallerError (ODBC_ERROR_DRIVER_SPECIFIC, "Could not add the driver information."); goto done; } break; case ODBC_CONFIG_DRIVER: if (!lpszArgs || !STRLEN (lpszArgs)) { SQLPostInstallerError (ODBC_ERROR_DRIVER_SPECIFIC, "No enough parameters for configururation."); goto done; } /* Add each keyword and values */ for (curr = (LPSTR) lpszArgs; *curr; curr += (STRLEN (curr) + 1)) { STRCPY (driverread, curr); cour = strchr (driverread, '='); if (cour) *cour = 0; SQLSetConfigMode (confMode); if (!SQLWritePrivateProfileString (lpszDriver, driverread, (cour && STRLEN (cour + 1)) ? cour + 1 : NULL, "odbcinst.ini")) goto done; } break; case ODBC_REMOVE_DRIVER: /* Remove the Driver to the ODBC Drivers */ SQLSetConfigMode (confMode); if (!SQLRemoveDriver (lpszDriver, TRUE, NULL)) { SQLPostInstallerError (ODBC_ERROR_DRIVER_SPECIFIC, "Could not remove driver information."); goto done; } break; default: SQLPostInstallerError (ODBC_ERROR_REQUEST_FAILED, NULL); goto done; }; quit: retcode = TRUE; done: if (pcbMsgOut) *pcbMsgOut = 0; return retcode; }
/*! * \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; }
char *__find_lib_name( char *dsn, char *lib_name, char *driver_name ) { char driver[ INI_MAX_PROPERTY_VALUE + 1 ]; char driver_lib[ INI_MAX_PROPERTY_VALUE + 1 ]; SQLSetConfigMode( ODBC_USER_DSN ); /* * GET DRIVER FROM ODBC.INI */ SQLGetPrivateProfileString( dsn, "Driver", "", driver_lib, sizeof( driver_lib ), "ODBC.INI" ); if ( driver_lib[ 0 ] == 0 ) { /* * if not found look in system DSN */ SQLSetConfigMode( ODBC_SYSTEM_DSN ); SQLGetPrivateProfileString( dsn, "Driver", "", driver_lib, sizeof( driver_lib ), "ODBC.INI" ); SQLSetConfigMode( ODBC_BOTH_DSN ); if ( driver_lib[ 0 ] == 0 ) return NULL; } /* * GET DRIVER FROM ODBCINST.INI IF ODBC.INI HAD USER FRIENDLY NAME */ strcpy( driver_name, "" ); if ( driver_lib[ 0 ] != '/' ) { strcpy( driver, driver_lib ); /* * allow the use of "User odbcinst files */ #ifdef PLATFORM64 SQLGetPrivateProfileString( driver, "Driver64", "", driver_lib, sizeof( driver_lib ), "ODBCINST.INI" ); if ( driver_lib[ 0 ] == '\0' ) { SQLGetPrivateProfileString( driver, "Driver", "", driver_lib, sizeof( driver_lib ), "ODBCINST.INI" ); } #else SQLGetPrivateProfileString( driver, "Driver", "", driver_lib, sizeof( driver_lib ), "ODBCINST.INI" ); #endif strcpy( driver_name, driver ); if ( driver_lib[ 0 ] == 0 ) { return NULL; } } strcpy( lib_name, driver_lib ); return lib_name; }
/* Changed ... Have to implement the same for translators */ void adddrivers_to_list (ControlRef widget, WindowRef dlg, BOOL addNotify) { wchar_t drvdesc[1024], drvattrs[1024], driver[1024]; DataBrowserItemID item = DBITEM_ID + 1; DataBrowserCallbacks dbCallbacks; ThemeDrawingState outState = NULL; UInt16 colSize[5] = { 150, 150, 100, 50 , 50}; void *handle; SInt16 outBaseline; Point ioBound; struct stat _stat; SQLSMALLINT len, len1; SQLRETURN ret; HENV henv, drv_henv; HDBC drv_hdbc; pSQLGetInfoFunc funcHdl; pSQLAllocHandle allocHdl; pSQLAllocEnv allocEnvHdl = NULL; pSQLAllocConnect allocConnectHdl = NULL; pSQLFreeHandle freeHdl; pSQLFreeEnv freeEnvHdl; pSQLFreeConnect freeConnectHdl; char *_drv_u8 = NULL; int i; if (!widget) return; GetThemeDrawingState (&outState); /* Install an event handler on the component databrowser */ dbCallbacks.version = kDataBrowserLatestCallbacks; InitDataBrowserCallbacks (&dbCallbacks); if (addNotify) dbCallbacks.u.v1.itemNotificationCallback = NewDataBrowserItemNotificationUPP (drivers_notification_item); /* On Mac OS X 10.0.x : clientDataCallback */ dbCallbacks.u.v1.itemDataCallback = NewDataBrowserItemDataUPP (drivers_getset_item); SetDataBrowserCallbacks (widget, &dbCallbacks); /* Begin the draw of the data browser */ SetDataBrowserTarget (widget, DBITEM_ID); /* Make the clean up */ for (i = 0; i < Drivers_nrows; i++, item++) { CFRelease (Drivers_array[0][i]); Drivers_array[0][i] = NULL; CFRelease (Drivers_array[1][i]); Drivers_array[1][i] = NULL; CFRelease (Drivers_array[2][i]); Drivers_array[2][i] = NULL; CFRelease (Drivers_array[3][i]); Drivers_array[3][i] = NULL; CFRelease (Drivers_array[4][i]); Drivers_array[4][i] = NULL; RemoveDataBrowserItems (widget, DBITEM_ID, 1, &item, DBNAME_ID); } /* Global Initialization */ Drivers_nrows = 0; item = DBITEM_ID + 1; /* Create a HENV to get the list of drivers then */ ret = SQLAllocHandle (SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv); if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) { _iodbcdm_nativeerrorbox (dlg, henv, SQL_NULL_HANDLE, SQL_NULL_HANDLE); goto end; } /* Set the version ODBC API to use */ SQLSetEnvAttr (henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER); /* Get the list of drivers */ ret = SQLDriversW (henv, SQL_FETCH_FIRST, drvdesc, sizeof (drvdesc)/sizeof(wchar_t), &len, drvattrs, sizeof (drvattrs)/sizeof(wchar_t), &len1); if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO && ret != SQL_NO_DATA) { _iodbcdm_nativeerrorbox (dlg, henv, SQL_NULL_HANDLE, SQL_NULL_HANDLE); goto error; } while (ret != SQL_NO_DATA) { Drivers_array[0][Drivers_nrows] = convert_wchar_to_CFString(drvdesc); /* Get the driver library name */ SQLSetConfigMode (ODBC_BOTH_DSN); SQLGetPrivateProfileStringW (drvdesc, L"Driver", L"", driver, sizeof (driver)/sizeof(wchar_t), L"odbcinst.ini"); if (driver[0] == L'\0') SQLGetPrivateProfileStringW (L"Default", L"Driver", L"", driver, sizeof (driver)/sizeof(wchar_t), L"odbcinst.ini"); if (driver[0] == L'\0') { if (Drivers_array[0][Drivers_nrows]) { CFRelease (Drivers_array[0][Drivers_nrows]); Drivers_array[0][Drivers_nrows] = NULL; } goto skip; } Drivers_array[1][Drivers_nrows] = convert_wchar_to_CFString(driver); /* Alloc a connection handle */ drv_hdbc = NULL; drv_henv = NULL; _drv_u8 = (char *) dm_SQL_WtoU8((SQLWCHAR*)driver, SQL_NTS); if (_drv_u8 == NULL) goto skip; if ((handle = DLL_OPEN(_drv_u8)) != NULL) { if ((allocHdl = (pSQLAllocHandle)DLL_PROC(handle, "SQLAllocHandle")) != NULL) { ret = allocHdl(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &drv_henv); if (ret == SQL_ERROR) goto nodriverver; ret = allocHdl(SQL_HANDLE_DBC, drv_henv, &drv_hdbc); if (ret == SQL_ERROR) goto nodriverver; } else { if ((allocEnvHdl = (pSQLAllocEnv)DLL_PROC(handle, "SQLAllocEnv")) != NULL) { ret = allocEnvHdl(&drv_henv); if (ret == SQL_ERROR) goto nodriverver; } else goto nodriverver; if ((allocConnectHdl = (pSQLAllocConnect)DLL_PROC(handle, "SQLAllocConnect")) != NULL) { ret = allocConnectHdl(drv_henv, &drv_hdbc); if (ret == SQL_ERROR) goto nodriverver; } else goto nodriverver; } /* * Use SQLGetInfoA for Unicode drivers * and SQLGetInfo for ANSI drivers */ funcHdl = (pSQLGetInfoFunc)DLL_PROC(handle, "SQLGetInfoA"); if (!funcHdl) funcHdl = (pSQLGetInfoFunc)DLL_PROC(handle, "SQLGetInfo"); if (funcHdl) { /* Retrieve some informations */ ret = funcHdl (drv_hdbc, SQL_DRIVER_VER, drvattrs, sizeof(drvattrs), &len); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { char *p = drvattrs; /* Find the description if one provided */ for (; *p ; p++) { if (*p == ' ') { *p++ = '\0'; break; } } /* * Store Version */ Drivers_array[2][Drivers_nrows] = CFStringCreateWithCString(NULL, (char *)drvattrs, kCFStringEncodingUTF8); } else goto nodriverver; } else if ((funcHdl = (pSQLGetInfoFunc)DLL_PROC(handle, "SQLGetInfoW")) != NULL) { /* Retrieve some informations */ ret = funcHdl (drv_hdbc, SQL_DRIVER_VER, drvattrs, sizeof(drvattrs), &len); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { wchar_t *p = drvattrs; /* Find the description if one provided */ for (; *p ; p++) { if (*p == L' ') { *p++ = L'\0'; break; } } /* * Store Version */ Drivers_array[2][Drivers_nrows] = convert_wchar_to_CFString(drvattrs); } else goto nodriverver; } else goto nodriverver; } else { nodriverver: Drivers_array[2][Drivers_nrows] = CFStringCreateWithCString(NULL, "##.##", kCFStringEncodingUTF8); } if(drv_hdbc || drv_henv) { if(allocConnectHdl && (freeConnectHdl = (pSQLFreeConnect)DLL_PROC(handle, "SQLFreeConnect")) != NULL) { freeConnectHdl(drv_hdbc); drv_hdbc = NULL; } if(allocEnvHdl && (freeEnvHdl = (pSQLFreeEnv)DLL_PROC(handle, "SQLFreeEnv")) != NULL) { freeEnvHdl(drv_henv); drv_henv = NULL; } } if ((drv_hdbc || drv_henv) && (freeHdl = (pSQLFreeHandle)DLL_PROC(handle, "SQLFreeHandle")) != NULL) { if(drv_hdbc) freeHdl(SQL_HANDLE_DBC, drv_hdbc); if(drv_henv) freeHdl(SQL_HANDLE_ENV, drv_henv); } DLL_CLOSE(handle); /* Get the size and date of the driver */ if (!stat (_drv_u8, &_stat)) { CFStringRef strRef; struct tm drivertime; char buf[100]; Drivers_array[3][Drivers_nrows] = CFStringCreateWithFormat(NULL, NULL, strRef = CFStringCreateWithCString(NULL, "%d Kb", kCFStringEncodingUTF8), (int) (_stat.st_size / 1024)); CFRelease(strRef); localtime_r (&_stat.st_mtime, &drivertime); strftime (buf, sizeof (buf), "%c", &drivertime); Drivers_array[4][Drivers_nrows] = CFStringCreateWithCString(NULL, buf, kCFStringEncodingUTF8); } else { Drivers_array[3][Drivers_nrows] = CFStringCreateWithCString(NULL, "-", kCFStringEncodingUTF8); Drivers_array[4][Drivers_nrows] = CFStringCreateWithCString(NULL, "-", kCFStringEncodingUTF8); } for(i = 0 ; i < 5 ; i++) { GetThemeTextDimensions (Drivers_array[i][Drivers_nrows], kThemeSystemFont, kThemeStateActive, false, &ioBound, &outBaseline); if(colSize[i] < ioBound.h) colSize[i] = ioBound.h; } AddDataBrowserItems (widget, DBITEM_ID, 1, &item, DBNAME_ID); item++; Drivers_nrows++; /* Process next one */ skip: MEM_FREE (_drv_u8); _drv_u8 = NULL; ret = SQLDriversW (henv, SQL_FETCH_NEXT, drvdesc, sizeof (drvdesc)/sizeof(wchar_t), &len, drvattrs, sizeof (drvattrs)/sizeof(wchar_t), &len1); if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO && ret != SQL_NO_DATA) { _iodbcdm_nativeerrorbox (dlg, henv, SQL_NULL_HANDLE, SQL_NULL_HANDLE); goto error; } } error: /* Clean all that */ SQLFreeHandle (SQL_HANDLE_ENV, henv); end: ActivateControl (widget); /* Resize the columns to have a good look */ SetDataBrowserTableViewNamedColumnWidth (widget, DBNAME_ID, colSize[0] + 20); SetDataBrowserTableViewNamedColumnWidth (widget, DBFILE_ID, colSize[1] + 20); SetDataBrowserTableViewNamedColumnWidth (widget, DBVERSION_ID, colSize[2] + 20); SetDataBrowserTableViewNamedColumnWidth (widget, DBSIZE_ID, colSize[3] + 20); SetDataBrowserTableViewNamedColumnWidth (widget, DBDATE_ID, colSize[4] + 20); DrawOneControl (widget); /* Remove the DataBrowser callback */ SetDataBrowserCallbacks (NULL, &dbCallbacks); if(outState) DisposeThemeDrawingState (outState); }