Article ID: 128831
Article Last Modified on 10/17/2003
CSomeRecordset rs; rs.Open(); rs.Edit(); rs.IsFieldDirty(NULL); rs.m_field1="somevalue"; rs.Update(); rs.Close();IsFieldDirty() is called twice -- once explicitly and then indirectly in the Update() call.
void CRecordset::MarkForUpdate()
{
ASSERT_VALID(this);
ASSERT(m_hstmt != SQL_NULL_HSTMT);
// Must have already stored field values in memfile
ASSERT(m_pmemfile != NULL);
CFieldExchange fx(CFieldExchange::MarkForUpdate, this);
m_pmemfile->SeekToBegin();
ASSERT(m_par != NULL);
delete m_par;
m_par = NULL;
m_par = new CArchive(m_pmemfile, CArchive::load);
fx.m_par = m_par;
DoFieldExchange(&fx);
}
The SeekToBegin() call is made while the CArchive object pointed to by
m_par is still attached to the file. The CArchive doesn't know that the
memfile's file pointer has been moved by the SeekToBegin() call. When the
archive is deleted, its Flush() member function is called. In that
function, the archive attempts to move the file pointer back from where it
thinks the current file position is to the beginning of the file. Because
the current file position is already at the beginning of the file, a bad
seek CFileException is thrown.
void CSomeRecordset::MarkForUpdate()
{
ASSERT_VALID(this);
ASSERT(m_hstmt != SQL_NULL_HSTMT);
// Must have already stored field values in memfile
ASSERT(m_pmemfile != NULL);
ASSERT(m_par != NULL);
delete m_par;
m_par = NULL;
CFieldExchange fx(CFieldExchange::MarkForUpdate, this);
m_pmemfile->SeekToBegin();
m_par = new CArchive(m_pmemfile, CArchive::load);
fx.m_par = m_par;
DoFieldExchange(&fx);
}
Again, copy the Update(), UpdateInsertDelete(), and IsFieldDirty()
functions from the code in DBCORE.CPP to functions of the same name in your
new CRecordset-derived class.
Additional query words: 2.00 2.10 3.0 3.1 3.00 3.10
Keywords: kbbug kbfix kbdatabase KB128831