X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/645889ad25eaa6e332463a6105a1dfd63d917d36..88b792af94fe4a2d0f14a2c4c6b85ff3c4bd49a5:/demos/dbbrowse/browsedb.cpp diff --git a/demos/dbbrowse/browsedb.cpp b/demos/dbbrowse/browsedb.cpp index ef321bf2a6..2a4db60c6b 100644 --- a/demos/dbbrowse/browsedb.cpp +++ b/demos/dbbrowse/browsedb.cpp @@ -1,7 +1,7 @@ //---------------------------------------------------------------------------------------- // Name: BrowserDB.h,cpp // Purpose: a wxDB class -// Author: Mark Johnson, mj10777@gmx.net +// Author: Mark Johnson // Modified by: // Created: 19991127.mj10777 // Copyright: (c) Mark Johnson @@ -32,7 +32,11 @@ //---------------------------------------------------------------------------------------- // 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 + +#if !wxUSE_ODBC + #error Demo cannot be compiled unless setup.h has wxUSE_ODBC set to 1 +#endif //---------------------------------------------------------------------------------------- extern WXDLLEXPORT_DATA(wxDbList*) PtrBegDbList; /* from db.cpp, used in getting back error results from db connections */ @@ -79,7 +83,7 @@ char *GetExtendedDBErrorMsg(char *ErrFile, int ErrLine) //---------------------------------------------------------------------------------------- BrowserDB::BrowserDB() { - Zeiger_auf_NULL(0); + PointerToNULL(0); 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 @@ -90,7 +94,7 @@ 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 //---------------------------------------------------------------------------------------- @@ -113,16 +117,12 @@ bool BrowserDB::OnStartDB(int 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.")); return TRUE; } - // 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 //--------------------------------------------------------------------------------------- @@ -147,21 +147,22 @@ bool BrowserDB::OnStartDB(int Quiet) 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) { - 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()); } + DbConnectInf.FreeHenv(); return FALSE; } //-------------------------------------------------------------------------------------- @@ -175,7 +176,10 @@ bool BrowserDB::OnStartDB(int Quiet) return TRUE; } else + { + DbConnectInf.FreeHenv(); return FALSE; + } } //---------------------------------------------------------------------------------------- @@ -187,13 +191,9 @@ bool BrowserDB::OnCloseDB(int Quiet) { // 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) @@ -227,21 +227,23 @@ bool BrowserDB::OnGetNext(int Cols,int Quiet) for (i=0;itableName,"-E->"); - i_dbDataType = (cl_BrowserDB->pColFor+i)->i_dbDataType; + i_dbDataType = (cl_BrowserDB+i)->pColFor->i_dbDataType; if (i_dbDataType == 0) // Filter unsupported dbDataTypes { - if (((cl_BrowserDB->pColFor+i)->i_sqlDataType == SQL_VARCHAR) || ((cl_BrowserDB->pColFor+i)->i_sqlDataType == SQL_LONGVARCHAR)) + if (((cl_BrowserDB+i)->pColFor->i_sqlDataType == SQL_VARCHAR) || + ((cl_BrowserDB+i)->pColFor->i_sqlDataType == SQL_LONGVARCHAR)) i_dbDataType = DB_DATA_TYPE_VARCHAR; - if ((cl_BrowserDB->pColFor+i)->i_sqlDataType == SQL_C_DATE) + if ((cl_BrowserDB+i)->pColFor->i_sqlDataType == SQL_C_DATE) i_dbDataType = DB_DATA_TYPE_DATE; - if ((cl_BrowserDB->pColFor+i)->i_sqlDataType == SQL_C_BIT) + if ((cl_BrowserDB+i)->pColFor->i_sqlDataType == SQL_C_BIT) i_dbDataType = DB_DATA_TYPE_INTEGER; - if ((cl_BrowserDB->pColFor+i)->i_sqlDataType == SQL_NUMERIC) + if ((cl_BrowserDB+i)->pColFor->i_sqlDataType == SQL_NUMERIC) i_dbDataType = DB_DATA_TYPE_VARCHAR; - if ((cl_BrowserDB->pColFor+i)->i_sqlDataType == SQL_REAL) + if ((cl_BrowserDB+i)->pColFor->i_sqlDataType == SQL_REAL) i_dbDataType = DB_DATA_TYPE_FLOAT; } - if ((i_dbDataType == DB_DATA_TYPE_INTEGER) && ((cl_BrowserDB->pColFor+i)->i_sqlDataType == SQL_C_DOUBLE)) + if ((i_dbDataType == DB_DATA_TYPE_INTEGER) && + ((cl_BrowserDB+i)->pColFor->i_sqlDataType == SQL_C_DOUBLE)) { // DBASE Numeric i_dbDataType = DB_DATA_TYPE_FLOAT; } @@ -249,31 +251,31 @@ bool BrowserDB::OnGetNext(int Cols,int Quiet) { case DB_DATA_TYPE_VARCHAR: strcpy(s_temp,""); - if (!db_BrowserDB->GetData(i+1,(cl_BrowserDB->pColFor+i)->i_dbDataType,&s_temp,sizeof(s_temp), &cb)) + if (!db_BrowserDB->GetData(i+1,(cl_BrowserDB+i)->pColFor->i_dbDataType,&s_temp,sizeof(s_temp), &cb)) { Temp0.Printf(_("\n-E-> BrowserDB::OnGetNext - ODBC-Error with GetNext of >%s<.\n-E-> "),(cl_BrowserDB+i)->tableName); Temp0 += GetExtendedDBErrorMsg(__FILE__,__LINE__); wxLogMessage(Temp0); } - Temp0.Printf((cl_BrowserDB->pColFor+i)->s_Field,s_temp); + Temp0.Printf((cl_BrowserDB+i)->pColFor->s_Field,s_temp); strcpy((cl_BrowserDB+i)->tableName,Temp0.c_str()); break; case DB_DATA_TYPE_INTEGER: l_temp = 0; - if (!db_BrowserDB->GetData(i+1,(cl_BrowserDB->pColFor+i)->i_sqlDataType,&l_temp,sizeof(l_temp), &cb)) + if (!db_BrowserDB->GetData(i+1,(cl_BrowserDB+i)->pColFor->i_sqlDataType,&l_temp,sizeof(l_temp), &cb)) { Temp0.Printf(_("\n-E-> BrowserDB::OnGetData - ODBC-Error with GetNext \n-E-> ")); Temp0 += GetExtendedDBErrorMsg(__FILE__,__LINE__); } else { - Temp0.Printf((cl_BrowserDB->pColFor+i)->s_Field,l_temp); + Temp0.Printf((cl_BrowserDB+i)->pColFor->s_Field,l_temp); strcpy((cl_BrowserDB+i)->tableName,Temp0.c_str()); } break; case DB_DATA_TYPE_FLOAT: f_temp = 0; - if (!db_BrowserDB->GetData(i+1,(cl_BrowserDB->pColFor+i)->i_sqlDataType,&f_temp,sizeof(f_temp), &cb)) + if (!db_BrowserDB->GetData(i+1,(cl_BrowserDB+i)->pColFor->i_sqlDataType,&f_temp,sizeof(f_temp), &cb)) { Temp0.Printf(_("\n-E-> BrowserDB::OnGetData - ODBC-Error with GetNext \n-E-> ")); Temp0 += GetExtendedDBErrorMsg(__FILE__,__LINE__); @@ -281,13 +283,13 @@ bool BrowserDB::OnGetNext(int Cols,int Quiet) } else { - Temp0.Printf((cl_BrowserDB->pColFor+i)->s_Field,f_temp); + Temp0.Printf((cl_BrowserDB+i)->pColFor->s_Field,f_temp); strcpy((cl_BrowserDB+i)->tableName,Temp0.c_str()); } break; case DB_DATA_TYPE_DATE: t_temp.day = t_temp.month = t_temp.year = t_temp.hour = t_temp.minute = t_temp.second = t_temp.fraction = 0; - if (!db_BrowserDB->GetData(i+1,(cl_BrowserDB->pColFor+i)->i_sqlDataType,&t_temp,sizeof(t_temp), &cb)) + if (!db_BrowserDB->GetData(i+1,(cl_BrowserDB+i)->pColFor->i_sqlDataType,&t_temp,sizeof(t_temp), &cb)) { Temp0.Printf(_("\n-E-> BrowserDB::OnGetData - ODBC-Error with GetNext \n-E-> ")); Temp0 += GetExtendedDBErrorMsg(__FILE__,__LINE__); @@ -295,23 +297,23 @@ bool BrowserDB::OnGetNext(int Cols,int Quiet) else { // i_Nation = 0 = timestamp , 1=EU, 2=UK, 3=International, 4=US - if (((cl_BrowserDB->pColFor+i)->i_Nation == 0) || // TS YYYY-MM-DD - ((cl_BrowserDB->pColFor+i)->i_Nation == 3)) // IT YYYY-MM-DD + if (((cl_BrowserDB+i)->pColFor->i_Nation == 0) || // TS YYYY-MM-DD + ((cl_BrowserDB+i)->pColFor->i_Nation == 3)) // IT YYYY-MM-DD { - Temp0.Printf((cl_BrowserDB->pColFor+i)->s_Field,t_temp.year,t_temp.month,t_temp.day, + Temp0.Printf((cl_BrowserDB+i)->pColFor->s_Field,t_temp.year,t_temp.month,t_temp.day, t_temp.hour, t_temp.minute, t_temp.second, t_temp.fraction); strcpy((cl_BrowserDB+i)->tableName,Temp0.c_str()); } - if (((cl_BrowserDB->pColFor+i)->i_Nation == 1) || // EU DD.MM.YYYY - ((cl_BrowserDB->pColFor+i)->i_Nation == 2)) // UK DD/MM/YYYY + if (((cl_BrowserDB+i)->pColFor->i_Nation == 1) || // EU DD.MM.YYYY + ((cl_BrowserDB+i)->pColFor->i_Nation == 2)) // UK DD/MM/YYYY { - Temp0.Printf((cl_BrowserDB->pColFor+i)->s_Field,t_temp.day,t_temp.month,t_temp.year, + Temp0.Printf((cl_BrowserDB+i)->pColFor->s_Field,t_temp.day,t_temp.month,t_temp.year, t_temp.hour, t_temp.minute, t_temp.second, t_temp.fraction); strcpy((cl_BrowserDB+i)->tableName,Temp0.c_str()); } - if ((cl_BrowserDB->pColFor+i)->i_Nation == 3) // US MM/DD/YYYY + if ((cl_BrowserDB+i)->pColFor->i_Nation == 3) // US MM/DD/YYYY { - Temp0.Printf((cl_BrowserDB->pColFor+i)->s_Field,t_temp.month,t_temp.day,t_temp.year, + Temp0.Printf((cl_BrowserDB+i)->pColFor->s_Field,t_temp.month,t_temp.day,t_temp.year, t_temp.hour, t_temp.minute, t_temp.second, t_temp.fraction); strcpy((cl_BrowserDB+i)->tableName,Temp0.c_str()); } @@ -322,11 +324,11 @@ bool BrowserDB::OnGetNext(int Cols,int Quiet) if (AnzError <= 100) { Temp0 = (cl_BrowserDB+i)->colName; - wxLogMessage(_("-E-> BrowserDB::OnGetNext - DB_DATA_TYPE_?? (%d) in Col(%s)"),(cl_BrowserDB->pColFor+i)->i_dbDataType,Temp0.c_str()); + wxLogMessage(_("-E-> BrowserDB::OnGetNext - DB_DATA_TYPE_?? (%d) in Col(%s)"),(cl_BrowserDB+i)->pColFor->i_dbDataType,Temp0.c_str()); } else return TRUE; - Temp0.Printf(_("-E-> unknown Format(%d) - sql(%d)"),(cl_BrowserDB->pColFor+i)->i_dbDataType,(cl_BrowserDB->pColFor+i)->i_sqlDataType); + Temp0.Printf(_("-E-> unknown Format(%d) - sql(%d)"),(cl_BrowserDB+i)->pColFor->i_dbDataType,(cl_BrowserDB+i)->pColFor->i_sqlDataType); strcpy((cl_BrowserDB+i)->tableName,Temp0.c_str()); break; }; // switch @@ -406,23 +408,29 @@ wxDbInf* BrowserDB::OnGetCatalog(int Quiet) } //---------------------------------------------------------------------------------------- -wxDbColInf* BrowserDB::OnGetColumns(char *tableName, int numCols, int Quiet) +wxDbColInf* BrowserDB::OnGetColumns(char *tableName, UWORD numCols, int Quiet) { char UName[255]; int i; strcpy(UName,UserName); cl_BrowserDB = db_BrowserDB->GetColumns(tableName,&numCols,UName); - cl_BrowserDB->pColFor = new wxDbColFor[numCols]; +// cl_BrowserDB->pColFor = new wxDbColFor[numCols]; for (i=0;ipColFor+i)->Format(1,(cl_BrowserDB+i)->dbDataType,(cl_BrowserDB+i)->sqlDataType, - (cl_BrowserDB+i)->columnSize, (cl_BrowserDB+i)->decimalDigits); +// (cl_BrowserDB->pColFor+i)->Format(1,(cl_BrowserDB+i)->dbDataType,(cl_BrowserDB+i)->sqlDataType, +// (cl_BrowserDB+i)->columnSize, (cl_BrowserDB+i)->decimalDigits); + (cl_BrowserDB+i)->pColFor = new wxDbColFor; + (cl_BrowserDB+i)->pColFor->Format(1, + (cl_BrowserDB+i)->dbDataType, + (cl_BrowserDB+i)->sqlDataType, + (cl_BrowserDB+i)->columnSize, + (cl_BrowserDB+i)->decimalDigits); } return cl_BrowserDB; } //---------------------------------------------------------------------------------------- -void BrowserDB::Zeiger_auf_NULL(int Art) +void BrowserDB::PointerToNULL(int Art) { if (Art == 1) // Löschen {