X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2f74ed285965eaf401a4060507b5c80166dfc0f5..52a07708c402e7b60a73abb6bae42838cf92c9f7:/src/common/dbtable.cpp diff --git a/src/common/dbtable.cpp b/src/common/dbtable.cpp index f39279fef8..d640ddd82c 100644 --- a/src/common/dbtable.cpp +++ b/src/common/dbtable.cpp @@ -40,9 +40,9 @@ # endif #endif -#ifdef DBDEBUG_CONSOLE +//#ifdef DBDEBUG_CONSOLE #include -#endif +//#endif #ifdef __BORLANDC__ #pragma hdrstop @@ -130,8 +130,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); @@ -260,7 +258,7 @@ wxTable::~wxTable() TablesInUse.DeleteContents(TRUE); bool found = FALSE; - wxNode *pNode; + wxNode *pNode; pNode = TablesInUse.First(); while (pNode && !found) { @@ -282,6 +280,8 @@ wxTable::~wxTable() } #endif + + // Decrement the wxDB table count if (pDb) pDb->nTables--; @@ -296,12 +296,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 +312,11 @@ wxTable::~wxTable() // Delete dynamically allocated cursors if (hstmtDefault) DeleteCursor(hstmtDefault); + if (hstmtCount) DeleteCursor(hstmtCount); + } // wxTable::~wxTable() @@ -580,43 +584,20 @@ bool wxTable::Open(void) 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)) + if (!pDb->TableExists(tableName,pDb->GetUsername(),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 - { - // 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); } @@ -1696,6 +1677,7 @@ void wxTable::ClearMemberVars(void) pDt->second = 0; pDt->fraction = 0; break; + } } @@ -1800,10 +1782,20 @@ wxColDataPtr* wxTable::SetColDefs (wxColInf *pColInfs, ULONG numCols) { 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; + + // Be sure to allocate enough memory + if (pColInfs[index].bufferLength >= pColInfs[index].columnSize) + { + pColDataPtrs[index].PtrDataObj = new char[pColInfs[index].bufferLength+1]; + pColDataPtrs[index].SzDataObj = pColInfs[index].bufferLength; + } + else + { + pColDataPtrs[index].PtrDataObj = new char[pColInfs[index].columnSize+1]; + pColDataPtrs[index].SzDataObj = pColInfs[index].columnSize; + } + pColDataPtrs[index].SqlCtype = SQL_C_CHAR; + break; } case DB_DATA_TYPE_INTEGER: {