EWXWEXPORT(int,wxDb_GetDataSource)(void* henv,wxChar* dsn,int dsnLen,wxChar* description,int descLen,int direction) { if (dsn && dsnLen > 0) *dsn = '\0'; if (description && descLen > 0) *description = '\0'; #ifdef wxUSE_ODBC return wxDbGetDataSource( (HENV)(henv), dsn, dsnLen, description, descLen, direction); #else return 0; #endif }
//---------------------------------------------------------------------------------------- bool MainDoc::OnInitODBC() { wxChar Dsn[SQL_MAX_DSN_LENGTH+1]; wxChar DsDesc[254+1]; // BJO20002501 instead of 512 Temp0 = wxEmptyString; i_DSN = 0; // Counter int i; //--------------------------------------------------------------------------------------- // Initialize the ODBC Environment for Database Operations if (!DbConnectInf.AllocHenv()) { return false; } //--------------------------------------------------------------------------------------- const wxChar sep = 3; // separator character used in string between DSN and DsDesc wxSortedArrayString s_SortDSNList, s_SortDsDescList; // BJO-20000127 // In order to have same sort result on both Dsn and DsDesc, create a 'keyed' string. // The key will be removed after sorting wxString KeyString; //--------------------------------------------------------------------------------------- while (wxDbGetDataSource(DbConnectInf.GetHenv(), Dsn, SQL_MAX_DSN_LENGTH, DsDesc, 254)) { i_DSN++; // How many Dsn have we ? KeyString.Printf(_T("%s%c%s"),Dsn, sep, DsDesc); s_SortDSNList.Add(Dsn); s_SortDsDescList.Add(KeyString); } //--------------------------------------------------------------------------------------- // Allocate n ODBC-DSN objects to hold the information // Allocate n wxDatabase objects to hold the column information p_DSN = new DSN[i_DSN]; //BJO db_Br = new BrowserDB[i_DSN]; for (i=0;i<i_DSN;i++) { KeyString = s_SortDsDescList[i]; KeyString = KeyString.AfterFirst(sep); // ODBC-DSN object (p_DSN+i)->Dsn = s_SortDSNList[i]; (p_DSN+i)->Drv = KeyString; (p_DSN+i)->Usr = wxEmptyString; (p_DSN+i)->Pas = wxEmptyString; Temp0.Printf(_T("%02d) Dsn(%s) DsDesc(%s)"),i,(p_DSN+i)->Dsn.c_str(),(p_DSN+i)->Drv.c_str()); wxLogMessage(Temp0); // wxDataBase object (db_Br+i)->p_LogWindow = p_LogWin; (db_Br+i)->ODBCSource = (p_DSN+i)->Dsn; (db_Br+i)->UserName = (p_DSN+i)->Usr; (db_Br+i)->Password = (p_DSN+i)->Pas; (db_Br+i)->pDoc = this; (db_Br+i)->i_Which = i; } DbConnectInf.FreeHenv(); //--------------------------------------------------------------------------------------- if (!i_DSN) { wxString message = _("No Dataset names found in ODBC!\n"); message += _(" Program will exit!\n\n"); message += _(" Ciao"); wxMessageBox( message,_("-E-> Fatal situation")); return false; } //--------------------------------------------------------------------------------------- return true; }