X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2f74ed285965eaf401a4060507b5c80166dfc0f5..e1208c3103734c8581c9854c344b97323e381897:/src/common/dbtable.cpp?ds=sidebyside diff --git a/src/common/dbtable.cpp b/src/common/dbtable.cpp index f39279fef8..396ed696c0 100644 --- a/src/common/dbtable.cpp +++ b/src/common/dbtable.cpp @@ -41,7 +41,7 @@ #endif #ifdef DBDEBUG_CONSOLE - #include + #include "wx/ioswrap.h" #endif #ifdef __BORLANDC__ @@ -55,6 +55,7 @@ #include "wx/list.h" #include "wx/utils.h" #include "wx/msgdlg.h" + #include "wx/log.h" #endif #include "wx/filefn.h" #endif @@ -130,8 +131,6 @@ wxTable::wxTable(wxDB *pwxDB, const char *tblName, const int nCols, wxStrcpy(tableName, tblName); // Table Name if (tblPath) wxStrcpy(tablePath, tblPath); // Table Path - used for dBase files - else - tablePath[0]=0; if (qryTblName) // Name of the table/view to query wxStrcpy(queryTableName, qryTblName); @@ -268,7 +267,7 @@ wxTable::~wxTable() { found = TRUE; if (!TablesInUse.DeleteNode(pNode)) - wxMessageBox (s.GetData(),"Unable to delete node!"); + wxLogDebug (s.c_str(),"Unable to delete node!"); } else pNode = pNode->Next(); @@ -277,11 +276,13 @@ wxTable::~wxTable() { wxString msg; msg.sprintf("Unable to find the tableID in the linked\nlist of tables in use.\n\n%s",s.GetData()); - wxMessageBox (msg.GetData(),"NOTICE..."); + wxLogDebug (msg.GetData(),"NOTICE..."); } } #endif + + // Decrement the wxDB table count if (pDb) pDb->nTables--; @@ -296,12 +297,14 @@ wxTable::~wxTable() if (hstmtInsert) if (SQLFreeStmt(hstmtInsert, SQL_DROP) != SQL_SUCCESS) pDb->DispAllErrors(henv, hdbc); + if (hstmtDelete) if (SQLFreeStmt(hstmtDelete, SQL_DROP) != SQL_SUCCESS) - pDb->DispAllErrors(henv, hdbc); + if (hstmtUpdate) if (SQLFreeStmt(hstmtUpdate, SQL_DROP) != SQL_SUCCESS) pDb->DispAllErrors(henv, hdbc); + } if (hstmtInternal) if (SQLFreeStmt(hstmtInternal, SQL_DROP) != SQL_SUCCESS) @@ -310,9 +313,11 @@ wxTable::~wxTable() // Delete dynamically allocated cursors if (hstmtDefault) DeleteCursor(hstmtDefault); + if (hstmtCount) DeleteCursor(hstmtCount); + } // wxTable::~wxTable() @@ -578,45 +583,21 @@ bool wxTable::Open(void) return FALSE; int i; -// char sqlStmt[DB_MAX_STATEMENT_LEN]; wxString sqlStmt; - wxString *s = NULL; // Verify that the table exists in the database -// if (!pDb->TableExists(tableName,pDb->GetUsername(),tablePath)) - if (!pDb->TableExists(tableName,NULL,tablePath)) - { - s =new wxString("Table/view does not exist in the database"); - if (*(pDb->dbInf.accessibleTables) == 'Y') - { - (*s)+=", or you have insufficient permissions.\n"; - } - else - { - (*s)+=".\n"; - } - } - else + if (!pDb->TableExists(tableName,pDb->GetUsername(),tablePath)) { - // Verify the user has rights to access the table. - // Shortcut boolean evaluation to optimize out call to TablePrivs - // Unfortunely this optimization doesn't seem to be reliable! - if (/* *(pDb->dbInf.accessibleTables) == 'N' && */ - !pDb->TablePrivileges(tableName,"SELECT",NULL,tablePath)) - s = new wxString("Current logged in user has insufficient privileges to access this table.\n"); - } - - if (s) - { - wxString p; + wxString s; if (wxStrcmp(tablePath,"")) - p.sprintf("Error opening '%s/%s'.\n",tablePath,tableName); - else - p.sprintf("Error opening '%s'.\n", tableName); - - p += (*s); - pDb->LogError(p.GetData()); - + s.sprintf("Error opening '%s/%s'.\n",tablePath,tableName); + else + s.sprintf("Error opening '%s'.\n", tableName); + if (!pDb->TableExists(tableName,NULL,tablePath)) + s += "Table/view does not exist in the database.\n"; + else + s += "Current logged in user does not have sufficient privileges to access this table.\n"; + pDb->LogError(s.GetData()); return(FALSE); } @@ -1069,10 +1050,9 @@ bool wxTable::DropTable() { // NOTE: This function returns TRUE if the Table does not exist, but // only for identified databases. Code will need to be added - // below for any other databases when those databases are defined + // below for any other databases when those databases are defined // to handle this situation consistently -// char sqlStmt[DB_MAX_STATEMENT_LEN]; wxString sqlStmt; sqlStmt.sprintf("DROP TABLE %s", tableName); @@ -1190,7 +1170,6 @@ bool wxTable::DropIndex(const char * idxName) // below for any other databases when those databases are defined // to handle this situation consistently -// char sqlStmt[DB_MAX_STATEMENT_LEN]; wxString sqlStmt; if (pDb->Dbms() == dbmsACCESS) @@ -1284,7 +1263,7 @@ bool wxTable::Update(void) pDb->WriteSqlLog(sqlStmt); #ifdef DBDEBUG_CONSOLE - cout << endl << sqlStmt.GetData() << endl << endl; + cout << endl << sqlStmt << endl << endl; #endif // Execute the SQL UPDATE statement @@ -1322,7 +1301,7 @@ bool wxTable::UpdateWhere(const char *pWhereClause) pDb->WriteSqlLog(sqlStmt); #ifdef DBDEBUG_CONSOLE - cout << endl << sqlStmt.GetData() << endl << endl; + cout << endl << sqlStmt << endl << endl; #endif // Execute the SQL UPDATE statement @@ -1696,6 +1675,7 @@ void wxTable::ClearMemberVars(void) pDt->second = 0; pDt->fraction = 0; break; + } } @@ -1760,8 +1740,6 @@ void wxTable::SetColDefs (int index, const char *fieldName, int dataType, void * /********** wxTable::SetColDef() **********/ -// BJO20000121 : changed prototype in order to return proper pointer on wxColDataPtr's array -//bool wxTable::SetColDefs(wxColInf *pColInfs, ULONG numCols, wxColDataPtr *pColDataPtrs) wxColDataPtr* wxTable::SetColDefs (wxColInf *pColInfs, ULONG numCols) { assert(pColInfs); @@ -1776,34 +1754,15 @@ wxColDataPtr* wxTable::SetColDefs (wxColInf *pColInfs, ULONG numCols) for (index = 0; index < numCols; index++) { -/* - wxString title,msg; - title.sprintf("Catalog: %s, Schema: %s, Table name: %s",pColInfs[index].catalog,pColInfs[index].schema,pColInfs[index].tableName); - msg.sprintf("Column name: %s\nData type: %04d\nType name: %s\nColumn size: %d\nBuffer len: %d\nDecimals:%d\nRadix: %d\nNullable: %d\nRemarks: %s", - pColInfs[index].colName,pColInfs[index].sqlDataType,pColInfs[index].typeName,pColInfs[index].columnSize,pColInfs[index].bufferLength,pColInfs[index].decimalDigits,pColInfs[index].numPrecRadix,pColInfs[index].nullable,pColInfs[index].remarks); - msg += " \nDB_DATA_TYPE: "; - switch(pColInfs[index].dbDataType) - { - case DB_DATA_TYPE_VARCHAR: - msg += pDb->typeInfVarchar.TypeName; break; - case DB_DATA_TYPE_INTEGER: - msg += pDb->typeInfInteger.TypeName; break; - case DB_DATA_TYPE_FLOAT: - msg += pDb->typeInfFloat.TypeName; break; - case DB_DATA_TYPE_DATE: - msg += pDb->typeInfDate.TypeName; break; - } - wxMessageBox(msg.GetData(),title.GetData()); -*/ // Process the fields switch (pColInfs[index].dbDataType) { case DB_DATA_TYPE_VARCHAR: { - pColDataPtrs[index].PtrDataObj = new char[pColInfs[index].bufferLength+1]; - pColDataPtrs[index].SzDataObj = pColInfs[index].bufferLength; - pColDataPtrs[index].SqlCtype = SQL_C_CHAR; - break; + pColDataPtrs[index].PtrDataObj = new char[pColInfs[index].bufferLength+1]; + pColDataPtrs[index].SzDataObj = pColInfs[index].columnSize; + pColDataPtrs[index].SqlCtype = SQL_C_CHAR; + break; } case DB_DATA_TYPE_INTEGER: { @@ -1870,7 +1829,6 @@ void wxTable::SetCursor(HSTMT *hstmtActivate) ULONG wxTable::Count(const char *args) { ULONG l; -// char sqlStmt[DB_MAX_STATEMENT_LEN]; wxString sqlStmt; SDWORD cb;