fix memory allocation problem for strings

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6284 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Bart A.M. Jourquin
2000-02-25 15:00:22 +00:00
parent ed23853bc0
commit 7c5c05ae65

View File

@@ -40,9 +40,9 @@
# endif # endif
#endif #endif
#ifdef DBDEBUG_CONSOLE //#ifdef DBDEBUG_CONSOLE
#include <iostream.h> #include <iostream.h>
#endif //#endif
#ifdef __BORLANDC__ #ifdef __BORLANDC__
#pragma hdrstop #pragma hdrstop
@@ -280,6 +280,8 @@ wxTable::~wxTable()
} }
#endif #endif
// Decrement the wxDB table count // Decrement the wxDB table count
if (pDb) if (pDb)
pDb->nTables--; pDb->nTables--;
@@ -294,12 +296,14 @@ wxTable::~wxTable()
if (hstmtInsert) if (hstmtInsert)
if (SQLFreeStmt(hstmtInsert, SQL_DROP) != SQL_SUCCESS) if (SQLFreeStmt(hstmtInsert, SQL_DROP) != SQL_SUCCESS)
pDb->DispAllErrors(henv, hdbc); pDb->DispAllErrors(henv, hdbc);
if (hstmtDelete) if (hstmtDelete)
if (SQLFreeStmt(hstmtDelete, SQL_DROP) != SQL_SUCCESS) if (SQLFreeStmt(hstmtDelete, SQL_DROP) != SQL_SUCCESS)
pDb->DispAllErrors(henv, hdbc);
if (hstmtUpdate) if (hstmtUpdate)
if (SQLFreeStmt(hstmtUpdate, SQL_DROP) != SQL_SUCCESS) if (SQLFreeStmt(hstmtUpdate, SQL_DROP) != SQL_SUCCESS)
pDb->DispAllErrors(henv, hdbc); pDb->DispAllErrors(henv, hdbc);
} }
if (hstmtInternal) if (hstmtInternal)
if (SQLFreeStmt(hstmtInternal, SQL_DROP) != SQL_SUCCESS) if (SQLFreeStmt(hstmtInternal, SQL_DROP) != SQL_SUCCESS)
@@ -308,9 +312,11 @@ wxTable::~wxTable()
// Delete dynamically allocated cursors // Delete dynamically allocated cursors
if (hstmtDefault) if (hstmtDefault)
DeleteCursor(hstmtDefault); DeleteCursor(hstmtDefault);
if (hstmtCount) if (hstmtCount)
DeleteCursor(hstmtCount); DeleteCursor(hstmtCount);
} // wxTable::~wxTable() } // wxTable::~wxTable()
@@ -1671,6 +1677,7 @@ void wxTable::ClearMemberVars(void)
pDt->second = 0; pDt->second = 0;
pDt->fraction = 0; pDt->fraction = 0;
break; break;
} }
} }
@@ -1774,9 +1781,19 @@ wxColDataPtr* wxTable::SetColDefs (wxColInf *pColInfs, ULONG numCols)
switch (pColInfs[index].dbDataType) switch (pColInfs[index].dbDataType)
{ {
case DB_DATA_TYPE_VARCHAR: case DB_DATA_TYPE_VARCHAR:
{
// Be sure to allocate enough memory
if (pColInfs[index].bufferLength >= pColInfs[index].columnSize)
{ {
pColDataPtrs[index].PtrDataObj = new char[pColInfs[index].bufferLength+1]; pColDataPtrs[index].PtrDataObj = new char[pColInfs[index].bufferLength+1];
pColDataPtrs[index].SzDataObj = pColInfs[index].bufferLength; 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; pColDataPtrs[index].SqlCtype = SQL_C_CHAR;
break; break;
} }