我跟踪了 Close()方法,发现错误的代码了. void CRecordset::Close() { ENSURE_VALID(this); // Can't close if database has been deleted ENSURE(m_pDatabase != NULL); // This will force a requery for cursor name if reopened. m_strCursorName.Empty(); if (m_rgFieldInfos != NULL && m_nFields > 0 && m_bCheckCacheForDirtyFields) { FreeDataCache(); } //进去这个方法 FreeRowset(); //这个方法很长就不全贴出来了 }void CRecordset::FreeRowset() { // Delete the rowset status //执行下面代码会出错 delete [] m_rgRowStatus; m_rgRowStatus = NULL; if (m_dwOptions & useMultiRowFetch && !(m_dwOptions & userAllocMultiRowBuffers)) { // Calling virtual function, DoBulkFieldExchange, here is bad // because Close then FreeRowset may get called from destructor. // There is no simple choice however if RFX_Bulk functions do // a memory allocation. The net result is that users MUST call // Close explicitly (rather than relying on destructor) if // using multi row fetches, otherwise they will get a memory leak. // If rowset already allocated, delete old rowset buffers if (m_dwAllocatedRowsetSize != 0) { CFieldExchange fx(CFieldExchange::DeleteMultiRowBuffer, this); DoBulkFieldExchange(&fx); } } m_dwAllocatedRowsetSize = 0; }
void CRecordset::Close()
{
ENSURE_VALID(this);
// Can't close if database has been deleted
ENSURE(m_pDatabase != NULL); // This will force a requery for cursor name if reopened.
m_strCursorName.Empty(); if (m_rgFieldInfos != NULL &&
m_nFields > 0 && m_bCheckCacheForDirtyFields)
{
FreeDataCache();
}
//进去这个方法
FreeRowset();
//这个方法很长就不全贴出来了
}void CRecordset::FreeRowset()
{
// Delete the rowset status
//执行下面代码会出错
delete [] m_rgRowStatus;
m_rgRowStatus = NULL; if (m_dwOptions & useMultiRowFetch &&
!(m_dwOptions & userAllocMultiRowBuffers))
{
// Calling virtual function, DoBulkFieldExchange, here is bad
// because Close then FreeRowset may get called from destructor.
// There is no simple choice however if RFX_Bulk functions do
// a memory allocation. The net result is that users MUST call
// Close explicitly (rather than relying on destructor) if
// using multi row fetches, otherwise they will get a memory leak.
// If rowset already allocated, delete old rowset buffers
if (m_dwAllocatedRowsetSize != 0)
{
CFieldExchange fx(CFieldExchange::DeleteMultiRowBuffer, this);
DoBulkFieldExchange(&fx);
}
} m_dwAllocatedRowsetSize = 0;
}
数据库里有一个 BLOB类型的字段,以二进制格式保存文件信息,网上介绍存储这种格式数据都是继承于CRecordset的类.
但是我写的程序是个事例程序所以很简单. 没用到那个字段.
例如: http://www.docin.com/p-110403636.html
2, 有什么附加的操作吗?
没有
m_FZFile->Update();
这行代码,然后再调用
m_FZFile->Close();
就出错,不调用m_FZFile->Update(); 则没事.