Changed code to demonstrate the new wxDbConnectInf class
ODBC environment handle now managed via the wxDbConnectInf class
Condensed the use of multiple wxDbConnectInf instances to one and got rid of the bogus EXTERNs of the wxDbConnectInf that were causing so many headaches and mismatched usages of them.
Other minor bug fixes - still have not foudn the reason for the crash on exit
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9277
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
//----------------------------------------------------------------------------------------
// Global structure for holding ODBC connection information
// - darf nur einmal im Projekte definiert werden ?? Extra Databasse Klasse ?
//----------------------------------------------------------------------------------------
// Global structure for holding ODBC connection information
// - darf nur einmal im Projekte definiert werden ?? Extra Databasse Klasse ?
-wxDbConnectInf ConnectInf; // Für DBase
+wxDbConnectInf DbConnectInf; // Für DBase
//----------------------------------------------------------------------------------------
extern WXDLLEXPORT_DATA(wxDbList*) PtrBegDbList; /* from db.cpp, used in getting back error results from db connections */
//----------------------------------------------------------------------------------------
extern WXDLLEXPORT_DATA(wxDbList*) PtrBegDbList; /* from db.cpp, used in getting back error results from db connections */
//----------------------------------------------------------------------------------------
BrowserDB::BrowserDB()
{
//----------------------------------------------------------------------------------------
BrowserDB::BrowserDB()
{
ODBCSource = ""; // ODBC data source name (created with ODBC Administrator under Win95/NT)
UserName = ""; // database username - must already exist in the data source
Password = ""; // password database username
ODBCSource = ""; // ODBC data source name (created with ODBC Administrator under Win95/NT)
UserName = ""; // database username - must already exist in the data source
Password = ""; // password database username
//----------------------------------------------------------------------------------------
BrowserDB::~BrowserDB()
{
//----------------------------------------------------------------------------------------
BrowserDB::~BrowserDB()
{
- Zeiger_auf_NULL(1); // Clean up Tables and Databases (Commit, Close und delete)
+ PointerToNULL(1); // Clean up Tables and Databases (Commit, Close and delete)
} // BrowserDB destructor
//----------------------------------------------------------------------------------------
} // BrowserDB destructor
//----------------------------------------------------------------------------------------
if (db_BrowserDB != NULL)
{
if (!Quiet)
if (db_BrowserDB != NULL)
{
if (!Quiet)
- wxLogMessage(_("\n-I-> BrowserDB::OnStartDB() : DB is allready open."));
+ wxLogMessage(_("\n-I-> BrowserDB::OnStartDB() : DB is already open."));
- // Initialize the ODBC Environment for Database Operations
- if (SQLAllocEnv(&ConnectInf.Henv) != SQL_SUCCESS)
- {
- if (!Quiet)
- wxLogMessage(_("\n-E-> BrowserDB::OnStartDB() : DB CONNECTION ERROR : A problem occured while trying to get a connection to the data source"));
- return FALSE;
- }
+
+ DbConnectInf.AllocHenv();
+
//---------------------------------------------------------------------------------------
// Connect to datasource
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
// Connect to datasource
//---------------------------------------------------------------------------------------
if (OK)
{
//--------------------------------------------------------------------------------------
if (OK)
{
//--------------------------------------------------------------------------------------
- ConnectInf.Dsn = ODBCSource; // ODBC data source name (created with ODBC Administrator under Win95/NT)
- ConnectInf.Uid = UserName; // database username - must already exist in the data source
- ConnectInf.AuthStr= Password; // password database username
- db_BrowserDB = wxDbGetConnection(&ConnectInf);
+ DbConnectInf.SetDsn(ODBCSource); // ODBC data source name (created with ODBC Administrator under Win95/NT)
+ DbConnectInf.SetUserID(UserName); // database username - must already exist in the data source
+ DbConnectInf.SetPassword(Password); // password database username
+ db_BrowserDB = wxDbGetConnection(&DbConnectInf);
// wxLogMessage(">>>%s<<<>>>%s<<<",UserName.c_str(),Password.c_str());
if (db_BrowserDB == NULL)
{
// wxLogMessage(">>>%s<<<>>>%s<<<",UserName.c_str(),Password.c_str());
if (db_BrowserDB == NULL)
{
- ConnectInf.Dsn = "";
- ConnectInf.Uid = "";
- ConnectInf.AuthStr = "";
+ DbConnectInf.SetDsn(wxT(""));
+ DbConnectInf.SetUserID(wxT(""));
+ DbConnectInf.SetPassword(wxT(""));
if (!Quiet)
{
wxLogMessage(_("\n-E-> BrowserDB::OnConnectDataSource() DB CONNECTION ERROR : Unable to connect to the data source.\n\nCheck the name of your data source to verify it has been correctly entered/spelled.\n\nWith some databases, the user name and password must\nbe created with full rights to the table prior to making a connection\n(using tools provided by the database manufacturer)"));
wxLogMessage(_("-I-> BrowserDB::OnStartDB(%s) : End - Time needed : %ld ms"),ODBCSource.c_str(),sw.Time());
}
if (!Quiet)
{
wxLogMessage(_("\n-E-> BrowserDB::OnConnectDataSource() DB CONNECTION ERROR : Unable to connect to the data source.\n\nCheck the name of your data source to verify it has been correctly entered/spelled.\n\nWith some databases, the user name and password must\nbe created with full rights to the table prior to making a connection\n(using tools provided by the database manufacturer)"));
wxLogMessage(_("-I-> BrowserDB::OnStartDB(%s) : End - Time needed : %ld ms"),ODBCSource.c_str(),sw.Time());
}
+ DbConnectInf.FreeHenv();
return FALSE;
}
//--------------------------------------------------------------------------------------
return FALSE;
}
//--------------------------------------------------------------------------------------
+ {
+ DbConnectInf.FreeHenv();
}
//----------------------------------------------------------------------------------------
}
//----------------------------------------------------------------------------------------
{
// db_BrowserDB->Close();
wxDbFreeConnection(db_BrowserDB);
{
// db_BrowserDB->Close();
wxDbFreeConnection(db_BrowserDB);
-/*
- // Free Environment Handle that ODBC uses
- if (SQLFreeEnv(&ConnectInf.Henv) != SQL_SUCCESS)
- {
- // Error freeing environment handle
- }
-*/
+
+ DbConnectInf.FreeHenv();
+
db_BrowserDB = NULL;
}
if (!Quiet)
db_BrowserDB = NULL;
}
if (!Quiet)
}
//----------------------------------------------------------------------------------------
}
//----------------------------------------------------------------------------------------
-void BrowserDB::Zeiger_auf_NULL(int Art)
+void BrowserDB::PointerToNULL(int Art)
{
if (Art == 1) // Löschen
{
{
if (Art == 1) // Löschen
{
//----------------------------------------------------------------------------------------
// Global structure for holding ODBC connection information
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
// Global structure for holding ODBC connection information
//----------------------------------------------------------------------------------------
-extern wxDbConnectInf DbConnectInf;
+//extern wxDbConnectInf DbConnectInf;
class MainDoc;
//----------------------------------------------------------------------------------------
class MainDoc;
//----------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
BrowserDB();
~BrowserDB();
//---------------------------------------------------------------------------------------
BrowserDB();
~BrowserDB();
- void Zeiger_auf_NULL(int Art);
+ void PointerToNULL(int Art);
bool Initialize(int Quiet);
//---------------------------------------------------------------------------------------
bool OnStartDB(int Quiet);
bool Initialize(int Quiet);
//---------------------------------------------------------------------------------------
bool OnStartDB(int Quiet);
//----------------------------------------------------------------------------------------
//-- Some Global Vars for all Files (extern in ?.h needed) -------------------------------
// Global structure for holding ODBC connection information
//----------------------------------------------------------------------------------------
//-- Some Global Vars for all Files (extern in ?.h needed) -------------------------------
// Global structure for holding ODBC connection information
-wxDbConnectInf DbConnectInf;
+extern wxDbConnectInf DbConnectInf;
//----------------------------------------------------------------------------------------
wxConfigBase *p_ProgramCfg; // All Config and Path information
//----------------------------------------------------------------------------------------
wxConfigBase *p_ProgramCfg; // All Config and Path information
int i = 0;
//---------------------------------------------------------------------------------------
// Initialize the ODBC Environment for Database Operations
int i = 0;
//---------------------------------------------------------------------------------------
// Initialize the ODBC Environment for Database Operations
-
- if (SQLAllocEnv(&DbConnectInf.Henv) != SQL_SUCCESS)
+
+ if (!DbConnectInf.AllocHenv())
//---------------------------------------------------------------------------------------
const char sep = 3; // separator character used in string between DSN ans DsDesc
wxStringList s_SortDSNList, s_SortDsDescList;
//---------------------------------------------------------------------------------------
const char sep = 3; // separator character used in string between DSN ans DsDesc
wxStringList s_SortDSNList, s_SortDsDescList;
// The key will be removed after sorting
wxString KeyString;
//---------------------------------------------------------------------------------------
// The key will be removed after sorting
wxString KeyString;
//---------------------------------------------------------------------------------------
- while(wxDbGetDataSource(DbConnectInf.Henv, Dsn, sizeof(Dsn), DsDesc, sizeof(DsDesc)))
+ while(wxDbGetDataSource(DbConnectInf.GetHenv(), Dsn, sizeof(Dsn), DsDesc, sizeof(DsDesc)))
{
i_DSN++; // How many Dsn have we ?
KeyString.Printf("%s%c%s",Dsn, sep, DsDesc);
{
i_DSN++; // How many Dsn have we ?
KeyString.Printf("%s%c%s",Dsn, sep, DsDesc);
(db_Br+i)->pDoc = this;
(db_Br+i)->i_Which = i;
}
(db_Br+i)->pDoc = this;
(db_Br+i)->i_Which = i;
}
- if (SQLFreeEnv(DbConnectInf.Henv) != SQL_SUCCESS) // BJO20000125 / MJ10777.20000309 : no &
- {
- // Error freeing environment handle
- }
+
+ DbConnectInf.FreeHenv();
+
delete [] s_SortDSN;
delete [] s_SortDsDesc;
//---------------------------------------------------------------------------------------
delete [] s_SortDSN;
delete [] s_SortDsDesc;
//---------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
// Global structure for holding ODBC connection information
//----------------------------------------------------------------------------------------
// Global structure for holding ODBC connection information
-extern wxDbConnectInf DbConnectInf;
+//extern wxDbConnectInf DbConnectInf;
//----------------------------------------------------------------------------------------
extern wxConfigBase *p_ProgramCfg; // All Config and Path information
//----------------------------------------------------------------------------------------
extern wxConfigBase *p_ProgramCfg; // All Config and Path information