FIX: Incorrect Return Value From CRecordset::IsOpen()ID: Q120206
|
When CRecordset::IsOpen() is called, it returns TRUE even if the CRecordset
has not been opened.
This happens only if a CRecordset is constructed with a CDatabase pointer
being passed to it.
CRecordset::IsOpen() checks whether the statement handle of the recordset has been allocated as follows:
_AFXDBCORE_INLINE BOOL CRecordset::IsOpen() const
{ ASSERT_VALID(this); return m_hstmt != SQL_NULL_HSTMT; }
The statement handle is usually allocated when CRecordset::Open() is called
(that is, when a recordset is opened).
To work around this problem, use one of the following methods:
Microsoft has confirmed this to be a bug in the products listed at the beginning of this article. This bug was corrected in the 32-bit version of MFC.
BOOL CMyRecordset::IsMyOpen() const
{
if (m_hstmt == NULL)
return FALSE;
RETCODE nRetCode;
SWORD nCols;
AFX_SQL_SYNC(::SQLNumResultCols(m_hstmt, &nCols));
if (nRetCode == SQL_ERROR)
{
TRACE0("Error: SQLNumResultCols failed during IsOpen().\n");
return FALSE;
}
else if (nCols == 0)
return FALSE;
return TRUE;
}
Additional query words: 1.50 1.51 1.52 2.50 2.51 2.52 2.53
Keywords : kb16bitonly kbDatabase kbMFC kbODBC kbVC
Version : 1.50 1.51 1.52 1.52b
Platform : WINDOWS
Issue type :
Last Reviewed: July 21, 1999